34 #include <nsArrayUtils.h>
42 #include <sbIDeviceEvent.h>
55 NS_ENSURE_ARG_POINTER(aBaseDevice);
57 NS_IF_RELEASE(baseDevice);
58 mBaseDevice = aBaseDevice;
59 NS_ADDREF(static_cast<sbIDevice *>(mBaseDevice));
61 NS_ENSURE_SUCCESS(rv, rv);
66 sbDeviceRequestThreadQueue::sbDeviceRequestThreadQueue() :
72 sbDeviceRequestThreadQueue::~sbDeviceRequestThreadQueue()
77 NS_IF_RELEASE(device);
94 PRBool same = PR_FALSE;
96 return (!aLeft && !aRight) ||
97 (aLeft && aRight && NS_SUCCEEDED(aLeft->Equals(aRight, &same)) &&
109 NS_ENSURE_TRUE(aRequest1,
false);
110 NS_ENSURE_TRUE(aRequest2,
false);
140 PRUint32 queueType = aQueueRequest->
GetType();
141 PRUint32 newType = aNewRequest->
GetType();
234 if (queueType == newType) {
297 newType == queueType;
307 sbDeviceRequestThreadQueue::IsDuplicateRequest(
sbRequestItem * aQueueRequest,
310 bool & aContinueChecking)
312 NS_ENSURE_ARG_POINTER(aQueueRequest);
313 NS_ENSURE_ARG_POINTER(aRequest);
323 PRUint32 type = request->
GetType();
326 bool isDuplicate = PR_FALSE;
327 PRBool continueChecking =
338 nsCOMPtr<sbIMutablePropertyArray>
341 NS_ENSURE_SUCCESS(rv, rv);
344 nsCOMPtr<sbIPropertyArray> propertyList;
345 propertyList = do_QueryInterface(queueRequest->
data, &rv);
347 if (NS_SUCCEEDED(rv)) {
348 rv = mergedPropertyList->AppendProperties(propertyList, PR_TRUE);
349 NS_ENSURE_SUCCESS(rv, rv);
352 propertyList = do_QueryInterface(request->
data, &rv);
353 NS_ENSURE_SUCCESS(rv, rv);
354 rv = mergedPropertyList->AppendProperties(propertyList, PR_TRUE);
355 NS_ENSURE_SUCCESS(rv, rv);
358 queueRequest->
data = mergedPropertyList;
364 PRUint32 queueType = aQueueRequest->
GetType();
373 queueRequest->
item = queueRequest->
list;
374 nsCOMPtr<sbILibrary> library;
375 queueRequest->
list->GetLibrary(getter_AddRefs(library));
376 queueRequest->
list = library;
386 aIsDuplicate = isDuplicate;
387 aContinueChecking = continueChecking;
392 void sbDeviceRequestThreadQueue::CompleteRequests() {
397 nsAutoLock lock(
mLock);
401 NS_WARNING(
"Failed to clear cancel state of aborted device");
407 nsresult sbDeviceRequestThreadQueue::CleanupBatch(Batch & aBatch)
412 nsInterfaceHashtable<nsISupportsHashKey, nsIMutableArray> groupedItems;
430 PRUint32 type = request->
GetType();
440 nsCOMPtr<nsIMutableArray> items;
441 groupedItems.Get(request->
list, getter_AddRefs(items));
443 items = do_CreateInstance(
444 "@songbirdnest.com/moz/xpcom/threadsafe-array;1",
446 NS_ENSURE_TRUE(groupedItems.Put(request->
list, items),
447 NS_ERROR_OUT_OF_MEMORY);
449 rv = items->AppendElement(request->
item, PR_FALSE);
450 NS_ENSURE_SUCCESS(rv, rv);
459 groupedItems.Enumerate(RemoveLibraryEnumerator, mBaseDevice);
465 nsresult sbDeviceRequestThreadQueue::OnThreadStop()
472 rv = mBaseDevice->DeviceSpecificDisconnect();
473 NS_ENSURE_SUCCESS(rv, rv);
481 mBaseDevice = nsnull;
482 NS_IF_RELEASE(device);
485 NS_WARNING(
"mBaseDevice is null in "
486 "sbDeviceRequestThreadActions::OnThreadShutdown");
492 sbDeviceRequestThreadQueue::RemoveLibraryEnumerator(
494 nsCOMPtr<nsIMutableArray> & aItems,
497 NS_ENSURE_TRUE(aList, PL_DHASH_NEXT);
498 NS_ENSURE_TRUE(aItems, PL_DHASH_NEXT);
504 "sbDeviceRequestThreadQueue::RemoveLibraryEnumerator called "
505 "with a device that does not have mLibraryListener set");
508 nsCOMPtr<nsISimpleEnumerator> enumerator;
509 nsresult rv = aItems->Enumerate(getter_AddRefs(enumerator));
510 NS_ENSURE_SUCCESS(rv, PL_DHASH_STOP);
512 nsCOMPtr<sbIMediaList> list = do_QueryInterface(aList);
514 rv = list->RemoveSome(enumerator);
515 NS_ENSURE_SUCCESS(rv, PL_DHASH_NEXT);
518 return PL_DHASH_NEXT;
522 sbDeviceRequestThreadQueue::ProcessBatch(Batch & aBatch)
526 NS_ENSURE_STATE(mBaseDevice);
531 NS_ENSURE_SUCCESS(rv, rv);
#define SB_PRLOG_SETUP(x)
PRBool IsPlaylist() const
bool GetIsProcessed() const
virtual nsresult ChangeState(PRUint32 aState)
virtual void CompleteRequests()
nsRefPtr< sbBaseDeviceLibraryListener > mLibraryListener
Songbird Variant Utility Definitions.
static bool DupeCheck(sbBaseDevice::TransferRequest *aQueueRequest, sbBaseDevice::TransferRequest *aNewRequest, bool &aIsDupe)
static sbDeviceRequestThreadQueue * New()
static bool CompareItems(sbIMediaItem *aLeft, sbIMediaItem *aRight)
sbBaseDevice::TransferRequest TransferRequest
RequestItems::const_iterator const_iterator
const unsigned long STATE_IDLE
#define TRACE_FUNCTION(...)
nsresult CreateAndDispatchDeviceManagerEvent(PRUint32 aType, nsIVariant *aData, PRBool aAsync=PR_TRUE)
const unsigned long EVENT_DEVICE_REMOVED
nsCOMPtr< sbIMediaItem > item
void SetType(PRUint32 aType)
virtual nsresult ProcessBatch(Batch &aBatch)=0
nsCOMPtr< sbIMediaList > list
static bool CompareRequestItems(sbBaseDevice::TransferRequest *aRequest1, sbBaseDevice::TransferRequest *aRequest2)
nsCOMPtr< nsISupports > data