54 #include <sbIDeviceEvent.h>
58 extern PRLogModuleInfo* gBaseDeviceLog;
62 #define LOG(args) PR_LOG(gBaseDeviceLog, PR_LOG_WARN, args)
105 PRUint32 aBatchCount) :
107 mBatchCount(aBatchCount),
109 mResult(NS_ERROR_FAILURE),
112 PRBool copyAfterTranscode =
114 mRequest->destinationCompatibility ==
117 const PRUint32 batchIndex = mRequest->GetBatchIndex();
126 if (batchIndex == 0 ||
127 (copyAfterTranscode && batchIndex == aBatchCount - 1)) {
136 !copyAfterTranscode);
140 mStatus->ItemStart(mRequest->list,
154 mResult(NS_ERROR_FAILURE),
169 PRInt32 aBatchCount) :
171 mBatchCount(aBatchCount),
173 mResult(NS_ERROR_FAILURE),
191 const PRUint32 batchIndex = mRequest->GetBatchIndex() + 1;
193 mStatus->ItemComplete(mResult);
195 if (batchIndex == mBatchCount) {
196 mStatus->OperationComplete(mResult);
207 aDestination = *
this;
214 sbDeviceStatusAutoOperationComplete::operator = (
217 mRequest = aOther.mRequest;
218 mBatchCount = aOther.mBatchCount;
220 mResult = aOther.mResult;
261 mOperationType = aOperationType;
263 mMediaList = aMediaList;
266 mMediaItem = aMediaItem;
270 mItemCount = aItemCount;
271 mItemType = aItemType;
277 switch (mOperationType)
280 LOG((
"sbDeviceStatusHelper::OperationStart mount\n"));
282 NS_LITERAL_STRING(
"Starting"),
293 LOG((
"sbDeviceStatusHelper::OperationStart write\n"));
295 NS_LITERAL_STRING(
"Starting"),
306 LOG((
"sbDeviceStatusHelper::OperationStart transcode\n"));
308 NS_LITERAL_STRING(
"Starting"),
319 LOG((
"sbDeviceStatusHelper::OperationStart delete\n"));
321 NS_LITERAL_STRING(
"Starting"),
332 LOG((
"sbDeviceStatusHelper::OperationStart read\n"));
334 NS_LITERAL_STRING(
"Starting"),
345 LOG((
"sbDeviceStatusHelper::OperationStart format\n"));
347 NS_LITERAL_STRING(
"Starting"),
358 LOG((
"sbDeviceStatusHelper::OperationStart download\n"));
360 NS_LITERAL_STRING(
"Starting"),
386 nsString stateMessage;
387 if (NS_SUCCEEDED(aResult))
388 stateMessage.AssignLiteral(
"Completed");
390 stateMessage.AssignLiteral(
"Failed");
393 LOG((
"sbDeviceStatusHelper::OperationComplete %s.\n",
394 NS_ConvertUTF16toUTF8(stateMessage).
get()));
395 switch(mOperationType)
398 LOG((
"sbDeviceStatusHelper::OperationComplete mount.\n"));
411 LOG((
"sbDeviceStatusHelper::OperationComplete write.\n"));
424 LOG((
"sbDeviceStatusHelper::OperationStart transcode\n"));
434 LOG((
"sbDeviceStatusHelper::OperationComplete read.\n"));
447 LOG((
"sbDeviceStatusHelper::OperationComplete delete.\n"));
460 LOG((
"sbDeviceStatusHelper::OperationComplete format.\n"));
473 LOG((
"sbDeviceStatusHelper::OperationComplete download\n"));
516 mItemCount = aItemCount;
519 mItemType = aItemType;
522 switch(mOperationType)
525 LOG((
"sbDeviceStatusHelper::ItemStart mount\n"));
527 NS_LITERAL_STRING(
"InProgress"),
538 LOG((
"sbDeviceStatusHelper::ItemStart write\n"));
540 NS_LITERAL_STRING(
"InProgress"),
550 LOG((
"sbDeviceStatusHelper::ItemStart delete\n"));
552 NS_LITERAL_STRING(
"InProgress"),
562 LOG((
"sbDeviceStatusHelper::ItemStart transcode\n"));
564 NS_LITERAL_STRING(
"Starting"),
575 LOG((
"sbDeviceStatusHelper::ItemStart read\n"));
577 NS_LITERAL_STRING(
"InProgress"),
588 LOG((
"sbDeviceStatusHelper::ItemStart download\n"));
590 NS_LITERAL_STRING(
"Starting"),
627 NS_ENSURE_TRUE(aMediaItem, );
630 mMediaList = aMediaList;
631 mMediaItem = aMediaItem;
634 ItemStart(aItemNum, aItemCount, aItemType);
649 switch(mOperationType)
652 LOG((
"sbDeviceStatusHelper::ItemProgress write\n"));
654 NS_LITERAL_STRING(
"InProgress"),
665 LOG((
"sbDeviceStatusHelper::ItemProgress transcode\n"));
667 NS_LITERAL_STRING(
"InProgress"),
678 LOG((
"sbDeviceStatusHelper::ItemProcess read\n"));
680 NS_LITERAL_STRING(
"InProgress"),
691 LOG((
"sbDeviceStatusHelper::ItemProgress download\n"));
693 NS_LITERAL_STRING(
"InProgress"),
720 if (NS_FAILED(aResult)) {
728 switch(mOperationType)
733 LOG((
"sbDeviceStatusHelper::ItemComplete write/transcode/download\n"));
740 LOG((
"sbDeviceStatusHelper::ItemComplete read\n"));
779 rv = mDevice->GetId(&deviceID);
780 NS_ENSURE_SUCCESS(rv, rv);
785 do_CreateInstance(
"@songbirdnest.com/Songbird/Device/DeviceStatus;1", &rv);
786 NS_ENSURE_SUCCESS(rv, rv);
789 char deviceIDString[NSID_LENGTH];
790 deviceID->ToProvidedString(deviceIDString);
791 rv =
mStatus->Init(NS_ConvertASCIItoUTF16(deviceIDString, NSID_LENGTH-1));
792 NS_ENSURE_SUCCESS(rv, rv);
812 NS_ENSURE_TRUE(
mStatus, NS_ERROR_NOT_INITIALIZED);
815 PRUint32 currentState;
816 PRUint32 currentSubState;
817 rv =
mStatus->GetCurrentState(¤tState);
818 NS_ENSURE_SUCCESS(rv, rv);
819 rv =
mStatus->GetCurrentSubState(¤tSubState);
820 NS_ENSURE_SUCCESS(rv, rv);
823 rv =
mStatus->SetMediaItem(nsnull);
824 NS_ENSURE_SUCCESS(rv, rv);
825 rv =
mStatus->SetMediaList(nsnull);
826 NS_ENSURE_SUCCESS(rv, rv);
831 PRBool changeMainState = PR_TRUE;
837 changeMainState = PR_FALSE;
842 PRUint32
state, subState;
843 if (changeMainState) {
847 state = currentState;
852 LOG((
"sbDeviceStatusHelper::ChangeState change state from %s:%s to %s:%s\n",
859 if (state != currentState) {
860 rv =
mStatus->SetCurrentState(state);
861 NS_ENSURE_SUCCESS(rv, rv);
863 NS_ENSURE_SUCCESS(rv, rv);
865 rv =
mStatus->SetCurrentSubState(subState);
866 NS_ENSURE_SUCCESS(rv, rv);
881 NS_ENSURE_ARG_POINTER(aCurrentStatus);
883 NS_IF_ADDREF(*aCurrentStatus =
mStatus);
901 const nsAString& aStateMessage,
910 LOG((
"sbDeviceStatusHelper::UpdateStatus item: %d, count: %d, progress %f, type %d\n",
911 aItemNum, aItemCount, aProgress, aItemType));
913 NS_ENSURE_TRUE(
mStatus, NS_ERROR_NOT_INITIALIZED);
916 if (aItemCount > 0) {
917 rv =
mStatus->SetWorkItemProgress(aItemNum);
918 NS_ENSURE_SUCCESS(rv, rv);
919 rv =
mStatus->SetWorkItemProgressEndCount(aItemCount);
920 NS_ENSURE_SUCCESS(rv, rv);
921 rv =
mStatus->SetWorkItemType(aItemType);
922 NS_ENSURE_SUCCESS(rv, rv);
926 rv =
mStatus->SetCurrentOperation(aOperation);
927 NS_ENSURE_SUCCESS(rv, rv);
928 rv =
mStatus->SetStateMessage(aStateMessage);
929 NS_ENSURE_SUCCESS(rv, rv);
930 rv =
mStatus->SetMediaItem(mMediaItem);
931 NS_ENSURE_SUCCESS(rv, rv);
932 rv =
mStatus->SetMediaList(mMediaList);
933 NS_ENSURE_SUCCESS(rv, rv);
934 rv =
mStatus->SetProgress(aProgress);
935 NS_ENSURE_SUCCESS(rv, rv);
954 mOperationType(OPERATION_TYPE_NONE),
960 NS_ASSERTION(aDevice,
"aDevice is null");
const unsigned long EVENT_DEVICE_ERROR_UNEXPECTED
nsresult UpdateStatus(const nsAString &aOperation, const nsAString &aStateMessage, PRInt32 aItemNum, PRInt32 aItemCount, double aProgress, PRInt32 aItemType=0)
static const char * gDeviceStateStringList[]
nsresult CreateAndDispatchEvent(PRUint32 aType, nsIVariant *aData, PRBool aAsync=PR_TRUE, sbIDeviceEventTarget *aTarget=nsnull)
nsAutoPtr< sbDeviceStatusHelper > mStatus
const unsigned long EVENT_DEVICE_TRANSCODE_START
const unsigned long EVENT_DEVICE_DOWNLOAD_START
void Transfer(sbDeviceStatusAutoOperationComplete &aDestination)
sbDeviceStatusAutoOperationComplete()
const unsigned long EVENT_DEVICE_MOUNTING_END
nsresult GetCurrentStatus(sbIDeviceStatus **aCurrentStatus)
const unsigned long EVENT_DEVICE_MOUNTING_PROGRESS
const unsigned long EVENT_DEVICE_MEDIA_READ_START
nsresult ChangeState(PRUint32 aState)
char const * DeviceStateString(PRUint32 aState)
Songbird Variant Utility Definitions.
void OperationStart(Operation aOperationType, PRInt32 aItemNum, PRInt32 aItemCount, PRInt32 aItemType, sbIMediaList *aMediaList=nsnull, sbIMediaItem *aMediaItem=nsnull, PRBool aNewBatch=PR_TRUE)
const unsigned long EVENT_DEVICE_FORMATTING_END
void OperationComplete(nsresult aResult)
sbDeviceStatusHelper(sbBaseDevice *aDevice)
const unsigned long EVENT_DEVICE_TRANSFER_END
~sbDeviceStatusAutoOperationComplete()
const unsigned long STATE_CANCEL
static bool IsItemOp(sbDeviceStatusHelper::Operation aOperation)
void ItemComplete(nsresult aResult)
const unsigned long EVENT_DEVICE_MOUNTING_START
const unsigned long STATE_IDLE
const unsigned long EVENT_DEVICE_FORMATTING_START
const unsigned long EVENT_DEVICE_MEDIA_READ_END
attribute unsigned long state
void ItemStart(PRInt32 aItemNum, PRInt32 aItemCount, PRInt32 aItemType)
const unsigned long STATE_MOUNTING
void ItemProgress(double aProgress)
const unsigned long EVENT_DEVICE_TRANSFER_START
const unsigned long STATE_SYNCING
Songbird Device Status Services Definitions.
const unsigned long EVENT_DEVICE_MEDIA_WRITE_END
const unsigned long EVENT_DEVICE_TRANSFER_PROGRESS
NS_IMETHOD SetState(PRUint32 aState)
const unsigned long EVENT_DEVICE_MEDIA_WRITE_START