sbBaseDevice.h
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
2 /*
3  *=BEGIN SONGBIRD GPL
4  *
5  * This file is part of the Songbird web player.
6  *
7  * Copyright(c) 2005-2011 POTI, Inc.
8  * http://www.songbirdnest.com
9  *
10  * This file may be licensed under the terms of of the
11  * GNU General Public License Version 2 (the ``GPL'').
12  *
13  * Software distributed under the License is distributed
14  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
15  * express or implied. See the GPL for the specific language
16  * governing rights and limitations.
17  *
18  * You should have received a copy of the GPL along with this
19  * program. If not, go to http://www.gnu.org/licenses/gpl.html
20  * or write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  *=END SONGBIRD GPL
24  */
25 
26 #ifndef __SBBASEDEVICE__H__
27 #define __SBBASEDEVICE__H__
28 
29 #include <algorithm>
30 #include <list>
31 #include <map>
32 #include <vector>
33 
34 #include "sbIDevice.h"
36 #include "sbBaseDeviceVolume.h"
37 #include "sbDeviceLibrary.h"
38 
39 #include <nsArrayUtils.h>
40 #include <nsAutoPtr.h>
41 #include <nsClassHashtable.h>
42 #include <nsCOMPtr.h>
43 #include <nsCOMArray.h>
44 #include <nsDataHashtable.h>
45 #include <nsIRunnable.h>
46 #include <nsISupportsImpl.h>
47 #include <nsITimer.h>
48 #include <nsIFile.h>
49 #include <nsIURL.h>
50 #include <nsTArray.h>
51 
52 #include <sbAutoRWLock.h>
53 #include <sbILibraryChangeset.h>
54 #include <sbIMediaItem.h>
55 #include <sbIMediaList.h>
56 #include "sbRequestItem.h"
58 #include <sbITemporaryFileFactory.h>
59 #include <sbITranscodeManager.h>
60 
61 #include <sbMemoryUtils.h>
62 #include <nsComponentManagerUtils.h>
63 
64 #include "sbDeviceStatistics.h"
65 
66 class nsIArray;
67 class nsIMutableArray;
68 class nsIPrefBranch;
69 
76 class sbDeviceImages;
79 class sbIDeviceLibrary;
82 class sbIMediaFormat;
83 
84 // Device property XML namespace.
85 #define SB_DEVICE_PROPERTY_NS "http://songbirdnest.com/device/1.0"
86 
87 #define SB_SYNC_PARTNER_PREF NS_LITERAL_STRING("SyncPartner")
88 
99 class NS_HIDDEN sbBaseDevice : public sbIDevice,
101 {
102 public:
103  // Friend declarations for classes used to divide up device work
104  friend class sbDeviceTranscoding;
105  friend class sbDeviceImages;
106  friend class sbBaseDeviceVolume;
108  friend class sbDevieEnsureSpaceForWrite;
109 
111 
112  struct TransferRequest : public sbRequestItem {
113  /* types of requests. not all types necessarily apply to all types of
114  * devices, and devices may have custom types.
115  * Request types that should result in delaying shutdown (e.g. writing to
116  * the device) should have the write flag set.
117  * The specific device may internally define more request types.
118  */
119 
120  static const int REQUEST_FLAG_USER = sbIDevice::REQUEST_FLAG_USER;
121  static const int REQUEST_FLAG_WRITE = sbIDevice::REQUEST_FLAG_WRITE;
122 
123  /* note that type 0 is reserved */
124  enum {
125  /* read requests */
126  REQUEST_MOUNT = sbIDevice::REQUEST_MOUNT,
127  REQUEST_READ = sbIDevice::REQUEST_READ,
128  REQUEST_EJECT = sbIDevice::REQUEST_EJECT,
129  REQUEST_SUSPEND = sbIDevice::REQUEST_SUSPEND,
130 
131  /* write requests */
132  REQUEST_WRITE = sbIDevice::REQUEST_WRITE,
133  REQUEST_DELETE = sbIDevice::REQUEST_DELETE,
134  REQUEST_SYNC = sbIDevice::REQUEST_SYNC,
135  REQUEST_IMAGESYNC = sbIDevice::REQUEST_IMAGESYNC,
136  REQUEST_WRITE_FILE = sbIDevice::REQUEST_WRITE_FILE,
137  REQUEST_DELETE_FILE = sbIDevice::REQUEST_DELETE_FILE,
138  /* delete all files */
139  REQUEST_WIPE = sbIDevice::REQUEST_WIPE,
140  /* move an item in one playlist */
141  REQUEST_MOVE = sbIDevice::REQUEST_MOVE,
142  REQUEST_UPDATE = sbIDevice::REQUEST_UPDATE,
143  REQUEST_NEW_PLAYLIST = sbIDevice::REQUEST_NEW_PLAYLIST,
144  REQUEST_FORMAT = sbIDevice::REQUEST_FORMAT,
145  REQUEST_SYNC_COMPLETE = sbIDevice::REQUEST_SYNC_COMPLETE
146  };
147 
148  enum {
149  REQUESTBATCH_UNKNOWN = 0,
150  REQUESTBATCH_AUDIO = 1,
151  REQUESTBATCH_VIDEO = 2,
152  REQUESTBATCH_IMAGE = 4
153  };
154 
155  nsCOMPtr<sbIMediaItem> item; /* the item this request pertains to */
156  nsCOMPtr<sbIMediaList> list; /* the list this request is to act on */
157  nsCOMPtr<nsISupports> data; /* optional data that may or may not be used by a type of request */
158  sbITranscodeProfile * transcodeProfile; /* Transcode profile to use if available
159  this is manually ref counted so
160  we don't have all of our consumers
161  have to include the transcode profile
162  directory */
163  PRUint32 index; /* the index in the list for this action */
164  PRUint32 otherIndex; /* any secondary index needed */
165 
166  PRUint32 itemType; /* Item type: Audio, Video... */
167 
168  /* Write request fields. */
169  PRBool contentSrcSet; /* if true, the content source URI for the
170  destination item has been set */
171  PRBool destinationMediaPresent; /* if true, the destination media is
172  present on the device (e.g., it's been
173  copied or transcoded to the device) */
174  /* This determines how much this item will be transferred onto the device */
175  typedef enum {
176  COMPAT_UNSUPPORTED, /* this item cannot be transferred */
177  COMPAT_SUPPORTED, /* this item is directly supported on the device */
178  COMPAT_NEEDS_TRANSCODING /* this item needs to be transcoded */
179  } CompatibilityType;
181  PRBool transcoded; /* if true, write item media was
182  transcoded */
183  nsCOMPtr<sbITranscodeAlbumArt> albumArt; /* Album art transcoding object,
184  or null if no album art
185  transcoding should be done */
186  /* Factory for creating temporary files. All temporary files are removed
187  when factory is destroyed. */
188  nsCOMPtr<sbITemporaryFileFactory> temporaryFileFactory;
189 
190  nsCOMPtr<nsIFile> downloadedFile; /* used if request item content source had
191  to be downloaded */
192 
199  PRBool IsPlaylist() const;
200 
205  PRBool IsCountable() const;
206 
207  static TransferRequest * New(PRUint32 aType,
208  sbIMediaItem * aItem,
209  sbIMediaList * aList,
210  PRUint32 aIndex,
211  PRUint32 aOtherIndex,
212  nsISupports * aData);
213 
214  /* Don't allow manual construction/destruction, but allow sub-classing. */
215  protected:
216  TransferRequest();
217 
218  ~TransferRequest(); /* we're refcounted, no manual deleting! */
219  };
220 
221 public:
222  /* selected methods from sbIDevice */
223  NS_IMETHOD Connect();
224  NS_IMETHOD Disconnect();
225  NS_IMETHOD GetPreference(const nsAString & aPrefName, nsIVariant **_retval);
226  NS_IMETHOD SetPreference(const nsAString & aPrefName, nsIVariant *aPrefValue);
227  NS_IMETHOD GetIsDirectTranscoding(PRBool *aIsDirect);
228  NS_IMETHOD GetIsBusy(PRBool *aIsBusy);
229  NS_IMETHOD GetCanDisconnect(PRBool *aCanDisconnect);
230  NS_IMETHOD GetState(PRUint32 *aState);
231  NS_IMETHOD SetState(PRUint32 aState);
232  NS_IMETHOD GetPreviousState(PRUint32 *aState);
233  NS_IMETHOD SyncLibraries(void);
238  NS_IMETHOD Eject(void);
239  NS_IMETHOD Format(void);
240  NS_IMETHOD GetSupportsReformat(PRBool *_retval);
241  NS_IMETHOD SupportsMediaItem(sbIMediaItem* aMediaItem,
242  sbIDeviceSupportsItemCallback* aCallback);
243  NS_IMETHOD GetDefaultLibrary(sbIDeviceLibrary** aDefaultLibrary);
244  NS_IMETHOD SetDefaultLibrary(sbIDeviceLibrary* aDefaultLibrary);
245  NS_IMETHOD GetPrimaryLibrary(sbIDeviceLibrary** aPrimaryLibrary);
246  NS_IMETHOD SubmitRequest(PRUint32 aRequest,
247  nsIPropertyBag2 *aRequestParameters);
248  NS_IMETHOD CancelRequests();
249 
250  NS_IMETHOD ImportFromDevice(sbILibrary * aImportToLibrary,
251  sbILibraryChangeset * aImportChangeset);
252 
253  NS_IMETHOD ExportToDevice(sbIDeviceLibrary* aDevLibrary,
254  sbILibraryChangeset* aChangeset);
255 
256 public:
257 
258  sbBaseDevice();
259  virtual ~sbBaseDevice();
260 
264  nsresult PushRequest(const PRUint32 aType,
265  sbIMediaItem* aItem = nsnull,
266  sbIMediaList* aList = nsnull,
267  PRUint32 aIndex = PR_UINT32_MAX,
268  PRUint32 aOtherIndex = PR_UINT32_MAX,
269  nsISupports * aData = nsnull);
270 
274  nsresult BatchBegin();
275 
279  nsresult BatchEnd();
283  nsresult ClearRequests();
284 
296  nsresult GetRequestTemporaryFileFactory
297  (TransferRequest* aRequest,
298  sbITemporaryFileFactory** aTemporaryFileFactory);
299 
308  nsresult DownloadRequestItem(TransferRequest* aRequest,
309  PRUint32 aBatchCount,
310  sbDeviceStatusHelper* aDeviceStatusHelper);
311 
325  nsresult SetPreferenceInternal(nsIPrefBranch* aPrefBranch,
326  const nsAString& aPrefName,
327  nsIVariant* aPrefValue,
328  PRBool* aHasChanged);
329 
336  nsresult HasPreference(nsAString& aPrefName,
337  PRBool* aHasPreference);
338 
342  virtual nsresult ProcessBatch(Batch & aBatch) = 0;
343 
348  nsresult SetPreviousState(PRUint32 aState);
349 
357  nsresult CreateDeviceLibrary(const nsAString& aId,
358  nsIURI* aLibraryLocation,
359  sbIDeviceLibrary** _retval);
360 
368  nsresult InitializeDeviceLibrary(sbDeviceLibrary* aDevLib,
369  const nsAString& aId,
370  nsIURI* aLibraryLocation);
371 
376  nsresult InitializeDeviceLibraryPreferences(sbDeviceLibrary* aDevLib);
377 
382  void FinalizeDeviceLibrary(sbIDeviceLibrary* aDevLib);
383 
388  nsresult AddLibrary(sbIDeviceLibrary* aDevLib);
389 
395  virtual nsresult CheckAccess(sbIDeviceLibrary* aDevLib);
396 
401  nsresult RemoveLibrary(sbIDeviceLibrary* aDevLib);
402 
412  nsresult UpdateLibraryProperty(sbILibrary* aLibrary,
413  const nsAString& aPropertyID,
414  const nsAString& aPropertyValue);
415 
420  nsresult UpdateDefaultLibrary(sbIDeviceLibrary* aDevLib);
421 
425  virtual nsresult OnDefaultLibraryChanged();
426 
431  nsresult ListenToList(sbIMediaList* aList);
432 
433  typedef struct {
435  nsCOMPtr<sbILibrary> library;
437 
438  static NS_HIDDEN_(PLDHashOperator)
439  EnumerateFinalizeMediaListListeners
440  (nsISupports* aKey,
442  void* aClosure);
443 
444  static NS_HIDDEN_(PLDHashOperator) EnumerateIgnoreMediaListListeners(nsISupports* aKey,
446  void* aClosure);
447 
453  nsresult SetIgnoreMediaListListeners(PRBool aIgnoreListener);
454 
460  nsresult SetIgnoreLibraryListener(PRBool aIgnoreListener);
461 
468  nsresult SetMediaListsHidden(sbIMediaList *aLibrary, PRBool aHidden);
469 
473  nsresult IgnoreMediaItem(sbIMediaItem * aItem);
474 
478  nsresult UnignoreMediaItem(sbIMediaItem * aItem);
479 
485  nsresult DeleteItem(sbIMediaList *aLibrary, sbIMediaItem *aItem);
486 
498  virtual nsresult GetItemContentType(sbIMediaItem* aMediaItem,
499  PRUint32* aContentType);
500 
510  nsresult UpdateOriginAndContentSrc(TransferRequest* aRequest,
511  nsIURI* aURI);
512 
513  nsresult CreateTransferRequest(PRUint32 aRequestType,
514  nsIPropertyBag2 *aRequestParameters,
515  TransferRequest **aTransferRequest);
516 
524  nsresult CreateAndDispatchEvent(PRUint32 aType,
525  nsIVariant *aData,
526  PRBool aAsync = PR_TRUE,
527  sbIDeviceEventTarget* aTarget = nsnull);
528 
539  nsresult CreateAndDispatchDeviceManagerEvent(PRUint32 aType,
540  nsIVariant *aData,
541  PRBool aAsync = PR_TRUE);
542 
547  nsresult RegenerateMediaURL(sbIMediaItem *aItem, nsIURI **_retval);
548 
558  virtual nsresult GenerateFilename(sbIMediaItem * aItem,
559  nsACString & aFilename);
560 
572  nsresult CreateUniqueMediaFile(nsIURI *aFileURI,
573  nsIFile **aUniqueFile,
574  nsIURI **aUniqueFileURI);
575 
579  nsresult ReqProcessingStart();
580 
584  nsresult ReqProcessingStop(nsIRunnable * aShutdownAction);
585 
590  bool CheckAndResetRequestAbort();
594  bool GetEnsureSpaceChecked() const {
595  return mEnsureSpaceChecked;
596  }
597 
601  void SetEnsureSpaceChecked(bool aChecked) {
602  mEnsureSpaceChecked = aChecked;
603  }
604 
605  NS_SCRIPTABLE NS_IMETHOD SetWarningDialogEnabled(const nsAString & aWarning, PRBool aEnabled);
606  NS_SCRIPTABLE NS_IMETHOD GetWarningDialogEnabled(const nsAString & aWarning, PRBool *_retval);
607  NS_SCRIPTABLE NS_IMETHOD ResetWarningDialogs(void);
608  NS_SCRIPTABLE NS_IMETHOD OpenInputStream(nsIURI* aURI,
609  nsIInputStream** retval);
610 
617  virtual PRBool IsRequestAborted();
618 
620  return mDeviceTranscoding;
621  }
627  PRLock * StateLock() {
628  return mStateLock;
629  }
634  PRUint32 GetDeviceState() {
635  return mState;
636  }
637 
639  return mDeviceImages;
640  }
641 
642 protected:
645  friend class sbDeviceStatistics;
646  friend class sbDeviceReqAddedEvent;
651  nsresult Init();
655  virtual nsresult InitDevice() { return NS_OK; }
656 
668  virtual nsresult ChangeState(PRUint32 aState);
669 
670 private:
675  virtual nsresult DeviceSpecificDisconnect() = 0;
679  nsresult GetFirstRequest(bool aRemove, TransferRequest** _retval);
680 protected:
681 
682 
683  PRLock *mStateLock;
684  PRUint32 mState;
686  PRUint32 mPreviousState;
687  PRInt32 mIgnoreMediaListCount; // Allows us to know if we're ignoring lists
688  PRUint32 mPerTrackOverhead; // estimated bytes of overhead per track
689  nsAutoPtr<sbDeviceStatusHelper> mStatus;
690 
691  nsCOMPtr<sbIDeviceLibrary> mDefaultLibrary;
692  nsCOMPtr<sbILibrary> mMainLibrary;
693  nsRefPtr<sbBaseDeviceLibraryListener> mLibraryListener;
694  nsRefPtr<sbDeviceBaseLibraryCopyListener> mLibraryCopyListener;
695  nsDataHashtableMT<nsISupportsHashKey, nsRefPtr<sbBaseDeviceMediaListListener> > mMediaListListeners;
696  nsCOMPtr<sbIDeviceInfoRegistrar> mInfoRegistrar;
698  nsCOMPtr<sbIDeviceCapabilities> mCapabilities;
703 
704  enum {
705  CAN_TRANSCODE_UNKNOWN = 0,
706  CAN_TRANSCODE_YES = 1,
707  CAN_TRANSCODE_NO = 2
708  };
711 
712  // This is a hack so that the UI has the information of what kind of media
713  // the set of sync changes contains. TODO: XXX we should look at replacing
714  // this at some point.
715  PRUint32 mSyncType;
716 
718 
719  //
720  // mConnectLock Connect lock.
721  // mConnected True if device is connected.
722  // mDeferredSetupDeviceTimer Timer used to defer presentation of the device
723  // setup dialog.
724  // mRequestThreadQueue This contains the logic to process requests
725  // for the device thread
726 
727  PRRWLock* mConnectLock;
728  PRBool mConnected;
729  nsCOMPtr<nsITimer> mDeferredSetupDeviceTimer;
730  nsRefPtr<sbDeviceRequestThreadQueue> mRequestThreadQueue;
731 
732  // cache data for media management preferences
733  struct OrganizeData {
735  nsCString dirFormat;
736  nsCString fileFormat;
737  OrganizeData() : organizeEnabled(PR_FALSE) {}
738  };
739  nsClassHashtableMT<nsIDHashKey, OrganizeData> mOrganizeLibraryPrefs;
740 
741  nsClassHashtable<nsUint32HashKey, nsString> mMediaFolderURLTable;
742 
747  static const PRUint32 DEFAULT_PER_TRACK_OVERHEAD = 10000;
748 
752  static const PRUint32 SYNC_PLAYLIST_AVAILABLE_PCT = 95;
753 
758  static const PRUint32 DEFER_DEVICE_SETUP_DELAY = 2000;
759 
775  nsresult EnsureSpaceForWrite(sbILibraryChangeset* aChangeset,
776  sbIDeviceLibrary* aDevLibrary);
777 
781  nsresult WaitForBatchEnd();
782 
786  static void WaitForBatchEndCallback(nsITimer* aTimer,
787  void* aClosure);
788 
792  void WaitForBatchEndCallback();
793 
802  nsresult GetMusicFreeSpace(sbILibrary* aLibrary,
803  PRInt64* aFreeMusicSpace);
804 
810  nsresult GetMusicAvailableSpace(sbILibrary* aLibrary,
811  PRInt64* aMusicAvailableSpace);
812 
828  nsresult SupportsMediaItem(sbIMediaItem* aMediaItem,
829  sbDeviceSupportsItemHelper* aCallback,
830  PRBool aReportErrors,
831  PRBool* _retval);
832 
833  nsDataHashtableMT<nsStringHashKey, PRBool> mTrackSourceTable;
834 
841  nsresult UpdateStreamingItemSupported(Batch & aBatch);
842 
844 
854  virtual nsresult SupportsMediaItemDRM(sbIMediaItem* aMediaItem,
855  PRBool aReportErrors,
856  PRBool* _retval);
857 
858  //----------------------------------------------------------------------------
859  //
860  // Device volume services.
861  //
862  //----------------------------------------------------------------------------
863 
864  //
865  // mVolumeLock Volume lock.
866  // mVolumeList List of volumes.
867  // mVolumeGUIDTable Table mapping volume GUIDs to volumes.
868  // mVolumeLibraryGUIDTable Table mapping library GUIDs to volumes.
869  // mPrimaryVolume Primary volume (usually internal storage).
870  // mDefaultVolume Default volume when none specified.
871  //
872 
873  PRLock* mVolumeLock;
874  nsTArray< nsRefPtr<sbBaseDeviceVolume> > mVolumeList;
875  nsInterfaceHashtableMT<nsStringHashKey,
877  nsInterfaceHashtableMT<nsStringHashKey,
879  nsRefPtr<sbBaseDeviceVolume> mPrimaryVolume;
880  nsRefPtr<sbBaseDeviceVolume> mDefaultVolume;
881 
888  nsresult AddVolume(sbBaseDeviceVolume* aVolume);
889 
896  nsresult RemoveVolume(sbBaseDeviceVolume* aVolume);
897 
909  nsresult GetVolumeForItem(sbIMediaItem* aItem,
910  sbBaseDeviceVolume** aVolume);
911 
912  //----------------------------------------------------------------------------
913  //
914  // Device settings services.
915  //
916  //----------------------------------------------------------------------------
917 
925  virtual nsresult GetDeviceSettingsDocument
926  (class nsIDOMDocument** aDeviceSettingsDocument);
927 
936  nsresult GetDeviceSettingsDocument
937  (nsIFile* aDeviceSettingsFile,
938  class nsIDOMDocument** aDeviceSettingsDocument);
939 
947  nsresult GetDeviceSettingsDocument
948  (nsTArray<PRUint8>& aDeviceSettingsContent,
949  class nsIDOMDocument** aDeviceSettingsDocument);
953  virtual nsresult ApplyDeviceSettingsDocument();
954 
961  virtual nsresult ApplyDeviceSettings
962  (class nsIDOMDocument* aDeviceSettingsDocument);
963 
974  nsresult ApplyDeviceSettingsToProperty
975  (class nsIDOMDocument* aDeviceSettingsDocument,
976  const nsAString& aPropertyName);
977 
985  virtual nsresult ApplyDeviceSettingsToProperty
986  (const nsAString& aPropertyName,
987  nsIVariant* aPropertyValue);
988 
995  nsresult ApplyDeviceSettingsDeviceInfo
996  (class nsIDOMDocument* aDeviceSettingsDocument);
997 
1004  nsresult ApplyDeviceSettingsToCapabilities
1005  (class nsIDOMDocument* aDeviceSettingsDocument);
1006 
1007 
1008  //----------------------------------------------------------------------------
1009  //
1010  // Device properties services.
1011  //
1012  //----------------------------------------------------------------------------
1013 
1017  virtual nsresult InitializeProperties();
1018 
1022  virtual nsresult UpdateProperties();
1023 
1029  virtual nsresult UpdateProperty(const nsAString& aName);
1030 
1034  virtual nsresult UpdateStatisticsProperties();
1035 
1039  nsresult UpdateVolumeNames();
1040 
1046  virtual nsresult UpdateVolumeName(sbBaseDeviceVolume* aVolume);
1047 
1048 
1049  //----------------------------------------------------------------------------
1050  //
1051  // Device preference services.
1052  //
1053  //----------------------------------------------------------------------------
1054 
1055  /* get the prefbranch root for this device */
1056  nsresult GetPrefBranchRoot(nsACString& aRoot);
1057 
1058  /* get a prefbranch for this device */
1059  nsresult GetPrefBranch(nsIPrefBranch** aPrefBranch);
1060 
1061  /* get a prefbranch for a device library */
1062  nsresult GetPrefBranch(sbIDeviceLibrary* aLibrary,
1063  nsIPrefBranch** aPrefBranch);
1064 
1065  /* Helper function to get a particular pref branch */
1066  nsresult GetPrefBranch(const char *aPrefBranchName,
1067  nsIPrefBranch** aPrefBranch);
1068 
1069  /* Get a preference from a specific pref branch */
1070  nsresult GetPreferenceInternal(nsIPrefBranch *aPrefBranch,
1071  const nsAString & aPrefName,
1072  nsIVariant **_retval);
1073 
1074  /* Set a preference on a specific pref branch */
1075  nsresult SetPreferenceInternal(nsIPrefBranch *aPrefBranch,
1076  const nsAString & aPrefName,
1077  nsIVariant *aPrefValue);
1078 
1079  /* Set a preference, not sending an event if the preference changed */
1080  nsresult SetPreferenceInternalNoNotify(const nsAString & aPrefName,
1081  nsIVariant *aPrefValue,
1082  PRBool *aPrefChanged);
1083 
1084 
1093  virtual nsresult ApplyPreference(const nsAString& aPrefName,
1094  nsIVariant* aPrefValue);
1095 
1103  PRBool GetIsLibraryPreference(const nsAString& aPrefName);
1104 
1117  nsresult GetPreferenceLibrary(const nsAString& aPrefName,
1118  sbIDeviceLibrary** aLibrary,
1119  nsAString& aLibraryPrefBase);
1120 
1131  nsresult GetLibraryPreference(sbIDeviceLibrary* aLibrary,
1132  const nsAString& aLibraryPrefName,
1133  nsIVariant** aPrefValue);
1134 
1144  nsresult GetLibraryPreference(const nsAString& aLibraryPrefBase,
1145  const nsAString& aLibraryPrefName,
1146  nsIVariant** aPrefValue);
1147 
1159  virtual nsresult ApplyLibraryPreference(sbIDeviceLibrary* aLibrary,
1160  const nsAString& aLibraryPrefName,
1161  nsIVariant* aPrefValue);
1162 
1176  virtual nsresult ApplyLibraryOrganizePreference(sbIDeviceLibrary* aLibrary,
1177  const nsAString& aLibraryPrefName,
1178  const nsAString& aLibraryPrefBase,
1179  nsIVariant* aPrefValue);
1180 
1188  nsresult GetLibraryPreferenceName(const nsAString& aPrefName,
1189  nsAString& aLibraryPrefName);
1190 
1200  nsresult GetLibraryPreferenceName(const nsAString& aPrefName,
1201  const nsAString& aLibraryPrefBase,
1202  nsAString& aLibraryPrefName);
1203 
1211  nsresult GetLibraryPreferenceBase(sbIDeviceLibrary* aLibrary,
1212  nsAString& aPrefBase);
1213 
1220  nsresult GetCapabilitiesPreference(nsIVariant** aCapabilities);
1221 
1228  nsresult GetLocalDeviceDir(nsIFile** aLocalDeviceDir);
1229 
1230 
1231  //----------------------------------------------------------------------------
1232  //
1233  // Device sync services.
1234  //
1235  //----------------------------------------------------------------------------
1236 
1240  nsresult SendSyncCompleteRequest();
1241 
1247  nsresult HandleSyncRequest(TransferRequest* aRequest);
1248 
1254  nsresult HandleSyncCompletedRequest(TransferRequest* aRequest);
1255 
1267  nsresult EnsureSpaceForSync(sbILibraryChangeset* aChangeset,
1268  PRBool* aCapacityExceeded,
1269  PRBool* aAbort);
1270 
1285  nsresult SyncCreateAndSyncToList
1286  (sbILibrary* aSrcLib,
1287  sbIDeviceLibrary* aDstLib,
1288  PRInt64 aAvailableSpace);
1289 
1303  nsresult SyncCreateSyncMediaList(sbILibrary* aSrcLib,
1304  sbIDeviceLibrary* aDstLib,
1305  PRInt64 aAvailableSpace,
1306  sbIMediaList** aSyncMediaList);
1307 
1315  nsresult SyncToMediaList(sbIDeviceLibrary* aDstLib,
1316  sbIMediaList* aMediaList);
1317 
1325  PRInt64 GetChangeSize(sbIDeviceLibrary * aDestLibrary,
1326  sbILibraryChange * aChange);
1340  nsresult SyncGetSyncItemSizes(sbIDeviceLibrary * aDestLibrary,
1341  sbILibraryChangeset* aChangeset,
1342  PRInt64 aAvailableSpace,
1343  PRUint32& aLastChangeThatFit,
1344  PRInt64& aTotalSyncSize);
1345 
1354  nsresult SyncGetSyncAvailableSpace(sbILibrary* aLibrary,
1355  PRInt64* aAvailableSpace);
1356 
1365  nsresult SyncProduceChangeset(TransferRequest* aRequest,
1366  sbILibraryChangeset** aExportChangeset,
1367  sbILibraryChangeset** aImportChangeset);
1368 
1377  nsresult SyncMainLibraryFlag(sbIMediaItem * aMediaItem);
1378 
1385  nsresult PromptForEjectDuringPlayback(PRBool* aEject);
1386 
1390  virtual nsresult UpdateMediaFolders();
1391 
1404  nsresult GetDeviceWriteDestURI(sbIMediaItem* aWriteDstItem,
1405  nsIURI* aContentSrcBaseURI,
1406  nsIURI* aWriteSrcURI,
1407  nsIURI ** aDestinationURI);
1408 
1414  nsresult ListenToMediaLists(sbILibrary * aLibrary);
1415 
1419  nsresult SetupDevice();
1420 
1425  static void DeferredSetupDevice(nsITimer* aTimer,
1426  void* aClosure);
1427 
1428  nsresult DeferredSetupDevice();
1429 
1433  nsresult RegisterDeviceInfo();
1438  nsresult RegisterDeviceCapabilities(sbIDeviceCapabilities * aCapabilities);
1439 
1443  nsresult ProcessInfoRegistrars();
1444 
1451  virtual nsresult GetSupportedTranscodeProfiles(PRUint32 aType,
1452  nsIArray **aSupportedProfiles);
1453 
1464  nsresult GetDeviceTranscodingProperty(PRUint32 aTranscodeType,
1465  const nsAString& aPropertyName,
1466  nsIVariant** aPropertyValue);
1467 
1475  nsresult DispatchTranscodeErrorEvent(sbIMediaItem* aMediaItem,
1476  const nsAString& aErrorMessage);
1477 
1478  /* Return an array of sbIImageFormatType describing all the supported
1479  * album art formats for the device.
1480  *
1481  * The array may be empty; this should be interpreted as "unknown" rather than
1482  * "album art is not supported"
1483  */
1484  nsresult GetSupportedAlbumArtFormats(nsIArray * *aFormats);
1485 
1493  nsresult GetShouldLimitMusicSpace(const nsAString & aPrefBase,
1494  PRBool *aOutShouldLimitSpace);
1495 
1504  nsresult GetMusicLimitSpacePercent(const nsAString & aPrefBase,
1505  PRUint32 *aOutLimitPercentage);
1506 
1510  static PLDHashOperator RemoveLibraryEnumerator(
1511  nsISupports * aList,
1512  nsCOMPtr<nsIMutableArray> & aItems,
1513  void * aUserArg);
1514 
1519  {
1520  public:
1521  AutoListenerIgnore(sbBaseDevice * aDevice);
1522  ~AutoListenerIgnore();
1523  private:
1524  sbBaseDevice * mDevice;
1525  };
1526 
1538  template <class T>
1539  nsresult RemoveLibraryItems(T iter, T end)
1540  {
1541  nsresult rv;
1542  nsInterfaceHashtable<nsISupportsHashKey, nsIMutableArray> groupedItems;
1543  groupedItems.Init();
1544 
1545  while (iter != end) {
1546  sbBaseDevice::TransferRequest * request = *iter;
1547  PRUint32 type = request->GetType();
1548 
1549  // If this is a request that adds an item to the device we need to remove
1550  // it from the device since it never was copied
1551  switch (type) {
1554  if (request->list && request->item) {
1555  nsCOMPtr<nsIMutableArray> items;
1556  groupedItems.Get(request->list, getter_AddRefs(items));
1557  if (!items) {
1558  items = do_CreateInstance(
1559  "@songbirdnest.com/moz/xpcom/threadsafe-array;1",
1560  &rv);
1561  NS_ENSURE_TRUE(groupedItems.Put(request->list, items),
1562  NS_ERROR_OUT_OF_MEMORY);
1563  }
1564  rv = items->AppendElement(request->item, PR_FALSE);
1565  NS_ENSURE_SUCCESS(rv, rv);
1566  }
1567  }
1568  break;
1569  }
1570  ++iter;
1571  }
1572  AutoListenerIgnore ignore(this);
1573  groupedItems.Enumerate(RemoveLibraryEnumerator, this);
1574  return NS_OK;
1575  }
1576 
1581  nsresult GetNameBase(nsAString& aName);
1589  nsresult GetProductNameBase(char const * aDefaultModelNumberString,
1590  nsAString& aProductName);
1596  nsresult
1597  IgnoreWatchFolderPath(nsIURI * aURI,
1598  sbAutoIgnoreWatchFolderPath ** aIgnorePath);
1602  void LogDeviceFolders();
1606  static PLDHashOperator LogDeviceFoldersEnum(const unsigned int& aKey,
1607  nsString* aData,
1608  void* aUserArg);
1609  nsresult GetExcludedFolders(nsTArray<nsString> & aExcludedFolders);
1610 
1615  nsresult UpdateMediaLists(nsIArray * aMediaLists);
1616 
1622  nsresult AddMediaLists(sbILibrary * aLibrary,
1623  nsIArray * aMediaLists);
1624 
1631  static nsresult GetImportSettings(sbIDeviceLibrary * aDevLibrary,
1632  PRBool * aImportAudio,
1633  PRBool * aImportVideo);
1634 
1640  nsresult CopyChangedMediaItemsToMediaList(sbILibraryChange * aChange,
1641  sbIMediaList * aMediaList);
1642 };
1643 
1644 
1646  sbBaseDevice::Batch & aNonTranscodeItems,
1647  sbBaseDevice::Batch & aTrancodeItems,
1648  sbBaseDevice::Batch & aPlaylistItems);
1649 //
1650 // Auto-disposal class wrappers.
1651 //
1652 // sbAutoResetEnsureSpaceChecked
1653 // Wrapper to automatically reset the space
1654 // checked flag.
1655 
1656 SB_AUTO_NULL_CLASS(sbAutoResetEnsureSpaceChecked,
1657  sbBaseDevice*,
1658  mValue->SetEnsureSpaceChecked(false));
1659 
1660 #endif /* __SBBASEDEVICE__H__ */
nsCOMPtr< nsIFile > downloadedFile
Definition: sbBaseDevice.h:190
PRLock * mVolumeLock
Definition: sbBaseDevice.h:873
return NS_OK
nsresult CreateAndDispatchDeviceManagerEvent(PRUint32 aType, nsIVariant *aData, nsISupports *aOrigin, PRUint32 aDeviceState, PRBool aAsync)
Definition: sbIPDUtils.cpp:72
void SBWriteRequestSplitBatches(const sbBaseDevice::Batch &aInput, sbBaseDevice::Batch &aNonTranscodeItems, sbBaseDevice::Batch &aTrancodeItems, sbBaseDevice::Batch &aPlaylistItems)
nsAutoPtr< sbDeviceStatusHelper > mStatus
Definition: sbBaseDevice.h:689
PRLock * StateLock()
Definition: sbBaseDevice.h:627
const unsigned long REQUEST_SYNC
Definition: sbIDevice.idl:265
[UNIMPLEMENTED UNTIL AFTER 0.3]
PRLock * mPreviousStateLock
Definition: sbBaseDevice.h:685
nsRefPtr< sbDeviceRequestThreadQueue > mRequestThreadQueue
Definition: sbBaseDevice.h:730
const unsigned long REQUEST_WIPE
Definition: sbIDevice.idl:267
nsRefPtr< sbBaseDeviceVolume > mPrimaryVolume
Definition: sbBaseDevice.h:879
PRUint32 GetType() const
Definition: sbRequestItem.h:65
nsCOMPtr< sbIDeviceLibrary > mDefaultLibrary
Definition: sbBaseDevice.h:691
PRUint32 mSyncType
Definition: sbBaseDevice.h:715
sbDeviceImages * GetDeviceImages() const
Definition: sbBaseDevice.h:638
Songbird Base Device Volume Definitions.
nsCOMPtr< sbILibrary > mMainLibrary
Definition: sbBaseDevice.h:692
CompatibilityType destinationCompatibility
Definition: sbBaseDevice.h:180
const nsIPrefBranch
An object defining a transcoding profile.
PRUint32 mCanTranscodeAudio
Definition: sbBaseDevice.h:709
nsRefPtr< sbBaseDeviceLibraryListener > mLibraryListener
Definition: sbBaseDevice.h:693
A brief description of the contents of this interface.
nsRefPtr< sbBaseDeviceVolume > mDefaultVolume
Definition: sbBaseDevice.h:880
PRUint32 mInfoRegistrarType
Definition: sbBaseDevice.h:697
sbDeviceTranscoding * mDeviceTranscoding
Definition: sbBaseDevice.h:701
const unsigned long REQUEST_SUSPEND
Definition: sbIDevice.idl:260
const unsigned long REQUEST_READ
Definition: sbIDevice.idl:258
sbDeviceTranscoding * GetDeviceTranscoding() const
Definition: sbBaseDevice.h:619
nsRefPtr< sbDeviceBaseLibraryCopyListener > mLibraryCopyListener
Definition: sbBaseDevice.h:694
const unsigned long REQUEST_FLAG_USER
Definition: sbIDevice.idl:252
const unsigned long REQUEST_WRITE
Definition: sbIDevice.idl:263
const unsigned long REQUEST_DELETE
Definition: sbIDevice.idl:264
virtual nsresult InitDevice()
Definition: sbBaseDevice.h:655
const unsigned long REQUEST_EJECT
Definition: sbIDevice.idl:259
nsresult RemoveLibraryItems(T iter, T end)
const unsigned long REQUEST_WRITE_FILE
Definition: sbIDevice.idl:283
void SetEnsureSpaceChecked(bool aChecked)
Definition: sbBaseDevice.h:601
const unsigned long REQUEST_SYNC_COMPLETE
Definition: sbIDevice.idl:287
nsCOMPtr< nsITimer > mDeferredSetupDeviceTimer
Definition: sbBaseDevice.h:729
bool mEnsureSpaceChecked
Definition: sbBaseDevice.h:717
nsInterfaceHashtableMT< nsStringHashKey, sbBaseDeviceVolume > mVolumeGUIDTable
Definition: sbBaseDevice.h:876
nsDataHashtableMT< nsISupportsHashKey, nsRefPtr< sbBaseDeviceMediaListListener > > mMediaListListeners
Definition: sbBaseDevice.h:695
PRUint32 mMusicLimitPercent
Definition: sbBaseDevice.h:700
function Init()
void * aClosure
Definition: sbArray.cpp:52
nsCOMPtr< sbIDeviceInfoRegistrar > mInfoRegistrar
Definition: sbBaseDevice.h:696
PRUint32 mPerTrackOverhead
Definition: sbBaseDevice.h:688
sbITranscodeProfile * transcodeProfile
Definition: sbBaseDevice.h:158
Media library abstraction.
Definition: sbILibrary.idl:82
SB_AUTO_NULL_CLASS(sbAutoResetEnsureSpaceChecked, sbBaseDevice *, mValue->SetEnsureSpaceChecked(false))
const unsigned long REQUEST_FLAG_WRITE
Definition: sbIDevice.idl:253
const unsigned long REQUEST_DELETE_FILE
Definition: sbIDevice.idl:284
const PR_UINT32_MAX
Definition: httpd.js:55
nsClassHashtable< nsUint32HashKey, nsString > mMediaFolderURLTable
Definition: sbBaseDevice.h:741
PRBool mConnected
Definition: sbBaseDevice.h:728
const unsigned long REQUEST_MOVE
Definition: sbIDevice.idl:269
nsTArray< nsRefPtr< sbBaseDeviceVolume > > mVolumeList
Definition: sbBaseDevice.h:874
_updateCookies aName
Songbird Device Statistics Definitions.
sbRequestThreadQueue::Batch Batch
Definition: sbBaseDevice.h:110
const unsigned long REQUEST_IMAGESYNC
Definition: sbIDevice.idl:280
PRLock * mPreferenceLock
Definition: sbBaseDevice.h:699
const unsigned long REQUEST_FORMAT
Definition: sbIDevice.idl:277
nsDataHashtableMT< nsStringHashKey, PRBool > mTrackSourceTable
Definition: sbBaseDevice.h:833
nsCOMPtr< sbIDeviceCapabilities > mCapabilities
Definition: sbBaseDevice.h:698
sbDeviceImages * mDeviceImages
Definition: sbBaseDevice.h:702
PRUint32 mState
Definition: sbBaseDevice.h:684
const unsigned long REQUEST_NEW_PLAYLIST
Definition: sbIDevice.idl:271
nsCOMPtr< sbIMediaItem > item
Definition: sbBaseDevice.h:155
Interface that defines a single item of media in the system.
PRUint32 GetDeviceState()
Definition: sbBaseDevice.h:634
nsCOMPtr< sbITemporaryFileFactory > temporaryFileFactory
Definition: sbBaseDevice.h:188
restoreWindow aState
nsClassHashtableMT< nsIDHashKey, OrganizeData > mOrganizeLibraryPrefs
Definition: sbBaseDevice.h:739
nsInterfaceHashtableMT< nsStringHashKey, sbBaseDeviceVolume > mVolumeLibraryGUIDTable
Definition: sbBaseDevice.h:878
const unsigned long REQUEST_MOUNT
Definition: sbIDevice.idl:257
nsCOMPtr< sbIMediaList > list
Definition: sbBaseDevice.h:156
PRLock * mStateLock
Definition: sbBaseDevice.h:683
nsCOMPtr< sbITranscodeAlbumArt > albumArt
Definition: sbBaseDevice.h:183
const unsigned long REQUEST_UPDATE
Definition: sbIDevice.idl:270
PRUint32 mCanTranscodeVideo
Definition: sbBaseDevice.h:710
PRRWLock * mConnectLock
Definition: sbBaseDevice.h:727
PRUint32 mPreviousState
Definition: sbBaseDevice.h:686
PRInt32 mIgnoreMediaListCount
Definition: sbBaseDevice.h:687
_updateTextAndScrollDataForFrame aData
nsCOMPtr< nsISupports > data
Definition: sbBaseDevice.h:157