33 #include "sbIDeviceBase.h"
35 #include <nsAppDirectoryServiceDefs.h>
36 #include <nsAutoLock.h>
37 #include <nsAutoPtr.h>
38 #include <nsCOMArray.h>
39 #include <nsCRTGlue.h>
40 #include <nsComponentManagerUtils.h>
41 #include <nsDirectoryServiceUtils.h>
42 #include <nsIFileURL.h>
43 #include <nsIIOService.h>
44 #include <nsILocalFile.h>
45 #include <nsIProxyObjectManager.h>
47 #include <nsIURIFixup.h>
48 #include <nsIWritablePropertyBag2.h>
50 #include <nsProxyRelease.h>
51 #include <nsServiceManagerUtils.h>
52 #include <nsStringGlue.h>
53 #include <nsThreadUtils.h>
54 #include <nsUnicharUtils.h>
57 #include <sbILibraryFactory.h>
58 #include <sbILibraryManager.h>
59 #include <sbIPropertyArray.h>
63 #define MSG_DEVICE_BASE (0x2000) // Base message ID
65 #define MSG_DEVICE_TRANSFER (MSG_DEVICE_BASE + 0)
66 #define MSG_DEVICE_UPLOAD (MSG_DEVICE_BASE + 1)
67 #define MSG_DEVICE_DELETE (MSG_DEVICE_BASE + 2)
68 #define MSG_DEVICE_UPDATE_METADATA (MSG_DEVICE_BASE + 3)
69 #define MSG_DEVICE_EVENT (MSG_DEVICE_BASE + 4)
70 #define MSG_DEVICE_INITIALIZE (MSG_DEVICE_BASE + 5)
71 #define MSG_DEVICE_FINALIZE (MSG_DEVICE_BASE + 6)
72 #define MSG_DEVICE_EJECT (MSG_DEVICE_BASE + 7)
74 #define TRANSFER_TABLE_NAME NS_LITERAL_STRING("Transfer")
75 #define URL_COLUMN_NAME NS_LITERAL_STRING("url")
76 #define SOURCE_COLUMN_NAME NS_LITERAL_STRING("source")
77 #define DESTINATION_COLUMN_NAME NS_LITERAL_STRING("destination")
78 #define INDEX_COLUMN_NAME NS_LITERAL_STRING("id")
85 static PRLogModuleInfo *gUSBMassStorageDeviceLog = nsnull;
86 #define TRACE(args) if (gUSBMassStorageDeviceLog) PR_LOG(gUSBMassStorageDeviceLog, PR_LOG_DEBUG, args)
87 #define LOG(args) if (gUSBMassStorageDeviceLog) PR_LOG(gUSBMassStorageDeviceLog, PR_LOG_WARN, args)
96 const nsAString& aOldChars,
97 const PRUnichar aNewChar)
99 PRUint32 length = aOldString.Length();
100 for (PRUint32 index = 0; index < length; index++) {
101 PRUnichar currentChar = aOldString.CharAt(index);
102 PRInt32 oldCharsIndex = aOldChars.FindChar(currentChar);
103 if (oldCharsIndex > -1)
104 aOldString.Replace(index, 1, aNewChar);
110 const nsACString& aOldChars,
113 PRUint32 length = aOldString.Length();
114 for (PRUint32 index = 0; index < length; index++) {
115 char currentChar = aOldString.CharAt(index);
116 PRInt32 oldCharsIndex = aOldChars.FindChar(currentChar);
117 if (oldCharsIndex > -1)
118 aOldString.Replace(index, 1, aNewChar);
126 PLDHashOperator PR_CALLBACK
131 NS_ASSERTION(aUserData,
"Null userData!");
133 PRUint32* index =
static_cast<PRUint32*
>(aUserData);
134 NS_ENSURE_TRUE(index, PL_DHASH_STOP);
136 if (aEntry > *index) {
140 return PL_DHASH_NEXT;
145 mIgnoreListener(PR_FALSE),
146 mManagePlaylists(PR_FALSE)
158 NS_ENSURE_ARG_POINTER(aDevice);
163 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
183 sbDeviceBaseLibraryListener::OnItemAdded(
sbIMediaList *aMediaList,
186 PRBool *aNoMoreForBatch)
188 NS_ENSURE_ARG_POINTER(aMediaList);
189 NS_ENSURE_ARG_POINTER(aMediaItem);
190 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
192 *aNoMoreForBatch = PR_FALSE;
200 nsCOMPtr<sbILibrary> library;
201 rv = aMediaList->GetLibrary(getter_AddRefs(library));
202 NS_ENSURE_SUCCESS(rv, rv);
204 PRBool destinationIsLibrary;
205 rv = aMediaList->Equals(library, &destinationIsLibrary);
206 NS_ENSURE_SUCCESS(rv, rv);
208 nsCOMPtr<sbIMediaList> list = do_QueryInterface(aMediaItem, &rv);
209 PRBool addedIsList = NS_SUCCEEDED(rv);
214 rv = list->AddListener(
this,
223 NS_ENSURE_SUCCESS(rv, rv);
226 NS_ENSURE_TRUE(removedIndexes, NS_ERROR_OUT_OF_MEMORY);
228 PRBool success = removedIndexes->Init();
229 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
232 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
234 removedIndexes.forget();
241 nsCOMPtr<nsIMutableArray> items =
242 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
243 NS_ENSURE_SUCCESS(rv, rv);
245 rv = items->AppendElement(aMediaItem, PR_FALSE);
246 NS_ENSURE_SUCCESS(rv, rv);
248 PRUint32 transferItemCount = 0;
250 if (destinationIsLibrary) {
255 NS_ENSURE_SUCCESS(rv, rv);
258 nsCOMPtr<nsIURI>
uri;
267 NS_ENSURE_SUCCESS(rv, rv);
272 NS_WARNING(
"DeviceBase does not support lists of lists!");
281 NS_ENSURE_SUCCESS(rv, rv);
286 nsCOMPtr<nsIURI>
uri;
294 NS_ENSURE_SUCCESS(rv, rv);
301 sbDeviceBaseLibraryListener::OnBeforeItemRemoved(
sbIMediaList *aMediaList,
304 PRBool *aNoMoreForBatch)
306 NS_ENSURE_ARG_POINTER(aMediaList);
307 NS_ENSURE_ARG_POINTER(aMediaItem);
308 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
311 *aNoMoreForBatch = PR_FALSE;
325 nsCOMPtr<sbILibrary> library;
326 rv = aMediaList->GetLibrary(getter_AddRefs(library));
327 NS_ENSURE_SUCCESS(rv, rv);
329 PRBool fromListIsLibrary;
330 rv = aMediaList->Equals(library, &fromListIsLibrary);
331 NS_ENSURE_SUCCESS(rv, rv);
333 if (!fromListIsLibrary) {
335 rv = aMediaList->IndexOf(aMediaItem, 0, &index);
336 NS_ENSURE_SUCCESS(rv, rv);
340 NS_ENSURE_TRUE(success, NS_ERROR_UNEXPECTED);
342 success = removedIndexes->Put(aMediaItem, index);
343 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
350 sbDeviceBaseLibraryListener::OnAfterItemRemoved(
sbIMediaList *aMediaList,
353 PRBool *aNoMoreForBatch)
355 NS_ENSURE_ARG_POINTER(aMediaList);
356 NS_ENSURE_ARG_POINTER(aMediaItem);
357 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
361 *aNoMoreForBatch = PR_FALSE;
363 nsCOMPtr<sbILibrary> library;
364 rv = aMediaList->GetLibrary(getter_AddRefs(library));
365 NS_ENSURE_SUCCESS(rv, rv);
367 PRBool fromListIsLibrary;
368 rv = aMediaList->Equals(library, &fromListIsLibrary);
369 NS_ENSURE_SUCCESS(rv, rv);
371 nsCOMPtr<sbIMediaList> list = do_QueryInterface(aMediaItem, &rv);
372 PRBool removedIsList = NS_SUCCEEDED(rv);
375 rv = list->RemoveListener(
this);
376 NS_ENSURE_SUCCESS(rv, rv);
383 nsCOMPtr<nsIMutableArray> items =
384 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
385 NS_ENSURE_SUCCESS(rv, rv);
387 rv = items->AppendElement(aMediaItem, PR_FALSE);
388 NS_ENSURE_SUCCESS(rv, rv);
390 PRUint32 deleteItemCount;
392 if (fromListIsLibrary) {
395 NS_ENSURE_SUCCESS(rv, rv);
401 NS_ENSURE_SUCCESS(rv, rv);
406 NS_WARNING(
"Removal of lists that contain lists is not suported");
411 NS_ENSURE_TRUE(success, NS_ERROR_UNEXPECTED);
414 PRBool found = removedIndexes->Get(aMediaItem, &index);
416 removedIndexes->Remove(aMediaItem);
422 NS_ENSURE_SUCCESS(rv, rv);
430 NS_WARNING(
"OnAfterItemRemoved on item not in mBeforeRemoveIndexes");
437 NS_ENSURE_SUCCESS(rv, rv);
444 sbDeviceBaseLibraryListener::OnItemUpdated(
sbIMediaList *aMediaList,
447 PRBool* aNoMoreForBatch)
449 NS_ENSURE_ARG_POINTER(aMediaItem);
450 NS_ENSURE_ARG_POINTER(aMediaList);
451 NS_ENSURE_ARG_POINTER(aProperties);
452 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
454 *aNoMoreForBatch = PR_FALSE;
462 nsCOMPtr<nsIMutableArray> items;
463 items = do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
464 NS_ENSURE_SUCCESS(rv, rv);
466 rv = items->AppendElement(aMediaItem, PR_FALSE);
467 NS_ENSURE_SUCCESS(rv, rv);
469 PRUint32 updateItemCount;
471 NS_ENSURE_SUCCESS(rv, rv);
477 sbDeviceBaseLibraryListener::OnItemMoved(
sbIMediaList *aMediaList,
480 PRBool *aNoMoreForBatch)
482 NS_ENSURE_ARG_POINTER(aMediaList);
483 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
485 *aNoMoreForBatch = PR_FALSE;
491 if (aFromIndex == aToIndex) {
495 PRUint32 updateItemCount;
502 NS_ENSURE_SUCCESS(rv, rv);
509 sbDeviceBaseLibraryListener::OnBeforeListCleared(
sbIMediaList *aMediaList,
510 PRBool aExcludeLists,
511 PRBool* aNoMoreForBatch)
514 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
516 *aNoMoreForBatch = PR_FALSE;
521 sbDeviceBaseLibraryListener::OnListCleared(
sbIMediaList *aMediaList,
522 PRBool aExcludeLists,
523 PRBool* aNoMoreForBatch)
525 NS_ENSURE_ARG_POINTER(aMediaList);
526 NS_ENSURE_ARG_POINTER(aNoMoreForBatch);
528 *aNoMoreForBatch = PR_FALSE;
536 nsCOMPtr<sbILibrary> library;
537 rv = aMediaList->GetLibrary(getter_AddRefs(library));
538 NS_ENSURE_SUCCESS(rv, rv);
540 PRBool fromListIsLibrary;
541 rv = aMediaList->Equals(library, &fromListIsLibrary);
542 NS_ENSURE_SUCCESS(rv, rv);
544 PRUint32 deletedItemCount = 0;
547 NS_ENSURE_SUCCESS(rv, rv);
553 NS_ENSURE_SUCCESS(rv, rv);
560 sbDeviceBaseLibraryListener::OnBatchBegin(
sbIMediaList *aMediaList)
566 sbDeviceBaseLibraryListener::OnBatchEnd(
sbIMediaList *aMediaList)
589 NS_ENSURE_ARG_POINTER(aDevice);
598 sbDeviceBaseLibraryCopyListener::OnItemCopied(
sbIMediaItem *aSourceItem,
601 NS_ENSURE_ARG_POINTER(aSourceItem);
602 NS_ENSURE_ARG_POINTER(aDestItem);
605 nsCOMPtr<nsIMutableArray> items;
607 items = do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
608 NS_ENSURE_SUCCESS(rv, rv);
610 rv = items->AppendElement(aSourceItem, PR_FALSE);
611 NS_ENSURE_SUCCESS(rv, rv);
613 nsCOMPtr<nsIURI>
uri;
616 nsCOMPtr<sbILibrary> library;
617 rv = aDestItem->GetLibrary(getter_AddRefs(library));
619 PRUint32 transferItemCount = 0;
652 NS_ASSERTION(aCallback,
"aCallback is null");
654 nsCOMPtr<nsIProxyObjectManager> proxyObjectManager;
658 nsCOMPtr<nsIThread> thread;
659 rv = NS_GetCurrentThread(getter_AddRefs(thread));
660 NS_ENSURE_SUCCESS(rv, rv);
662 NS_ENSURE_SUCCESS(rv, rv);
665 proxyObjectManager = do_CreateInstance(
"@mozilla.org/xpcomproxy;1", &rv);
666 NS_ENSURE_SUCCESS(rv, rv);
667 rv = proxyObjectManager->GetProxyForObject
668 (NS_PROXY_TO_CURRENT_THREAD,
671 nsIProxyObjectManager::INVOKE_ASYNC |
672 nsIProxyObjectManager::FORCE_PROXY_CREATION,
674 NS_ENSURE_SUCCESS(rv, rv);
683 if (!gUSBMassStorageDeviceLog) {
684 gUSBMassStorageDeviceLog = PR_NewLogModule(
"sbDeviceBase");
697 NS_ENSURE_TRUE(
mDeviceQueues.Init(), NS_ERROR_OUT_OF_MEMORY);
699 NS_ENSURE_TRUE(
mDeviceStates.Init(), NS_ERROR_OUT_OF_MEMORY);
708 NS_ENSURE_ARG_POINTER(aCallback);
710 nsRefPtr<sbDeviceBaseCallbackProxy> callbackProxy;
715 NS_ENSURE_TRUE(callbackProxy, NS_ERROR_OUT_OF_MEMORY);
716 rv = callbackProxy->Init(aCallback);
717 NS_ENSURE_SUCCESS(rv, rv);
723 return NS_ERROR_OUT_OF_MEMORY;
729 NS_ENSURE_ARG_POINTER(aCallback);
739 nsCOMArray<sbIDeviceBaseCallback> *
array =
static_cast<nsCOMArray<sbIDeviceBaseCallback> *
>(closure);
740 array->AppendObject(data->mCallbackProxy);
741 return PL_DHASH_NEXT;
747 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
748 PRUint32 callbackCount = 0;
749 nsCOMArray<sbIDeviceBaseCallback> callbackSnapshot;
752 callbackCount = callbackSnapshot.Count();
756 for(PRUint32
i = 0;
i < callbackCount;
i++)
758 nsCOMPtr<sbIDeviceBaseCallback>
callback = callbackSnapshot.ObjectAt(
i);
761 callback->OnTransferStart(aMediaItem);
765 NS_ERROR(
"pCallback->OnTransferStart threw an exception");
775 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
776 PRUint32 callbackCount = 0;
777 nsCOMArray<sbIDeviceBaseCallback> callbackSnapshot;
780 callbackCount = callbackSnapshot.Count();
784 for(PRUint32
i = 0;
i < callbackCount;
i++)
786 nsCOMPtr<sbIDeviceBaseCallback>
callback = callbackSnapshot.ObjectAt(
i);
789 callback->OnTransferComplete(aMediaItem, aStatus);
793 NS_ERROR(
"pCallback->OnTransferComplete threw an exception");
802 PRUint32 callbackCount = 0;
803 nsCOMArray<sbIDeviceBaseCallback> callbackSnapshot;
806 callbackCount = callbackSnapshot.Count();
810 for(PRUint32
i = 0;
i < callbackCount;
i++)
812 nsCOMPtr<sbIDeviceBaseCallback>
callback = callbackSnapshot.ObjectAt(
i);
815 callback->OnDeviceConnect(aDeviceString);
819 NS_ERROR(
"pCallback->OnDeviceConnect threw an exception");
828 PRUint32 callbackCount = 0;
829 nsCOMArray<sbIDeviceBaseCallback> callbackSnapshot;
832 callbackCount = callbackSnapshot.Count();
836 for(PRUint32
i = 0;
i < callbackCount;
i++)
838 nsCOMPtr<sbIDeviceBaseCallback>
callback = callbackSnapshot.ObjectAt(
i);
841 callback->OnDeviceDisconnect(aDeviceString);
845 NS_ERROR(
"pCallback->OnDeviceDisconnect threw an exception");
855 PRUint32 callbackCount = 0;
856 nsCOMArray<sbIDeviceBaseCallback> callbackSnapshot;
859 callbackCount = callbackSnapshot.Count();
863 for(PRUint32
i = 0;
i < callbackCount;
i++)
865 nsCOMPtr<sbIDeviceBaseCallback>
callback = callbackSnapshot.ObjectAt(
i);
868 callback->OnStateChanged(aDeviceString, aState);
872 NS_ERROR(
"pCallback->OnStateChanged threw an exception");
880 nsIURI *aDeviceDatabaseURI,
883 NS_ENSURE_ARG_POINTER(aDevice);
886 nsCOMPtr<sbILibraryFactory> libraryFactory =
888 NS_ENSURE_SUCCESS(rv, rv);
890 nsCOMPtr<nsIWritablePropertyBag2> libraryProps =
891 do_CreateInstance(
"@mozilla.org/hash-property-bag;1", &rv);
892 NS_ENSURE_SUCCESS(rv, rv);
894 nsCOMPtr<nsIFile> libraryFile;
895 if(aDeviceDatabaseURI) {
897 nsCOMPtr<nsIFileURL> furl = do_QueryInterface(aDeviceDatabaseURI, &rv);
898 NS_ENSURE_SUCCESS(rv, rv);
900 rv = furl->GetFile(getter_AddRefs(libraryFile));
901 NS_ENSURE_SUCCESS(rv, rv);
906 getter_AddRefs(libraryFile));
907 NS_ENSURE_SUCCESS(rv, rv);
909 rv = libraryFile->Append(NS_LITERAL_STRING(
"db"));
910 NS_ENSURE_SUCCESS(rv, rv);
912 PRBool exists = PR_FALSE;
913 rv = libraryFile->Exists(&exists);
914 NS_ENSURE_SUCCESS(rv, rv);
916 rv = libraryFile->Create(nsIFile::DIRECTORY_TYPE, 0700);
917 NS_ENSURE_SUCCESS(rv, rv);
920 nsAutoString filename(aDeviceIdentifier);
921 filename.AppendLiteral(
".db");
923 rv = libraryFile->Append(filename);
924 NS_ENSURE_SUCCESS(rv, rv);
927 rv = libraryProps->SetPropertyAsInterface(NS_LITERAL_STRING(
"databaseFile"),
929 NS_ENSURE_SUCCESS(rv, rv);
934 if(NS_SUCCEEDED(libraryFile->GetNativePath(str))) {
935 LOG((
"Attempting to create device library with file path %s", str.get()));
940 nsCOMPtr<sbILibrary> library;
941 rv = libraryFactory->CreateLibrary(libraryProps, getter_AddRefs(library));
942 NS_ENSURE_SUCCESS(rv, rv);
944 nsRefPtr<sbDeviceBaseLibraryListener>
listener;
946 NS_ENSURE_TRUE(listener, NS_ERROR_OUT_OF_MEMORY);
948 rv = listener->Init(aDeviceIdentifier, aDevice);
949 NS_ENSURE_SUCCESS(rv, rv);
951 nsCOMPtr<sbIMediaList> list;
952 list = do_QueryInterface(library, &rv);
953 NS_ENSURE_SUCCESS(rv, rv);
955 rv = list->AddListener(listener,
962 NS_ENSURE_SUCCESS(rv, rv);
965 NS_ENSURE_SUCCESS(rv, rv);
967 nsCOMPtr<sbILocalDatabaseSimpleMediaList> simpleList;
968 simpleList = do_QueryInterface(list, &rv);
970 if(NS_SUCCEEDED(rv)) {
971 nsRefPtr<sbDeviceBaseLibraryCopyListener> copyListener;
973 NS_ENSURE_TRUE(copyListener, NS_ERROR_OUT_OF_MEMORY);
975 rv = copyListener->Init(aDeviceIdentifier, aDevice);
976 NS_ENSURE_SUCCESS(rv, rv);
978 rv = simpleList->SetCopyListener(copyListener);
979 NS_ENSURE_SUCCESS(rv, rv);
983 "Failed to get sbILocalDatabaseSimpleMediaList interface. Copy Listener disabled.");
990 return NS_ERROR_OUT_OF_MEMORY;
1004 NS_ENSURE_ARG_POINTER(aDeviceLibrary);
1006 if(
mDeviceLibraries.Get(nsAutoString(aDeviceIdentifier), aDeviceLibrary)) {
1010 return NS_ERROR_INVALID_ARG;
1016 NS_ENSURE_ARG_POINTER(aDeviceLibrary);
1021 do_GetService(
"@songbirdnest.com/Songbird/library/Manager;1", &rv);
1022 NS_ENSURE_SUCCESS(rv, rv);
1024 return libraryManager->RegisterLibrary(aDeviceLibrary, PR_FALSE);
1030 NS_ENSURE_ARG_POINTER(aDeviceLibrary);
1035 do_GetService(
"@songbirdnest.com/Songbird/library/Manager;1", &rv);
1036 NS_ENSURE_SUCCESS(rv, rv);
1038 return libraryManager->UnregisterLibrary(aDeviceLibrary);
1045 nsCOMPtr<nsIMutableArray> deviceQueue =
1046 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
1047 NS_ENSURE_SUCCESS(rv, rv);
1049 if(
mDeviceQueues.Put(nsAutoString(aDeviceIdentifier), deviceQueue)) {
1053 return NS_ERROR_OUT_OF_MEMORY;
1067 NS_ENSURE_ARG_POINTER(aMediaItem);
1069 nsCOMPtr<nsIMutableArray> deviceQueue;
1070 if(
mDeviceQueues.Get(aDeviceIdentifier, getter_AddRefs(deviceQueue))) {
1071 return deviceQueue->AppendElement(aMediaItem, PR_FALSE);
1074 return NS_ERROR_INVALID_ARG;
1081 NS_ENSURE_ARG_POINTER(aMediaItem);
1086 nsCOMPtr<nsIMutableArray> deviceQueue;
1087 if(
mDeviceQueues.Get(aDeviceIdentifier, getter_AddRefs(deviceQueue))) {
1088 rv = deviceQueue->IndexOf(0, aMediaItem, &index);
1089 NS_ENSURE_SUCCESS(rv, rv);
1091 return deviceQueue->RemoveElementAt(index);
1101 NS_ENSURE_ARG_POINTER(aMediaItem);
1103 nsCOMPtr<nsIMutableArray> deviceQueue;
1104 if(
mDeviceQueues.Get(aDeviceIdentifier, getter_AddRefs(deviceQueue))) {
1105 return deviceQueue->QueryElementAt(0,
1107 (
void **)aMediaItem);
1110 return NS_ERROR_INVALID_ARG;
1115 PRUint32 aItemIndex,
1118 NS_ENSURE_ARG_POINTER(aMediaItem);
1120 nsCOMPtr<nsIMutableArray> deviceQueue;
1121 if(
mDeviceQueues.Get(aDeviceIdentifier, getter_AddRefs(deviceQueue))) {
1122 return deviceQueue->QueryElementAt(aItemIndex,
1124 (
void **)aMediaItem);
1127 return NS_ERROR_INVALID_ARG;
1132 nsIMutableArray* *aTransferQueue)
1134 NS_ENSURE_ARG_POINTER(aTransferQueue);
1136 *aTransferQueue = nsnull;
1141 return NS_ERROR_INVALID_ARG;
1147 nsCOMPtr<nsIMutableArray> deviceQueue;
1148 if(
mDeviceQueues.Get(nsAutoString(aDeviceIdentifier), getter_AddRefs(deviceQueue))) {
1149 return deviceQueue->Clear();
1152 return NS_ERROR_INVALID_ARG;
1161 nsCOMPtr<nsIMutableArray> queue;
1163 NS_ENSURE_SUCCESS(rv, rv);
1165 PRUint32 length = 0;
1166 rv = queue->GetLength(&length);
1167 NS_ENSURE_SUCCESS(rv, rv);
1178 PRUint32* aDeviceState)
1180 NS_ENSURE_ARG_POINTER(aDeviceState);
1187 return NS_ERROR_INVALID_ARG;
1192 PRUint32 aDeviceState)
1197 PRUint32 currentState;
1198 NS_ENSURE_TRUE(
mDeviceStates.Get(aDeviceIdentifier, ¤tState),
1199 NS_ERROR_INVALID_ARG);
1201 if (aDeviceState != currentState)
1206 return NS_ERROR_OUT_OF_MEMORY;
1216 return NS_ERROR_OUT_OF_MEMORY;
1232 NS_ENSURE_ARG_POINTER(aMediaListListener);
1238 return NS_ERROR_OUT_OF_MEMORY;
1245 NS_ENSURE_ARG_POINTER(aMediaListListener);
1251 return NS_ERROR_INVALID_ARG;
1257 nsCOMPtr<sbILibrary> library;
1258 nsCOMPtr<sbIMediaListListener>
listener;
1264 nsCOMPtr<sbIMediaList> list;
1266 list = do_QueryInterface(library, &rv);
1267 NS_ENSURE_SUCCESS(rv, rv);
1269 rv = list->RemoveListener(listener);
1270 NS_ENSURE_SUCCESS(rv, rv);
1277 return NS_ERROR_INVALID_ARG;
nsresult GetListenerForDeviceLibrary(const nsAString &aDeviceIdentifier, sbIMediaListListener **aMediaListListener)
nsresult RemoveItemFromTransferQueue(const nsAString &aDeviceIdentifier, sbIMediaItem *aMediaItem)
Remove an item from the internal transfer queue.
const unsigned long OP_UPLOAD
Device Operation Constants.
nsresult SetIgnoreListener(PRBool aIgnoreListener)
void ReplaceChars(nsAString &aOldString, const nsAString &aOldChars, const PRUnichar aNewChar)
void DoStateChangedCallback(const nsAString &aDeviceIdentifier, PRUint32 aState)
nsString mDeviceIdentifier
EnumDeviceCallback(nsISupports *key, sbDeviceBaseCallbackProxy *data, void *closure)
virtual ~sbDeviceBaseLibraryCopyListener()
nsresult SetDeviceState(const nsAString &aDeviceIdentifier, PRUint32 aDeviceState)
PR_STATIC_CALLBACK(PRBool) FindElementCallback(void *aElement
nsresult Init(sbBaseDevice *aDevice)
nsresult GetDeviceState(const nsAString &aDeviceIdentifier, PRUint32 *aDeviceState)
nsresult IsTransferQueueEmpty(const nsAString &aDeviceIdentifier, PRBool &aEmpty)
nsresult UnregisterDeviceLibrary(sbILibrary *aDeviceLibrary)
Unregister a device library with the library manager.
nsresult GetLibraryForDevice(const nsAString &aDeviceIdentifier, sbILibrary **aDeviceLibrary)
Get the library instance for a device.
nsInterfaceHashtableMT< nsStringHashKey, nsIMutableArray > mDeviceQueues
nsresult SetManagePlaylists(PRBool aManagePlaylists)
nsClassHashtable< nsISupportsHashKey, sbRemovedItemIndexes > mBeforeRemoveIndexes
[SOON TO BE DEPRECATED AFTER 0.3] The callback class for sbIDeviceBase
nsCOMPtr< nsIEventTarget > mOwningThread
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
nsresult Init(const nsAString &aDeviceIdentifier, sbIDeviceBase *aDevice)
nsresult CreateTransferQueue(const nsAString &aDeviceIdentifier)
Create an internal transfer queue for a device instance.
nsresult GetTransferQueue(const nsAString &aDeviceIdentifier, nsIMutableArray **aTransferQueue)
Get the internnal transfer queue for a device instance.
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
#define SB_LOCALDATABASE_LIBRARYFACTORY_CONTRACTID
[SOON TO BE DEPRECATED AFTER 0.3] Base interface for all supported devices.
nsresult InitDeviceState(const nsAString &aDeviceIdentifier)
nsDataHashtableMT< nsStringHashKey, PRUint32 > mDeviceStates
NS_IMPL_THREADSAFE_ISUPPORTS1(sbDeviceBaseLibraryListener, sbIMediaListListener)
nsCOMPtr< sbIDeviceBaseCallback > mCallbackProxy
NS_DECL_ISUPPORTS NS_DECL_SBILOCALDATABASEMEDIALISTCOPYLISTENER sbDeviceBaseLibraryCopyListener()
nsresult RemoveTransferQueue(const nsAString &aDeviceIdentifier)
Remove an internal transfer queue for a device instance.
const PRUint32 STATE_IDLE
const PRUint32 STATE_DELETING
nsresult AddCallback(sbIDeviceBaseCallback *aCallback)
virtual ~sbDeviceBaseLibraryListener()
nsInterfaceHashtableMT< nsStringHashKey, sbILibrary > mDeviceLibraries
nsresult SetListenerForDeviceLibrary(const nsAString &aDeviceIdentifier, sbIMediaListListener *aMediaListListener)
static PLDHashOperator PR_CALLBACK ShiftIndexesCallback(nsISupportsHashKey::KeyType aKey, PRUint32 &aEntry, void *aUserData)
nsresult AddItemToTransferQueue(const nsAString &aDeviceIdentifier, sbIMediaItem *aMediaItem)
Add an item to the internal transfer queue.
nsresult GetNextItemFromTransferQueue(const nsAString &aDeviceIdentifier, sbIMediaItem **aMediaItem)
Get the next item in the transfer queue.
Media library abstraction.
nsresult CreateDeviceLibrary(const nsAString &aDeviceIdentifier, nsIURI *aDeviceDatabaseURI, sbIDeviceBase *aDevice)
Create a library for a device instance.
nsresult Init()
Initialize the base device class for use.
void DoDeviceDisconnectCallback(const nsAString &aDeviceIdentifier)
nsresult RegisterDeviceLibrary(sbILibrary *aDeviceLibrary)
Register a device library with the library manager.
NS_DECL_ISUPPORTS NS_DECL_SBIMEDIALISTLISTENER sbDeviceBaseLibraryListener()
nsresult RemoveCallback(sbIDeviceBaseCallback *aCallback)
void DoTransferStartCallback(sbIMediaItem *aMediaItem)
nsresult RemoveListenerForDeviceLibrary(const nsAString &aDeviceIdentifier)
nsInterfaceHashtableMT< nsStringHashKey, sbIMediaListListener > mDeviceLibraryListeners
nsresult RemoveDeviceLibrary(const nsAString &aDeviceIdentifier)
Remove a library for a device instance.
nsresult GetItemByIndexFromTransferQueue(const nsAString &aDeviceIdentifier, PRUint32 aItemIndex, sbIMediaItem **aMediaItem)
Get an item from the transfer queue by index.
nsRefPtrHashtableMT< nsISupportsHashKey, sbDeviceBaseCallbackProxy > mDeviceCallbacks
nsresult ClearTransferQueue(const nsAString &aDeviceIdentifier)
Clear the entire transfer queue.
void DoDeviceConnectCallback(const nsAString &aDeviceIdentifier)
nsresult ClearDeviceState(const nsAString &aDeviceIdentifier)
nsresult Init(sbIDeviceBaseCallback *aCallback)
void DoTransferCompleteCallback(sbIMediaItem *aMediaItem, PRInt32 aStatus)
nsDataHashtable< nsISupportsHashKey, PRUint32 > sbRemovedItemIndexes
const unsigned long OP_DOWNLOAD
nsString mDeviceIdentifier
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
virtual ~sbDeviceBaseCallbackProxy()
Songbird DeviceBase Component Definition.
_getSelectedPageStyle s i