29 #include <nsIClassInfoImpl.h>
30 #include <nsIMutableArray.h>
31 #include <nsIProgrammingLanguage.h>
32 #include <nsIStringEnumerator.h>
34 #include <nsArrayUtils.h>
35 #include <nsAutoLock.h>
36 #include <nsComponentManagerUtils.h>
37 #include <nsServiceManagerUtils.h>
39 #include <sbIPlaybackHistoryService.h>
60 nsAutoLock::DestroyLock(mLock);
65 sbPlaybackHistoryEntry::GetEntryId(PRInt64 *aEntryId)
67 NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
68 NS_ENSURE_ARG_POINTER(aEntryId);
70 nsAutoLock lock(mLock);
77 sbPlaybackHistoryEntry::SetEntryId(PRInt64 aEntryId)
79 NS_ENSURE_TRUE(mLock, );
81 nsAutoLock lock(mLock);
94 NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
95 NS_ENSURE_ARG_POINTER(aItem);
97 nsAutoLock lock(mLock);
98 NS_IF_ADDREF(*aItem = mItem);
104 sbPlaybackHistoryEntry::GetTimestamp(PRInt64 *aTimestamp)
106 NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
107 NS_ENSURE_ARG_POINTER(aTimestamp);
109 nsAutoLock lock(mLock);
110 *aTimestamp = mTimestamp;
116 sbPlaybackHistoryEntry::GetDuration(PRInt64 *aDuration)
118 NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
119 NS_ENSURE_ARG_POINTER(aDuration);
121 nsAutoLock lock(mLock);
122 *aDuration = mDuration;
130 NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
131 NS_ENSURE_ARG_POINTER(aAnnotations);
133 nsAutoLock lock(mLock);
134 NS_IF_ADDREF(*aAnnotations = mAnnotations);
140 sbPlaybackHistoryEntry::GetAnnotation(
const nsAString & aAnnotationId,
143 NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
147 nsAutoLock lock(mLock);
152 nsresult rv = mAnnotations->GetPropertyValue(aAnnotationId, _retval);
153 NS_ENSURE_SUCCESS(rv, rv);
159 sbPlaybackHistoryEntry::HasAnnotation(
const nsAString & aAnnotationId,
162 NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
166 nsAutoLock lock(mLock);
172 nsresult rv = mAnnotations->GetPropertyValue(aAnnotationId, value);
181 sbPlaybackHistoryEntry::SetAnnotation(
const nsAString & aAnnotationId,
182 const nsAString & aAnnotationValue)
184 NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
186 nsAutoLock lock(mLock);
188 nsresult rv = NS_ERROR_UNEXPECTED;
193 NS_ENSURE_SUCCESS(rv, rv);
195 mAnnotations = do_QueryInterface(annotations, &rv);
196 NS_ENSURE_SUCCESS(rv, rv);
199 annotations = do_QueryInterface(mAnnotations, &rv);
200 NS_ENSURE_SUCCESS(rv, rv);
203 rv = annotations->AppendProperty(aAnnotationId, aAnnotationValue);
204 NS_ENSURE_SUCCESS(rv, rv);
210 nsCOMPtr<sbIPlaybackHistoryService>
history =
212 NS_ENSURE_SUCCESS(rv, rv);
214 rv = history->AddOrUpdateAnnotation(mEntryId,
217 NS_ENSURE_SUCCESS(rv, rv);
224 sbPlaybackHistoryEntry::RemoveAnnotation(
const nsAString &aAnnotationId)
226 NS_ENSURE_TRUE(mLock, NS_ERROR_NOT_INITIALIZED);
228 nsAutoLock lock(mLock);
230 nsresult rv = NS_ERROR_UNEXPECTED;
235 NS_ENSURE_SUCCESS(rv, rv);
237 mAnnotations = do_QueryInterface(annotations, &rv);
238 NS_ENSURE_SUCCESS(rv, rv);
241 annotations = do_QueryInterface(mAnnotations, &rv);
242 NS_ENSURE_SUCCESS(rv, rv);
246 rv = annotations->GetLength(&length);
247 NS_ENSURE_SUCCESS(rv, rv);
249 for(PRUint32 current = 0; current < length; ++current) {
250 nsCOMPtr<sbIProperty>
property =
251 do_QueryElementAt(annotations, current, &rv);
252 NS_ENSURE_SUCCESS(rv, rv);
255 rv =
property->GetId(
id);
256 NS_ENSURE_SUCCESS(rv, rv);
258 if(aAnnotationId.Equals(
id)) {
259 rv = annotations->RemoveElementAt(current);
260 NS_ENSURE_SUCCESS(rv, rv);
267 nsCOMPtr<sbIPlaybackHistoryService>
history =
269 NS_ENSURE_SUCCESS(rv, rv);
271 rv = history->RemoveAnnotation(mEntryId, aAnnotationId);
272 NS_ENSURE_SUCCESS(rv, rv);
284 NS_ENSURE_ARG_POINTER(aItem);
285 NS_ENSURE_ARG_MIN(aTimestamp, 0);
286 NS_ENSURE_ARG_MIN(aDuration, 0);
288 mLock = nsAutoLock::NewLock(
"sbPlaybackHistoryEntry::mLock");
289 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
291 nsAutoLock lock(mLock);
294 mTimestamp = aTimestamp;
295 mDuration = aDuration;
296 mAnnotations = aAnnotations;
NS_IMPL_THREADSAFE_ISUPPORTS1(sbPlaybackHistoryEntry, sbIPlaybackHistoryEntry) sbPlaybackHistoryEntry
readonly attribute sbIPropertyArray annotations
Annotations to the entry. Annotations are properties.
#define SB_PLAYBACKHISTORYSERVICE_CONTRACTID
~sbPlaybackHistoryEntry()
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...