sbIPDRequest.cpp
Go to the documentation of this file.
1 /* -*- Mode: C++; 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 // iPod device request services.
31 //
32 //------------------------------------------------------------------------------
33 //------------------------------------------------------------------------------
34 
40 //------------------------------------------------------------------------------
41 //
42 // iPod device request imported services.
43 //
44 //------------------------------------------------------------------------------
45 
46 // Local imports.
47 #include "sbIPDDevice.h"
48 #include "sbIPDLog.h"
49 
50 // Songbird imports.
51 #include <sbAutoRWLock.h>
52 #include <sbIDeviceEvent.h>
53 #include <sbStandardProperties.h>
54 
55 // Mozilla imports.
56 #include <nsArrayUtils.h>
57 #include <nsThreadUtils.h>
58 #include <nsILocalFile.h>
59 
60 
61 //------------------------------------------------------------------------------
62 //
63 // iPod device request sbBaseDevice services.
64 //
65 //------------------------------------------------------------------------------
66 
67 
68 //------------------------------------------------------------------------------
69 //
70 // iPod device request handler services.
71 //
72 // All functions in the request handler services, except
73 // ReqHandleRequestAdded, must be called under the connect and request locks.
74 //
75 //------------------------------------------------------------------------------
76 
81 nsresult
82 sbIPDDevice::ProcessBatch(Batch & aBatch)
83 {
84  nsresult rv;
85 
86  // Operate under the connect lock.
87  sbAutoReadLock autoConnectLock(mConnectLock);
88  NS_ENSURE_TRUE(mConnected, NS_ERROR_NOT_AVAILABLE);
89 
90  // Set up to automatically set the state to STATE_IDLE on exit. Any device
91  // operation must change the state to not be idle. This ensures that the
92  // device is not prematurely removed (e.g., ejected) while the device content
93  // is being accessed. This is particularly important since most changes
94  // result in the iPod database or prefs files being rewritten.
95  sbIPDAutoIdle autoIdle(this);
96 
97  // Set up to auto-flush the iPod database files before returning to the idle
98  // state.
99  {
100  sbIPDAutoDBFlush autoDBFlush(this);
101 
102 
103  if (aBatch.empty()) {
104  return NS_OK;
105  }
106 
107  PRUint32 batchType = aBatch.RequestType();
108 
109  if (batchType == TransferRequest::REQUEST_WRITE) {
110 
111  // Force update of storage statistics before checking for space.
112  StatsUpdate(PR_TRUE);
113 
114  PRUint32 deviceState;
115  rv = GetState(&deviceState);
116  NS_ENSURE_SUCCESS(rv, rv);
117  }
118 
119  Batch batches[3];
121  batches[0],
122  batches[1],
123  batches[2]);
124 
125  for (PRUint32 batchIndex = 0;
126  batchIndex < NS_ARRAY_LENGTH(batches);
127  ++batchIndex) {
128  Batch & batch = batches[batchIndex];
129  const Batch::const_iterator end = batch.end();
130  for (Batch::const_iterator iter = batch.begin();
131  iter != end;
132  ++iter) {
133  // Check for abort.
134  if (IsRequestAborted()) {
135  return NS_ERROR_ABORT;
136  }
137 
138  TransferRequest * request = static_cast<TransferRequest *>(*iter);
139 
140 
141  PRUint32 type = request->GetType();
142 
143  FIELD_LOG(("Processing request 0x%08x\n", type));
144  switch(type)
145  {
147  mIPDStatus->ChangeStatus(STATE_MOUNTING);
148  ReqHandleMount(request);
149  break;
150 
152  // Handle request if space has been ensured for it.
153  mIPDStatus->ChangeStatus(STATE_COPYING);
154  ReqHandleWrite(request, batch.CountableItems());
155  }
156  break;
157 
159  mIPDStatus->ChangeStatus(STATE_DELETING);
160  ReqHandleDelete(request, batch.CountableItems());
161  break;
162 
164  mIPDStatus->ChangeStatus(STATE_DELETING);
165  ReqHandleWipe(request);
166  break;
167 
169  mIPDStatus->ChangeStatus(STATE_BUSY);
170  ReqHandleNewPlaylist(request);
171  break;
172 
174  mIPDStatus->ChangeStatus(STATE_UPDATING);
175  ReqHandleUpdate(request);
176  break;
177 
179  mIPDStatus->ChangeStatus(STATE_BUSY);
180  ReqHandleMovePlaylistTrack(request);
181  break;
182 
184  mIPDStatus->ChangeStatus(STATE_SYNCING);
185  HandleSyncRequest(request);
186  break;
187 
189  mIPDStatus->ChangeStatus(STATE_BUSY);
190  ReqHandleFactoryReset(request);
191  break;
192 
193  case REQUEST_WRITE_PREFS :
194  mIPDStatus->ChangeStatus(STATE_BUSY);
195  ReqHandleWritePrefs(request);
196  break;
197 
198  case REQUEST_SET_PROPERTY :
199  mIPDStatus->ChangeStatus(STATE_BUSY);
200  ReqHandleSetProperty(request);
201  break;
202 
203  case REQUEST_SET_PREF :
204  ReqHandleSetPref(static_cast<SetNamedValueRequest*>(request));
205  break;
206 
207  default :
208  NS_WARNING("Invalid request type.");
209  break;
210  }
211  if (IsRequestAborted()) {
212  // If we're aborting iterators will be invalid, need to exit loop
213  // to get the next batch if any.
214  break;
215  }
216  request->SetIsProcessed(true);
217  }
218  }
219  }
220 
221  return NS_OK;
222 }
223 
224 
233 void
234 sbIPDDevice::ReqHandleMount(TransferRequest * aRequest)
235 {
236  // Validate arguments.
237  NS_ASSERTION(aRequest, "aRequest is null");
238 
239  // Function variables.
240  nsresult rv;
241 
242  const PRUint32 batchIndex = aRequest->GetBatchIndex() + 1;
243 
244  // Update status and set for auto-failure.
246  aRequest,
247  batchIndex);
248 
249  sbAutoStatusOperationFailure autoStatus(mIPDStatus);
250 
251  // Force early updating of statistics to get some initial statistics for UI.
252  StatsUpdate(PR_TRUE);
253 
254  // Ignore library changes and set up to automatically stop ignoring.
255  {
256  mLibraryListener->SetIgnoreListener(PR_TRUE);
257  sbIPDAutoStopIgnoreLibrary autoStopIgnoreLibrary(mLibraryListener);
258 
259  // Process the on-the-go playlists. Do this before importing the iPod
260  // database because processing will change the on-the-go playlist names.
261  rv = ProcessOTGPlaylists();
262  NS_ENSURE_SUCCESS(rv, /* void */);
263 
264  // Import the iPod database.
265  rv = ImportDatabase();
266  NS_ENSURE_SUCCESS(rv, /* void */);
267 
268  rv = ListenToMediaLists(mDeviceLibrary);
269  NS_ENSURE_SUCCESS(rv, /* void */);
270 
271  // Show the device library.
272  rv = mDeviceLibrary->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_HIDDEN),
273  NS_LITERAL_STRING("0"));
274  NS_ENSURE_SUCCESS(rv, /* void */);
275  }
276 
277  // Update status and clear auto-failure.
278  mIPDStatus->OperationComplete(NS_OK);
279  autoStatus.forget();
280 
281  // Indicate that the device is now ready.
282  //XXXeps should have some variable that can be read by code that misses this
283  //XXXeps event (e.g., some JS that registers its handlers after mounting
284  //XXXeps completes).
287  sbIPDVariant(NS_ISUPPORTS_CAST(sbIDevice*, this)).get());
288 
289  // Force updating of statistics.
290  StatsUpdate(PR_TRUE);
291 
292  // Initiate auto-synchronization from the device.
293  //XXXeps should do this via a request so that wait on quit works.
294  SyncFromDevice();
295 }
296 
297 
306 void
307 sbIPDDevice::ReqHandleWrite(TransferRequest * aRequest, PRUint32 aBatchCount)
308 {
309  // Validate arguments.
310  NS_ASSERTION(aRequest, "aRequest is null");
311 
312  // Write the item.
313  if (aRequest->IsPlaylist())
314  ReqHandleWritePlaylistTrack(aRequest);
315  else
316  ReqHandleWriteTrack(aRequest, aBatchCount);
317 }
318 
319 
328 void
329 sbIPDDevice::ReqHandleWriteTrack(TransferRequest * aRequest,
330  PRUint32 aBatchCount)
331 {
332  // Validate arguments.
333  NS_ASSERTION(aRequest, "aRequest is null");
334 
335  // Function variables.
336  nsresult rv;
337 
338  const PRUint32 batchIndex = aRequest->GetBatchIndex() + 1;
339 
340  // Update operation status and set for auto-completion.
341  sbAutoStatusOperationComplete autoOperationStatus(mIPDStatus, NS_ERROR_FAILURE);
342  if (batchIndex == 1) {
344  aBatchCount);
345  }
346  if (batchIndex == aBatchCount) {
347  autoOperationStatus.Set(mIPDStatus, NS_OK);
348  }
349 
350  sbAutoStatusItemFailure autoItemStatus(mIPDStatus);
351 
352  // Remove unsupported media items and report errors.
353  PRBool supported;
354  rv = sbBaseDevice::SupportsMediaItem(aRequest->item,
355  nsnull,
356  PR_TRUE,
357  &supported);
358  NS_ENSURE_SUCCESS(rv, /* void */);
359  if (!supported) {
360  rv = DeleteItem(aRequest->list, aRequest->item);
361  NS_ENSURE_SUCCESS(rv, /* void */);
362  return;
363  }
364 
365  // Upload track.
366  rv = UploadTrack(aRequest->item);
367  NS_ENSURE_SUCCESS(rv, /* void */);
368 
369  // Update status and clear auto-failure.
370  autoItemStatus.forget();
371  mIPDStatus->ItemComplete(NS_OK);
372 }
373 
374 
383 void
384 sbIPDDevice::ReqHandleWritePlaylistTrack(TransferRequest* aRequest)
385 {
386  // Validate arguments.
387  NS_ASSERTION(aRequest, "aRequest is null");
388 
389  // Function variables.
390  nsresult rv;
391 
392  // Log progress.
393  FIELD_LOG(("Add track to playlist at index %d.\n", aRequest->index));
394 
395  // Add the track to the playlist.
396  rv = PlaylistAddTrack(aRequest->list, aRequest->item, aRequest->index);
397  NS_ENSURE_SUCCESS(rv, /* void */);
398 }
399 
400 
409 void
410 sbIPDDevice::ReqHandleWipe(TransferRequest * aRequest)
411 {
412  // Validate arguments.
413  NS_ASSERTION(aRequest, "aRequest is null");
414 
415  // Function variables.
416  nsresult rv;
417 
418  // if this is a library we're wiping the device
419  nsCOMPtr<sbILibrary> library = do_QueryInterface(aRequest->item, &rv);
420  if (NS_SUCCEEDED(rv)) {
421  rv = WipeDevice();
422  NS_ENSURE_SUCCESS(rv, /* void */);
423  }
424  else {
425  // Determine if the item to delete is a playlist.
426  nsCOMPtr<sbIMediaList> mediaList = do_QueryInterface(aRequest->item, &rv);
427  if (NS_SUCCEEDED(rv)) {
428  rv = PlaylistWipe(mediaList);
429  NS_ENSURE_SUCCESS(rv, /* void */);
430  }
431  else {
432  NS_WARNING("Unexpected data provided to REQUEST_WIPE");
433  }
434  }
435 }
436 
445 void
446 sbIPDDevice::ReqHandleDelete(TransferRequest* aRequest,
447  PRUint32 aBatchCount)
448 {
449  // Validate arguments.
450  NS_ASSERTION(aRequest, "aRequest is null");
451 
452  // Function variables.
453  nsresult rv;
454 
455  // Determine if the item to delete is a playlist.
456  PRBool deletePlaylist;
457  nsCOMPtr<sbIMediaList> mediaList = do_QueryInterface(aRequest->item, &rv);
458  if (NS_SUCCEEDED(rv))
459  deletePlaylist = PR_TRUE;
460  else
461  deletePlaylist = PR_FALSE;
462 
463  // Delete the item.
464  if (deletePlaylist) {
465  ReqHandleDeletePlaylist(aRequest);
466  } else {
467  if (aRequest->IsPlaylist())
468  ReqHandleDeletePlaylistTrack(aRequest);
469  else
470  ReqHandleDeleteTrack(aRequest, aBatchCount);
471  }
472 }
473 
474 
483 void
484 sbIPDDevice::ReqHandleDeleteTrack(TransferRequest * aRequest,
485  PRUint32 aBatchCount)
486 {
487  // Validate arguments.
488  NS_ASSERTION(aRequest, "aRequest is null");
489 
490  // Function variables.
491  nsresult rv;
492 
493  const PRUint32 batchIndex = aRequest->GetBatchIndex() + 1;
494 
495 
496  // Update operation status and set for auto-completion.
497  sbAutoStatusOperationComplete autoOperationStatus(mIPDStatus, NS_ERROR_FAILURE);
498  if (batchIndex == 1) {
500  aBatchCount);
501  }
502  if (batchIndex == aBatchCount) {
503  autoOperationStatus.Set(mIPDStatus, NS_OK);
504  }
505 
506  sbAutoStatusItemFailure autoItemStatus(mIPDStatus);
507 
508  // Delete track.
509  rv = DeleteTrack(aRequest->item);
510  NS_ENSURE_SUCCESS(rv, /* void */);
511 
512  // Update status and clear auto-failure.
513  autoItemStatus.forget();
514  mIPDStatus->ItemComplete(NS_OK);
515 }
516 
517 
526 void
527 sbIPDDevice::ReqHandleDeletePlaylistTrack(TransferRequest * aRequest)
528 {
529  // Validate arguments.
530  NS_ASSERTION(aRequest, "aRequest is null");
531 
532  // Function variables.
533  nsresult rv;
534 
535  // Log progress.
536  FIELD_LOG(("Delete track from playlist at index %d.\n", aRequest->index));
537 
538  // Delete the track from the playlist.
539  rv = PlaylistRemoveTrack(aRequest->list, aRequest->item, aRequest->index);
540  NS_ENSURE_SUCCESS(rv, /* void */);
541 }
542 
543 
552 void
553 sbIPDDevice::ReqHandleDeletePlaylist(TransferRequest * aRequest)
554 {
555  // Validate arguments.
556  NS_ASSERTION(aRequest, "aRequest is null");
557 
558  // Function variables.
559  nsresult rv;
560 
561  // Log progress.
562  FIELD_LOG(("Deleting playlist.\n"));
563 
564  // Delete the playlist from the iPod.
565  nsCOMPtr<sbIMediaList> mediaList = do_QueryInterface(aRequest->item, &rv);
566  NS_ENSURE_SUCCESS(rv, /* void */);
567  rv = PlaylistDelete(mediaList);
568  NS_ENSURE_SUCCESS(rv, /* void */);
569 }
570 
571 
580 void
581 sbIPDDevice::ReqHandleNewPlaylist(TransferRequest * aRequest)
582 {
583  // Validate arguments.
584  NS_ASSERTION(aRequest, "aRequest is null");
585 
586  // Function variables.
587  nsresult rv;
588 
589  // Log progress.
590  FIELD_LOG(("Creating playlist.\n"));
591 
592  // Add the playlist to the iPod.
593  Itdb_Playlist* playlist;
594  nsCOMPtr<sbIMediaList> mediaList = do_QueryInterface(aRequest->item, &rv);
595  NS_ENSURE_SUCCESS(rv, /* void */);
596  rv = PlaylistAdd(mediaList, &playlist);
597  NS_ENSURE_SUCCESS(rv, /* void */);
598 }
599 
600 
609 void
610 sbIPDDevice::ReqHandleUpdate(TransferRequest * aRequest)
611 {
612  // Validate arguments.
613  NS_ASSERTION(aRequest, "aRequest is null");
614 
615  // Function variables.
616  nsresult rv;
617 
618  // Get the request parameters.
619  nsCOMPtr<sbIMediaItem> mediaItem = aRequest->item;
620  nsCOMPtr<sbIMediaList> mediaList = do_QueryInterface(mediaItem);
621 
622  // Do nothing if the item to update no longer exists.
623  nsCOMPtr<sbILibrary> library;
624  PRBool exists;
625  rv = mediaItem->GetLibrary(getter_AddRefs(library));
626  NS_ENSURE_SUCCESS(rv, /* void */);
627  rv = library->Contains(mediaItem, &exists);
628  NS_ENSURE_SUCCESS(rv, /* void */);
629  if (!exists)
630  return;
631 
632  // Log progress.
633  FIELD_LOG(("Updating item.\n"));
634 
635  // Update the item.
636  if (mediaList)
637  rv = PlaylistUpdateProperties(mediaList);
638  else
639  rv = TrackUpdateProperties(mediaItem);
640  NS_ENSURE_SUCCESS(rv, /* void */);
641 }
642 
643 
652 void
653 sbIPDDevice::ReqHandleMovePlaylistTrack(TransferRequest * aRequest)
654 {
655  // Validate arguments.
656  NS_ASSERTION(aRequest, "aRequest is null");
657 
658  // Function variables.
659  nsresult rv;
660 
661  // Log progress.
662  FIELD_LOG(("Move playlist track from index %d to index %d.\n",
663  aRequest->index,
664  aRequest->otherIndex));
665 
666  // Validate request parameters.
667  NS_ENSURE_TRUE(aRequest->list, /* void */);
668 
669  // Move the track in the playlist.
670  rv = PlaylistMoveTrack(aRequest->list,
671  aRequest->index,
672  aRequest->otherIndex);
673  NS_ENSURE_SUCCESS(rv, /* void */);
674 }
675 
676 
685 void
686 sbIPDDevice::ReqHandleFactoryReset(TransferRequest * aRequest)
687 {
688  // Validate arguments.
689  NS_ASSERTION(aRequest, "aRequest is null");
690 
691  // Function variables.
692  nsresult rv;
693 
694  // Log progress.
695  FIELD_LOG(("Factory reset.\n"));
696 
697  nsCOMPtr<nsILocalFile> mountDir =
698  do_CreateInstance("@mozilla.org/file/local;1");
699  mountDir->InitWithPath(mMountPath);
700 
701  nsCOMPtr<nsISimpleEnumerator> files;
702  rv = mountDir->GetDirectoryEntries(getter_AddRefs(files));
703  NS_ENSURE_SUCCESS(rv, /* void */);
704 
705  PRBool hasMore;
706  while (NS_SUCCEEDED(files->HasMoreElements(&hasMore)) && hasMore) {
707  nsCOMPtr<nsIFile> file;
708  rv = files->GetNext(getter_AddRefs(file));
709  NS_ENSURE_SUCCESS(rv, /* void */);
710 
711 #ifdef DEBUG
712  nsString path;
713  file->GetPath(path);
714 
715  FIELD_LOG(("sbIPDDevice::ReqHandleFactoryReset deleting directory %s\n",
716  NS_LossyConvertUTF16toASCII(path).get()));
717 #endif
718 
719  rv = file->Remove(PR_TRUE);
720  NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to delete directory");
721  }
722 
723  /* eject! */
724  Eject();
725 }
726 
727 
736 void
737 sbIPDDevice::ReqHandleWritePrefs(TransferRequest * aRequest)
738 {
739  // Validate arguments.
740  NS_ASSERTION(aRequest, "aRequest is null");
741 
742  // Function variables.
743  GError* gError = NULL;
744  PRBool success;
745 
746  // Operate under the preference lock.
747  //XXXeps this can sometimes cause a potential deadlock assert because the
748  //XXXeps main thread can hold the pref lock, then the request thread can
749  //XXXeps acquire the request lock, then try to acquire the pref lock. This
750  //XXXeps doesn't lead to an actual dead lock, just an assert.
751  nsAutoLock autoPrefLock(mPrefLock);
752 
753  // Write the iPod preferences.
754  if (mIPodPrefsDirty) {
755  success = itdb_prefs_write(mITDB->device, mIPodPrefs, &gError);
756  if (gError) {
757  if (gError->message)
758  FIELD_LOG(("%s", gError->message));
759  g_error_free(gError);
760  gError = NULL;
761  }
762  if (!success)
763  NS_WARNING("Failed to write the iPod preferences file.");
764  }
765  mIPodPrefsDirty = PR_FALSE;
766 
767  // Write the sync playlist list.
768  if (mSyncPlaylistListDirty) {
769  success = itdb_update_playlists_write(mITDB->device,
770  mSyncPlaylistList.Elements(),
771  mSyncPlaylistList.Length(),
772  &gError);
773  if (gError) {
774  if (gError->message)
775  FIELD_LOG(("%s", gError->message));
776  g_error_free(gError);
777  gError = nsnull;
778  }
779  if (!success)
780  NS_WARNING("Failed to write the iPod sync playlist file.");
781  }
782  mSyncPlaylistListDirty = PR_FALSE;
783 }
784 
785 
794 void
795 sbIPDDevice::ReqHandleSetProperty(TransferRequest * aRequest)
796 {
797  // Validate arguments.
798  NS_ASSERTION(aRequest, "aRequest is null");
799 
800  // Function variables.
801  nsresult rv;
802 
803  SetNamedValueRequest* request = static_cast<SetNamedValueRequest*>(aRequest);
804 
805  // Process the request.
806  if (request->name.EqualsLiteral("FriendlyName")) {
807  // Get the friendly name.
808  nsAutoString friendlyName;
809  rv = request->value->GetAsAString(friendlyName);
810  NS_ENSURE_SUCCESS(rv, /* void */);
811 
812  // Set the master playlist name to the friendly name.
813  gchar* masterPlaylistName =
814  g_strdup(NS_ConvertUTF16toUTF8(friendlyName).get());
815  NS_ENSURE_TRUE(masterPlaylistName, /* void */);
816  if (mMasterPlaylist->name)
817  g_free(mMasterPlaylist->name);
818  mMasterPlaylist->name = masterPlaylistName;
819 
820  // Mark the iPod database as dirty.
821  mITDBDirty = PR_TRUE;
822  }
823 }
824 
825 
834 void
835 sbIPDDevice::ReqHandleSetPref(SetNamedValueRequest * aRequest)
836 {
837  // Validate arguments.
838  NS_ASSERTION(aRequest, "aRequest is null");
839 
840  // Function variables.
841  nsresult rv;
842 
843  // Process the request.
844 
845  if (aRequest->name.EqualsLiteral("SyncPartner")) {
846  // Get the Songbird sync partner ID.
847  nsAutoString sbSyncPartnerID;
848  rv = aRequest->value->GetAsAString(sbSyncPartnerID);
849  NS_ENSURE_SUCCESS(rv, /* void */);
850 
851  // Get the iPod sync partner ID mapped to the Songbird sync partner ID.
852  // Create one if none mapped.
853  guint64 iPodSyncPartnerID;
854  rv = IDMapGet(sbSyncPartnerID, &iPodSyncPartnerID);
855  if (rv == NS_ERROR_NOT_AVAILABLE) {
856  iPodSyncPartnerID = (((guint64) g_random_int()) << 32) |
857  g_random_int();
858  IDMapAdd(sbSyncPartnerID, iPodSyncPartnerID);
859  } else {
860  NS_ENSURE_SUCCESS(rv, /* void */);
861  }
862 
863  // Set the iPod linked library ID preference under the preference lock.
864  {
865  nsAutoLock autoPrefLock(mPrefLock);
866  mIPodPrefs->music_lib_link_id = iPodSyncPartnerID;
867  mIPodPrefsDirty = PR_TRUE;
868  }
869 
870  // Write the preferences.
871  rv = PushRequest(REQUEST_WRITE_PREFS);
872  NS_ENSURE_SUCCESS(rv, /* void */);
873  }
874 }
875 
876 
877 //------------------------------------------------------------------------------
878 //
879 // iPod device request services.
880 //
881 //------------------------------------------------------------------------------
882 
892 nsresult
893 sbIPDDevice::ReqPushSetNamedValue(int aType,
894  const nsAString& aName,
895  nsIVariant* aValue)
896 {
897  // Validate arguments.
898  NS_ASSERTION(aValue, "aValue is null");
899 
900  // Function variables.
901  nsresult rv;
902 
903  // Set up the set named value request.
904  SetNamedValueRequest * request = new SetNamedValueRequest(aType);
905  NS_ENSURE_TRUE(request, NS_ERROR_OUT_OF_MEMORY);
906  request->name = aName;
907  request->value = aValue;
908 
909  // Enqueue the request.
910  //XXXeps This can raise a potential deadlock assert when called from the
911  //XXXeps request thread. Not sure what to do about that.
912  rv = mRequestThreadQueue->PushRequest(request);
913  NS_ENSURE_SUCCESS(rv, rv);
914 
915  return NS_OK;
916 }
917 
918 
const unsigned long REQUEST_FACTORY_RESET
Definition: sbIDevice.idl:274
nsresult CreateAndDispatchEvent(PRUint32 aType, nsIVariant *aData, PRBool aAsync=PR_TRUE, sbIDeviceEventTarget *aTarget=nsnull)
return NS_OK
void OperationComplete(nsresult aResult)
const unsigned long STATE_DELETING
Definition: sbIDevice.idl:224
onPageChanged aValue
Definition: FeedWriter.js:1395
void ItemComplete(nsresult aResult)
nsRefPtr< sbDeviceRequestThreadQueue > mRequestThreadQueue
Definition: sbBaseDevice.h:730
nsresult ListenToMediaLists(sbILibrary *aLibrary)
friend class sbIPDAutoIdle
Definition: sbIPDDevice.h:259
nsresult ChangeStatus(PRUint32 newState)
const unsigned long STATE_UPDATING
Definition: sbIDevice.idl:225
const NS_ERROR_ABORT
#define SB_PROPERTY_HIDDEN
nsRefPtr< sbBaseDeviceLibraryListener > mLibraryListener
Definition: sbBaseDevice.h:693
virtual PRBool IsRequestAborted()
NS_IMETHOD GetState(PRUint32 *aState)
const unsigned long EVENT_DEVICE_READY
nsresult PushRequest(const PRUint32 aType, sbIMediaItem *aItem=nsnull, sbIMediaList *aList=nsnull, PRUint32 aIndex=PR_UINT32_MAX, PRUint32 aOtherIndex=PR_UINT32_MAX, nsISupports *aData=nsnull)
friend class sbIPDAutoDBFlush
Definition: sbIPDDevice.h:258
NS_IMETHOD SupportsMediaItem(sbIMediaItem *aMediaItem, sbIDeviceSupportsItemCallback *aCallback)
NS_IMETHOD Eject(void)
RequestItems::const_iterator const_iterator
const unsigned long STATE_COPYING
Definition: sbIDevice.idl:223
Songbird iPod Device Definitions.
#define FIELD_LOG(args)
Definition: sbIPDLog.h:126
static const PRUint32 OPERATION_TYPE_DELETE
Definition: sbIPDStatus.h:99
Songbird iPod Device Logging Definitions.
const unsigned long STATE_MOUNTING
Definition: sbIDevice.idl:226
_updateCookies aName
nsresult DeleteItem(sbIMediaList *aLibrary, sbIMediaItem *aItem)
const unsigned long STATE_SYNCING
Definition: sbIDevice.idl:221
StringArrayEnumerator prototype hasMore
sbRequestThreadQueue::Batch Batch
Definition: sbBaseDevice.h:110
nsresult HandleSyncRequest(TransferRequest *aRequest)
static const PRUint32 OPERATION_TYPE_MOUNT
Definition: sbIPDStatus.h:97
void SBWriteRequestSplitBatches(const sbBaseDevice::Batch &aInput, sbBaseDevice::Batch &aNonTranscodeItems, sbBaseDevice::Batch &aTranscodeItems, sbBaseDevice::Batch &aPlaylistItems)
const unsigned long STATE_BUSY
Definition: sbIDevice.idl:232
static const PRUint32 OPERATION_TYPE_WRITE
Definition: sbIPDStatus.h:98
void OperationStart(PRUint32 aOperationType, sbBaseDevice::TransferRequest *aRequest, PRUint32 aBatchCount)
var file