55 #include <sbIDeviceEvent.h>
61 {
"IDLE",
"SYNCING",
"COPYING",
62 "DELETING",
"UPDATING",
"MOUNTING",
"DOWNLOADING",
"UPLOADING",
63 "DOWNLOAD_PAUSED",
"UPLOAD_PAUSED",
"DISCONNECTED",
"BUSY" };
64 #define STATE_STRING(X) \
65 (((X)>=0 && (X)<(sizeof(gStateStrings)/sizeof(gStateStrings[0]))) ? \
66 gStateStrings[(X)] : "unknown")
85 mOperationType(OPERATION_TYPE_NONE)
88 NS_ASSERTION(aDevice,
"aDevice is null");
114 rv = mDevice->GetId(&deviceID);
115 NS_ENSURE_SUCCESS(rv, rv);
119 char deviceIDString[NSID_LENGTH];
120 deviceID->ToProvidedString(deviceIDString);
121 mStatus = do_CreateInstance(
"@songbirdnest.com/Songbird/Device/DeviceStatus;1", &rv);
122 NS_ENSURE_SUCCESS(rv, rv);
125 char idString[NSID_LENGTH];
126 deviceID->ToProvidedString(idString);
127 rv = mStatus->Init(NS_ConvertASCIItoUTF16(idString, NSID_LENGTH-1));
128 NS_ENSURE_SUCCESS(rv, rv);
170 PRUint32 aBatchCount)
173 NS_ENSURE_TRUE(aRequest, );
177 mMediaList = aRequest->
list;
178 mMediaItem = aRequest->
item;
184 mOperationType = aOperationType;
187 switch (mOperationType)
190 FIELD_LOG((
"Starting mount operation.\n"));
192 NS_LITERAL_STRING(
"mounting"), batchIndex, aBatchCount, 0.0);
199 FIELD_LOG((
"Starting write track operation.\n"));
201 NS_LITERAL_STRING(
"copying"), batchIndex, aBatchCount, 0.0);
208 FIELD_LOG((
"Starting delete operation.\n"));
210 NS_LITERAL_STRING(
"deleting"), batchIndex, aBatchCount, 0.0);
233 nsString stateMessage;
235 if (NS_SUCCEEDED(aResult)) {
236 stateMessage.AssignLiteral(
"Completed");
238 stateMessage.AssignLiteral(
"Failed");
242 switch(mOperationType)
245 FIELD_LOG((
"Completed mount operation.\n"));
254 FIELD_LOG((
"Completed write track operation.\n"));
263 FIELD_LOG((
"Completed delete track operation.\n"));
303 switch(mOperationType)
308 NS_LITERAL_STRING(
"mount"), aItemNum, aItemCount, 0.0);
315 FIELD_LOG((
"Starting write track item %d %d.\n", aItemNum, aItemCount));
318 NS_LITERAL_STRING(
"InProgress"), aItemNum, aItemCount, 0.0);
347 NS_ENSURE_TRUE(aTrack, );
374 NS_ENSURE_TRUE(aPlaylist, );
375 NS_ENSURE_TRUE(aTrack, );
402 NS_ENSURE_TRUE(aMediaItem, );
405 mMediaList = aMediaList;
406 mMediaItem = aMediaItem;
425 mStatus->SetProgress(aProgress);
443 switch(mOperationType)
446 FIELD_LOG((
"Completed write track item.\n"));
460 NS_ENSURE_ARG(aCurrentStatus);
461 NS_IF_ADDREF(*aCurrentStatus = mStatus);
469 rv = mStatus->GetCurrentState(&oldState);
470 NS_ENSURE_SUCCESS(rv, rv);
474 PRUint32 currentState = newState;
478 rv = mStatus->SetMediaItem(nsnull);
479 NS_ENSURE_SUCCESS(rv, rv);
480 rv = mStatus->SetMediaList(nsnull);
481 NS_ENSURE_SUCCESS(rv, rv);
491 currentSubState = newState;
492 currentState = oldState;
497 if (currentState != oldState) {
498 rv = mStatus->SetCurrentState(currentState);
499 NS_ENSURE_SUCCESS(rv, rv);
507 rv = mStatus->SetCurrentSubState(currentSubState);
508 NS_ENSURE_SUCCESS(rv, rv);
514 const nsAString& currentOperation,
515 const nsAString& currentStateMessage,
516 PRInt32 currentIndex,
518 double currentProgress) {
519 LOG(
"sbIPDStatus::UpdateStatus(forState=%s, currentIndex=%d, totalCount=%d)\n",
STATE_STRING(forState), currentIndex, totalCount);
520 PRUint32 currentState;
522 rv = mStatus->GetCurrentState(¤tState);
523 NS_ENSURE_SUCCESS(rv, rv);
526 if (totalCount != 0) {
527 rv = mStatus->SetWorkItemProgress(currentIndex + 1);
528 NS_ENSURE_SUCCESS(rv, rv);
529 rv = mStatus->SetWorkItemProgressEndCount(totalCount);
530 NS_ENSURE_SUCCESS(rv, rv);
533 rv = mStatus->SetCurrentOperation(currentOperation);
534 NS_ENSURE_SUCCESS(rv, rv);
535 rv = mStatus->SetStateMessage(currentStateMessage);
536 NS_ENSURE_SUCCESS(rv, rv);
537 rv = mStatus->SetMediaItem(mMediaItem);
538 NS_ENSURE_SUCCESS(rv, rv);
539 rv = mStatus->SetMediaList(mMediaList);
540 NS_ENSURE_SUCCESS(rv, rv);
541 rv = mStatus->SetProgress(currentProgress);
542 NS_ENSURE_SUCCESS(rv, rv);
550 LOG(
"sbIPDStatus::Idle()\n");
nsresult CreateAndDispatchEvent(PRUint32 aType, nsIVariant *aData, PRBool aAsync=PR_TRUE, sbIDeviceEventTarget *aTarget=nsnull)
#define SB_PRLOG_SETUP(x)
void OperationComplete(nsresult aResult)
const unsigned long STATE_DELETING
const unsigned long EVENT_DEVICE_MOUNTING_END
Songbird iPod Device Utility Definitions.
void ItemComplete(nsresult aResult)
const unsigned long EVENT_DEVICE_MOUNTING_PROGRESS
nsresult GetCurrentStatus(sbIDeviceStatus **aCurrentStatus)
nsresult ChangeStatus(PRUint32 newState)
void ItemStart(PRInt32 aItemNum=-1, PRInt32 aItemCount=-1)
Songbird iPod Device Status Definitions.
const unsigned long EVENT_DEVICE_TRANSFER_END
static const char * SB_UNUSED_IN_RELEASE(gStateStrings[])
PRUint32 GetBatchIndex() const
const unsigned long STATE_COPYING
Songbird iPod Device Definitions.
sbIPDStatus(sbIPDDevice *aDevice)
const unsigned long EVENT_DEVICE_MOUNTING_START
static const PRUint32 OPERATION_TYPE_DELETE
const unsigned long STATE_IDLE
nsresult UpdateStatus(PRUint32 forState, const nsAString ¤tOperation, const nsAString ¤tStateMessage, PRInt32 currentIndex, PRInt32 totalCount, double currentProgress)
Songbird iPod Device Logging Definitions.
const unsigned long STATE_MOUNTING
const unsigned long EVENT_DEVICE_TRANSFER_START
void ItemProgress(double aProgress)
const unsigned long STATE_SYNCING
nsCOMPtr< sbIMediaItem > item
const unsigned long EVENT_DEVICE_MEDIA_WRITE_END
static const PRUint32 OPERATION_TYPE_MOUNT
const unsigned long EVENT_DEVICE_TRANSFER_PROGRESS
NS_IMETHOD SetState(PRUint32 aState)
const unsigned long EVENT_DEVICE_MEDIA_WRITE_START
static const PRUint32 OPERATION_TYPE_WRITE
nsCOMPtr< sbIMediaList > list
void OperationStart(PRUint32 aOperationType, sbBaseDevice::TransferRequest *aRequest, PRUint32 aBatchCount)
static const PRUint32 OPERATION_TYPE_NONE