sbDeviceStatusHelper.cpp
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4  *=BEGIN SONGBIRD GPL
5  *
6  * This file is part of the Songbird web player.
7  *
8  * Copyright(c) 2005-2011 POTI, Inc.
9  * http://www.songbirdnest.com
10  *
11  * This file may be licensed under the terms of of the
12  * GNU General Public License Version 2 (the ``GPL'').
13  *
14  * Software distributed under the License is distributed
15  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
16  * express or implied. See the GPL for the specific language
17  * governing rights and limitations.
18  *
19  * You should have received a copy of the GPL along with this
20  * program. If not, go to http://www.gnu.org/licenses/gpl.html
21  * or write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  *=END SONGBIRD GPL
25  */
26 
27 //------------------------------------------------------------------------------
28 //------------------------------------------------------------------------------
29 //
30 // Device status helper services.
31 //
32 // These services may only be used within the request lock.
33 //
34 //------------------------------------------------------------------------------
35 //------------------------------------------------------------------------------
36 
42 //------------------------------------------------------------------------------
43 //
44 // Device status helper imported services.
45 //
46 //------------------------------------------------------------------------------
47 
48 // Self imports.
49 #include "sbDeviceStatusHelper.h"
50 
51 // Local imports.
52 // Songbird imports.
53 
54 #include <sbIDeviceEvent.h>
55 #include <sbVariantUtils.h>
56 
57 #ifdef PR_LOGGING
58 extern PRLogModuleInfo* gBaseDeviceLog;
59 #endif
60 
61 #undef LOG
62 #define LOG(args) PR_LOG(gBaseDeviceLog, PR_LOG_WARN, args)
63 
64 //------------------------------------------------------------------------------
65 //
66 // Device status helper defs.
67 //
68 //------------------------------------------------------------------------------
69 
70 //
71 // gDeviceStateStringList List of device state strings.
72 // STATE_STRING Macro for getting the state string.
73 //
74 
75 static const char* gDeviceStateStringList[] = {
76  "IDLE",
77  "SYNCING",
78  "COPYING",
79  "DELETING",
80  "UPDATING",
81  "MOUNTING",
82  "DOWNLOADING",
83  "UPLOADING",
84  "DOWNLOAD_PAUSED",
85  "UPLOAD_PAUSED",
86  "DISCONNECTED",
87  "BUSY",
88  "CANCEL",
89  "TRANSCODE",
90  "FORMATTING"
91 };
92 
93 inline char const *
95 {
96  return aState < NS_ARRAY_LENGTH(gDeviceStateStringList) ?
97  gDeviceStateStringList[aState] : "unknown";
98 }
99 
100 
102  sbDeviceStatusHelper * aStatus,
104  TransferRequest * aRequest,
105  PRUint32 aBatchCount) :
106  mRequest(aRequest),
107  mBatchCount(aBatchCount),
108  mStatus(aStatus),
109  mResult(NS_ERROR_FAILURE),
110  mOperation(aOperation)
111 {
112  PRBool copyAfterTranscode =
114  mRequest->destinationCompatibility ==
116 
117  const PRUint32 batchIndex = mRequest->GetBatchIndex();
118 
119  // If this is the start of a batch or is not a batch thingy do start op.
120  //
121  // Some device has two phases for transcoding (MTP for example).
122  // If this is the last copying operation in the queue after the last
123  // transcoding, do a start op (initialization). The values have been
124  // destroyed by the auto complete destructor of the last transcoding
125  // operation already.
126  if (batchIndex == 0 ||
127  (copyAfterTranscode && batchIndex == aBatchCount - 1)) {
128 
129  // Not a new batch if this is a write operation after transcoding.
130  mStatus->OperationStart(mOperation,
131  batchIndex + 1,
132  aBatchCount,
133  mRequest->itemType,
134  IsItemOp(mOperation) ? mRequest->list : nsnull,
135  IsItemOp(mOperation) ? mRequest->item : nsnull,
136  !copyAfterTranscode);
137  }
138  if (IsItemOp(mOperation)) {
139  // Update item status
140  mStatus->ItemStart(mRequest->list,
141  mRequest->item,
142  batchIndex + 1,
143  aBatchCount,
144  mRequest->itemType);
145  }
146 }
147 
149  sbDeviceStatusHelper * aStatus,
150  sbDeviceStatusHelper::Operation aOperation) :
151  mRequest(nsnull),
152  mBatchCount(0),
153  mStatus(aStatus),
154  mResult(NS_ERROR_FAILURE),
155  mOperation(aOperation)
156 {
157  mStatus->OperationStart(mOperation,
158  -1,
159  -1,
160  -1,
161  nsnull,
162  nsnull);
163 }
164 
166  sbDeviceStatusHelper * aStatus,
168  TransferRequest * aRequest,
169  PRInt32 aBatchCount) :
170  mRequest(aRequest),
171  mBatchCount(aBatchCount),
172  mStatus(aStatus),
173  mResult(NS_ERROR_FAILURE),
174  mOperation(aOperation) {
175 
176  mStatus->OperationStart(mOperation,
177  0,
178  mBatchCount,
179  aRequest->itemType,
180  IsItemOp(mOperation) ? mRequest->list : nsnull,
181  IsItemOp(mOperation) ? mRequest->item : nsnull);
182 }
183 
185  Complete();
186 }
187 
189 {
190  if (mStatus && mRequest) {
191  const PRUint32 batchIndex = mRequest->GetBatchIndex() + 1;
192  if (IsItemOp(mOperation)) {
193  mStatus->ItemComplete(mResult);
194  }
195  if (batchIndex == mBatchCount) {
196  mStatus->OperationComplete(mResult);
197  }
198  }
199  // We've completed it, lets make sure we don't do it again
200  mStatus = nsnull;
201  mRequest = nsnull;
202 }
203 
206 {
207  aDestination = *this;
208  // Prevent us from auto completing since aDestination now will
209  mStatus = nsnull;
210  mRequest = nsnull;
211 }
212 
214 sbDeviceStatusAutoOperationComplete::operator = (
216 {
217  mRequest = aOther.mRequest;
218  mBatchCount = aOther.mBatchCount;
219  mStatus = aOther.mStatus;
220  mResult = aOther.mResult;
221  mOperation = aOther.mOperation;
222  return *this;
223 }
224 
225 
226 //------------------------------------------------------------------------------
227 //
228 // Device status helper operation services.
229 //
230 //------------------------------------------------------------------------------
231 
244 void
246  PRInt32 aItemNum,
247  PRInt32 aItemCount,
248  PRInt32 aItemType,
249  sbIMediaList* aMediaList,
250  sbIMediaItem* aMediaItem,
251  PRBool aNewBatch)
252 {
253  // Check if we're already started. The initial batch item might have
254  // completed but might not have been removed from the queue, thus
255  // we might need to "restart" the operation
256  if (aItemNum > 1 && mOperationType != OPERATION_TYPE_NONE) {
257  return;
258  }
259 
260  // Update the current operation type.
261  mOperationType = aOperationType;
262  if (aMediaList) {
263  mMediaList = aMediaList;
264  }
265  if (aMediaItem) {
266  mMediaItem = aMediaItem;
267  }
268 
269  mItemNum = aItemNum;
270  mItemCount = aItemCount;
271  mItemType = aItemType;
272 
273  if (aNewBatch)
274  mStatus->SetIsNewBatch(true);
275 
276  // Dispatch operation dependent status processing.
277  switch (mOperationType)
278  {
279  case OPERATION_TYPE_MOUNT :
280  LOG(("sbDeviceStatusHelper::OperationStart mount\n"));
281  UpdateStatus(NS_LITERAL_STRING("mounting"),
282  NS_LITERAL_STRING("Starting"),
283  aItemNum,
284  aItemCount,
285  0.0,
286  aItemType);
287  mDevice->CreateAndDispatchEvent
289  sbNewVariant(NS_ISUPPORTS_CAST(sbIDevice*, mDevice)));
290  break;
291 
292  case OPERATION_TYPE_WRITE :
293  LOG(("sbDeviceStatusHelper::OperationStart write\n"));
294  UpdateStatus(NS_LITERAL_STRING("writing"),
295  NS_LITERAL_STRING("Starting"),
296  aItemNum,
297  aItemCount,
298  0.0,
299  aItemType);
300  mDevice->CreateAndDispatchEvent
302  sbNewVariant(mMediaItem));
303  break;
304 
306  LOG(("sbDeviceStatusHelper::OperationStart transcode\n"));
307  UpdateStatus(NS_LITERAL_STRING("transcoding"),
308  NS_LITERAL_STRING("Starting"),
309  aItemNum,
310  aItemCount,
311  0.0,
312  aItemType);
313  mDevice->CreateAndDispatchEvent
315  sbNewVariant(mMediaItem));
316  break;
317 
318  case OPERATION_TYPE_DELETE :
319  LOG(("sbDeviceStatusHelper::OperationStart delete\n"));
320  UpdateStatus(NS_LITERAL_STRING("deleting"),
321  NS_LITERAL_STRING("Starting"),
322  aItemNum,
323  aItemCount,
324  0.0,
325  aItemType);
326  mDevice->CreateAndDispatchEvent
328  sbNewVariant(mMediaItem));
329  break;
330 
331  case OPERATION_TYPE_READ :
332  LOG(("sbDeviceStatusHelper::OperationStart read\n"));
333  UpdateStatus(NS_LITERAL_STRING("reading"),
334  NS_LITERAL_STRING("Starting"),
335  aItemNum,
336  aItemCount,
337  0.0,
338  aItemType);
339  mDevice->CreateAndDispatchEvent
341  sbNewVariant(mMediaItem));
342  break;
343 
344  case OPERATION_TYPE_FORMAT :
345  LOG(("sbDeviceStatusHelper::OperationStart format\n"));
346  UpdateStatus(NS_LITERAL_STRING("formatting"),
347  NS_LITERAL_STRING("Starting"),
348  0,
349  0,
350  0.0,
351  0);
352  mDevice->CreateAndDispatchEvent
354  sbNewVariant(NS_ISUPPORTS_CAST(sbIDevice*, mDevice)));
355  break;
356 
358  LOG(("sbDeviceStatusHelper::OperationStart download\n"));
359  UpdateStatus(NS_LITERAL_STRING("downloading"),
360  NS_LITERAL_STRING("Starting"),
361  aItemNum,
362  aItemCount,
363  0.0,
364  aItemType);
365  mDevice->CreateAndDispatchEvent
367  sbNewVariant(mMediaItem));
368  break;
369 
370  default :
371  break;
372  }
373 }
374 
382 void
384 {
385  // Set the state message according to the completion result.
386  nsString stateMessage;
387  if (NS_SUCCEEDED(aResult))
388  stateMessage.AssignLiteral("Completed");
389  else
390  stateMessage.AssignLiteral("Failed");
391 
392  // Dispatch operation dependent status processing.
393  LOG(("sbDeviceStatusHelper::OperationComplete %s.\n",
394  NS_ConvertUTF16toUTF8(stateMessage).get()));
395  switch(mOperationType)
396  {
397  case OPERATION_TYPE_MOUNT :
398  LOG(("sbDeviceStatusHelper::OperationComplete mount.\n"));
399  UpdateStatus(NS_LITERAL_STRING("mounting"),
400  stateMessage,
401  0,
402  0,
403  1.0,
404  mItemType);
405  mDevice->CreateAndDispatchEvent
407  sbNewVariant(NS_ISUPPORTS_CAST(sbIDevice*, mDevice)));
408  break;
409 
410  case OPERATION_TYPE_WRITE :
411  LOG(("sbDeviceStatusHelper::OperationComplete write.\n"));
412  UpdateStatus(NS_LITERAL_STRING("writing"),
413  stateMessage,
414  0,
415  0,
416  1.0,
417  mItemType);
418  mDevice->CreateAndDispatchEvent
420  sbNewVariant(mMediaItem));
421  break;
422 
424  LOG(("sbDeviceStatusHelper::OperationStart transcode\n"));
425  UpdateStatus(NS_LITERAL_STRING("transcoding"),
426  stateMessage,
427  0,
428  0,
429  1.0,
430  mItemType);
431  break;
432 
433  case OPERATION_TYPE_READ :
434  LOG(("sbDeviceStatusHelper::OperationComplete read.\n"));
435  UpdateStatus(NS_LITERAL_STRING("reading"),
436  stateMessage,
437  0,
438  0,
439  1.0,
440  mItemType);
441  mDevice->CreateAndDispatchEvent
443  sbNewVariant(mMediaItem));
444  break;
445 
446  case OPERATION_TYPE_DELETE :
447  LOG(("sbDeviceStatusHelper::OperationComplete delete.\n"));
448  UpdateStatus(NS_LITERAL_STRING("deleting"),
449  stateMessage,
450  0,
451  0,
452  1.0,
453  mItemType);
454  mDevice->CreateAndDispatchEvent
456  sbNewVariant(mMediaItem));
457  break;
458 
459  case OPERATION_TYPE_FORMAT :
460  LOG(("sbDeviceStatusHelper::OperationComplete format.\n"));
461  UpdateStatus(NS_LITERAL_STRING("formatting"),
462  stateMessage,
463  0,
464  0,
465  1.0,
466  mItemType);
467  mDevice->CreateAndDispatchEvent
469  sbNewVariant(NS_ISUPPORTS_CAST(sbIDevice*, mDevice)));
470  break;
471 
473  LOG(("sbDeviceStatusHelper::OperationComplete download\n"));
474  UpdateStatus(NS_LITERAL_STRING("downloading"),
475  stateMessage,
476  0,
477  0,
478  1.0,
479  mItemType);
480  break;
481 
482  default :
483  break;
484  }
485 
486  // Clear the current operation state.
487  mOperationType = OPERATION_TYPE_NONE;
488  mMediaList = nsnull;
489  mMediaItem = nsnull;
490 }
491 
492 
493 //------------------------------------------------------------------------------
494 //
495 // Device status helper item services.
496 //
497 //------------------------------------------------------------------------------
498 
509 void
511  PRInt32 aItemCount,
512  PRInt32 aItemType)
513 {
514  // Update current item number and item count.
515  mItemNum = aItemNum;
516  mItemCount = aItemCount;
517 
518  // Update current item type
519  mItemType = aItemType;
520 
521  // Dispatch operation dependent status processing.
522  switch(mOperationType)
523  {
524  case OPERATION_TYPE_MOUNT :
525  LOG(("sbDeviceStatusHelper::ItemStart mount\n"));
526  UpdateStatus(NS_LITERAL_STRING("mounting"),
527  NS_LITERAL_STRING("InProgress"),
528  aItemNum,
529  aItemCount,
530  0.0,
531  aItemType);
532  mDevice->CreateAndDispatchEvent
534  sbNewVariant(NS_ISUPPORTS_CAST(sbIDevice*, mDevice)));
535  break;
536 
537  case OPERATION_TYPE_WRITE :
538  LOG(("sbDeviceStatusHelper::ItemStart write\n"));
539  UpdateStatus(NS_LITERAL_STRING("writing"),
540  NS_LITERAL_STRING("InProgress"),
541  aItemNum,
542  aItemCount,
543  0.0,
544  aItemType);
545  mDevice->CreateAndDispatchEvent
547  sbNewVariant(mMediaItem));
548  break;
550  LOG(("sbDeviceStatusHelper::ItemStart delete\n"));
551  UpdateStatus(NS_LITERAL_STRING("deleting"),
552  NS_LITERAL_STRING("InProgress"),
553  aItemNum,
554  aItemCount,
555  0.0,
556  aItemType);
557  mDevice->CreateAndDispatchEvent
559  sbNewVariant(mMediaItem));
560  break;
562  LOG(("sbDeviceStatusHelper::ItemStart transcode\n"));
563  UpdateStatus(NS_LITERAL_STRING("transcoding"),
564  NS_LITERAL_STRING("Starting"),
565  aItemNum,
566  aItemCount,
567  0.0,
568  aItemType);
569  mDevice->CreateAndDispatchEvent
571  sbNewVariant(mMediaItem));
572  break;
573 
574  case OPERATION_TYPE_READ :
575  LOG(("sbDeviceStatusHelper::ItemStart read\n"));
576  UpdateStatus(NS_LITERAL_STRING("reading"),
577  NS_LITERAL_STRING("InProgress"),
578  aItemNum,
579  aItemCount,
580  0.0,
581  aItemType);
582  mDevice->CreateAndDispatchEvent
584  sbNewVariant(mMediaItem));
585  break;
586 
588  LOG(("sbDeviceStatusHelper::ItemStart download\n"));
589  UpdateStatus(NS_LITERAL_STRING("downloading"),
590  NS_LITERAL_STRING("Starting"),
591  aItemNum,
592  aItemCount,
593  0.0,
594  aItemType);
595  mDevice->CreateAndDispatchEvent
597  sbNewVariant(mMediaItem));
598  break;
599 
600  default :
601  break;
602  }
603 }
604 
605 
619 void
621  sbIMediaItem* aMediaItem,
622  PRInt32 aItemNum,
623  PRInt32 aItemCount,
624  PRInt32 aItemType)
625 {
626  // Validate arguments.
627  NS_ENSURE_TRUE(aMediaItem, /* void */);
628 
629  // Update the current media item and list.
630  mMediaList = aMediaList;
631  mMediaItem = aMediaItem;
632 
633  // Apply default status processing.
634  ItemStart(aItemNum, aItemCount, aItemType);
635 }
636 
637 
645 void
647 {
648  // Dispatch operation dependent status processing.
649  switch(mOperationType)
650  {
651  case OPERATION_TYPE_WRITE :
652  LOG(("sbDeviceStatusHelper::ItemProgress write\n"));
653  UpdateStatus(NS_LITERAL_STRING("writing"),
654  NS_LITERAL_STRING("InProgress"),
655  mItemNum,
656  mItemCount,
657  aProgress,
658  mItemType);
659  mDevice->CreateAndDispatchEvent
661  sbNewVariant(mMediaItem));
662  break;
663 
665  LOG(("sbDeviceStatusHelper::ItemProgress transcode\n"));
666  UpdateStatus(NS_LITERAL_STRING("transcoding"),
667  NS_LITERAL_STRING("InProgress"),
668  mItemNum,
669  mItemCount,
670  aProgress,
671  mItemType);
672  mDevice->CreateAndDispatchEvent
674  sbNewVariant(mMediaItem));
675  break;
676 
677  case OPERATION_TYPE_READ :
678  LOG(("sbDeviceStatusHelper::ItemProcess read\n"));
679  UpdateStatus(NS_LITERAL_STRING("reading"),
680  NS_LITERAL_STRING("InProgress"),
681  mItemNum,
682  mItemCount,
683  aProgress,
684  mItemType);
685  mDevice->CreateAndDispatchEvent
687  sbNewVariant(mMediaItem));
688  break;
689 
691  LOG(("sbDeviceStatusHelper::ItemProgress download\n"));
692  UpdateStatus(NS_LITERAL_STRING("downloading"),
693  NS_LITERAL_STRING("InProgress"),
694  mItemNum,
695  mItemCount,
696  aProgress,
697  mItemType);
698  mDevice->CreateAndDispatchEvent
700  sbNewVariant(mMediaItem));
701  break;
702 
703  default :
704  break;
705  }
706 }
707 
708 
716 void
718 {
719  // Post an error event on a failure result.
720  if (NS_FAILED(aResult)) {
721  mDevice->CreateAndDispatchEvent
723  sbNewVariant(mMediaItem),
724  PR_TRUE);
725  }
726 
727  // Dispatch operation dependent status processing.
728  switch(mOperationType)
729  {
731  case OPERATION_TYPE_WRITE :
733  LOG(("sbDeviceStatusHelper::ItemComplete write/transcode/download\n"));
734  mDevice->CreateAndDispatchEvent
736  sbNewVariant(mMediaItem));
737  break;
738 
739  case OPERATION_TYPE_READ :
740  LOG(("sbDeviceStatusHelper::ItemComplete read\n"));
741  mDevice->CreateAndDispatchEvent
743  sbNewVariant(mMediaItem));
744  break;
745 
746  default :
747  break;
748  }
749 }
750 
751 
752 //------------------------------------------------------------------------------
753 //
754 // Device status helper public services.
755 //
756 //------------------------------------------------------------------------------
757 
763 {
764  MOZ_COUNT_DTOR(sbDeviceStatusHelper);
765 }
766 
767 
772 nsresult
774 {
775  nsresult rv;
776 
777  // Get the device ID and set it up for auto-disposal.
778  nsID* deviceID;
779  rv = mDevice->GetId(&deviceID);
780  NS_ENSURE_SUCCESS(rv, rv);
781  sbAutoNSMemPtr autoDeviceID(deviceID);
782 
783  // Create the base device status object.
784  mStatus =
785  do_CreateInstance("@songbirdnest.com/Songbird/Device/DeviceStatus;1", &rv);
786  NS_ENSURE_SUCCESS(rv, rv);
787 
788  // Initialize the base status object
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);
793 
794  // Set the state to idle.
796 
797  return NS_OK;
798 }
799 
800 
807 nsresult
809 {
810  nsresult rv;
811 
812  NS_ENSURE_TRUE(mStatus, NS_ERROR_NOT_INITIALIZED);
813 
814  // Get the current state.
815  PRUint32 currentState;
816  PRUint32 currentSubState;
817  rv = mStatus->GetCurrentState(&currentState);
818  NS_ENSURE_SUCCESS(rv, rv);
819  rv = mStatus->GetCurrentSubState(&currentSubState);
820  NS_ENSURE_SUCCESS(rv, rv);
821 
822  // Reset item status.
823  rv = mStatus->SetMediaItem(nsnull);
824  NS_ENSURE_SUCCESS(rv, rv);
825  rv = mStatus->SetMediaList(nsnull);
826  NS_ENSURE_SUCCESS(rv, rv);
827  mMediaList = nsnull;
828  mMediaItem = nsnull;
829 
830  // Determine whether to change the main state or the sub-state.
831  PRBool changeMainState = PR_TRUE;
832  if (aState != sbIDevice::STATE_IDLE) {
833  if (currentState == sbIDevice::STATE_SYNCING ||
834  currentState == sbIDevice::STATE_CANCEL ||
835  (currentState == sbIDevice::STATE_MOUNTING &&
836  aState != sbIDevice::STATE_SYNCING)) {
837  changeMainState = PR_FALSE;
838  }
839  }
840 
841  // Determine the new main and sub-states.
842  PRUint32 state, subState;
843  if (changeMainState) {
844  state = aState;
845  subState = sbIDevice::STATE_IDLE;
846  } else {
847  state = currentState;
848  subState = aState;
849  }
850 
851  // Log progress.
852  LOG(("sbDeviceStatusHelper::ChangeState change state from %s:%s to %s:%s\n",
853  DeviceStateString(currentState),
854  DeviceStateString(currentSubState),
855  DeviceStateString(state),
856  DeviceStateString(subState)));
857 
858  // Update the device states.
859  if (state != currentState) {
860  rv = mStatus->SetCurrentState(state);
861  NS_ENSURE_SUCCESS(rv, rv);
862  rv = mDevice->SetState(state);
863  NS_ENSURE_SUCCESS(rv, rv);
864  }
865  rv = mStatus->SetCurrentSubState(subState);
866  NS_ENSURE_SUCCESS(rv, rv);
867 
868  return NS_OK;
869 }
870 
871 
878 nsresult
880 {
881  NS_ENSURE_ARG_POINTER(aCurrentStatus);
882 
883  NS_IF_ADDREF(*aCurrentStatus = mStatus);
884  return NS_OK;
885 }
886 
887 
899 nsresult
900 sbDeviceStatusHelper::UpdateStatus(const nsAString& aOperation,
901  const nsAString& aStateMessage,
902  PRInt32 aItemNum,
903  PRInt32 aItemCount,
904  double aProgress,
905  PRInt32 aItemType)
906 {
907  nsresult rv;
908 
909  // Log progress.
910  LOG(("sbDeviceStatusHelper::UpdateStatus item: %d, count: %d, progress %f, type %d\n",
911  aItemNum, aItemCount, aProgress, aItemType));
912 
913  NS_ENSURE_TRUE(mStatus, NS_ERROR_NOT_INITIALIZED);
914 
915  // If the current operation has items, update the work item progress and type.
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);
923  }
924 
925  // Update the status.
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);
936 
937  return NS_OK;
938 }
939 
940 //------------------------------------------------------------------------------
941 //
942 // Device status helper private services.
943 //
944 //------------------------------------------------------------------------------
945 
953  mDevice(aDevice),
954  mOperationType(OPERATION_TYPE_NONE),
955  mItemNum(-1),
956  mItemCount(-1)
957 {
958  MOZ_COUNT_CTOR(sbDeviceStatusHelper);
959  // Validate arguments.
960  NS_ASSERTION(aDevice, "aDevice is null");
961 }
962 
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)
return NS_OK
nsAutoPtr< sbDeviceStatusHelper > mStatus
Definition: sbBaseDevice.h:689
const unsigned long EVENT_DEVICE_TRANSCODE_START
const unsigned long EVENT_DEVICE_DOWNLOAD_START
void Transfer(sbDeviceStatusAutoOperationComplete &aDestination)
const unsigned long EVENT_DEVICE_MOUNTING_END
nsresult GetCurrentStatus(sbIDeviceStatus **aCurrentStatus)
const unsigned long EVENT_DEVICE_MOUNTING_PROGRESS
#define LOG(args)
const unsigned long EVENT_DEVICE_MEDIA_READ_START
nsresult ChangeState(PRUint32 aState)
char const * DeviceStateString(PRUint32 aState)
Songbird Variant Utility Definitions.
A brief description of the contents of this interface.
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)
PRUint32 mOperation
const unsigned long EVENT_DEVICE_TRANSFER_END
const unsigned long STATE_CANCEL
Definition: sbIDevice.idl:234
static bool IsItemOp(sbDeviceStatusHelper::Operation aOperation)
void ItemComplete(nsresult aResult)
const unsigned long EVENT_DEVICE_MOUNTING_START
const unsigned long STATE_IDLE
Definition: sbIDevice.idl:220
const unsigned long EVENT_DEVICE_FORMATTING_START
const unsigned long EVENT_DEVICE_MEDIA_READ_END
attribute unsigned long state
Definition: sbIDevice.idl:217
void ItemStart(PRInt32 aItemNum, PRInt32 aItemCount, PRInt32 aItemType)
const unsigned long STATE_MOUNTING
Definition: sbIDevice.idl:226
void ItemProgress(double aProgress)
const unsigned long EVENT_DEVICE_TRANSFER_START
const unsigned long STATE_SYNCING
Definition: sbIDevice.idl:221
Songbird Device Status Services Definitions.
Interface that defines a single item of media in the system.
const unsigned long EVENT_DEVICE_MEDIA_WRITE_END
const unsigned long EVENT_DEVICE_TRANSFER_PROGRESS
restoreWindow aState
NS_IMETHOD SetState(PRUint32 aState)
const unsigned long EVENT_DEVICE_MEDIA_WRITE_START