sbIPDDevice.h
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 #ifndef __SB_IPD_DEVICE_H__
28 #define __SB_IPD_DEVICE_H__
29 
30 //------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------
32 //
33 // iPod device defs.
34 //
35 //------------------------------------------------------------------------------
36 //------------------------------------------------------------------------------
37 
43 //------------------------------------------------------------------------------
44 //
45 // iPod device imported services.
46 //
47 //------------------------------------------------------------------------------
48 
49 // Local imports.
50 #include "sbIPDLibrary.h"
51 #include "sbIPDProperties.h"
52 #include "sbIPDStatus.h"
53 
54 // Songbird imports.
55 #include <sbBaseDevice.h>
56 #include <sbDeviceCapabilities.h>
57 #include <sbIDatabaseQuery.h>
58 #include <sbIDeviceContent.h>
59 #include <sbIDeviceLibrary.h>
60 #include <sbILibraryManager.h>
61 #include <sbIPropertyArray.h>
62 #include <sbIPropertyManager.h>
64 
65 // Mozilla imports.
66 #include <nsIClassInfo.h>
67 #include <nsIFileProtocolHandler.h>
68 #include <nsIRunnable.h>
69 #include <nsIStringBundle.h>
70 #include <nsIThread.h>
71 #include <nsTArray.h>
72 #include <prrwlock.h>
73 
74 /* C++ STL imports. */
75 #include <map>
76 #include <vector>
77 
78 // Libgpod imports.
79 #include <itdb.h>
80 
81 
82 //------------------------------------------------------------------------------
83 //
84 // Thread support strategy:
85 //
86 // The iPod device services provide support for multi-threaded access using
87 // a combination of locks and request queues. Certain iPod device object
88 // fields may only be accessed under a lock and some may be accessed without
89 // restriction.
90 // The iPod device object fields are divided into different categories
91 // depending upon their access policy.
92 // After the iPod device object is created, the only method that is
93 // available is the Initialize method. It must be called immediately after
94 // object construction (XXXeps, currently, the object constructor calls the
95 // Initialize method). After initialization, all other methods may be called;
96 // however, some may return a not available error (e.g., those that depend
97 // upon the device being connected).
98 // Fields within the "not locked" category are created during initialization
99 // and may be accessed at any time without acquiring a lock. These fields are
100 // assumed to be internally thread safe. Fields within the "constant"
101 // category are created and set during initialization and should never be
102 // altered afterward.
103 //
104 // Fields within the "connect lock" category must only be accessed within
105 // the connect lock. All fields except mConnectLock and mConnected are
106 // only usable when the device is connected. These fields are created and
107 // initialized during device connection and are disposed of when the device is
108 // disconnected.
109 // The connect lock is a read/write lock. Only the Connect and Disconnect
110 // methods acquire a write lock on the connect lock. All other methods
111 // acquire read locks.
112 // In order to access the "connect lock" fields, a method must first
113 // acquire a read lock on the connect lock and check the mConnected field to
114 // see if the device is connected. If the device is not connected, the method
115 // must release the connect lock and not access any other field. If the
116 // device is connected, the method may access any field as long as it holds
117 // the connect lock.
118 // Since the connect lock is a read/write lock, acquiring a read lock does
119 // not lock out other threads from acquiring a read lock. This allows the
120 // request thread to maintain a long lived read lock on the connect lock
121 // without locking out other threads; it only locks out device disconnect.
122 // The "connect lock" only ensures that the "connect lock" field values won't
123 // change. Thus, the values of "connect lock" pointer fields will always point
124 // to the same location while the connect lock is held. However, the "connect
125 // lock" does not ensure that the data pointed to does not change. If a
126 // "connect lock" field is not internally thread safe, it may need to be
127 // protected within another lock (e.g., mITDB).
128 //
129 // Fields within the "request lock" category may only be accessed within the
130 // request lock. Each time the request thread processes a request, it
131 // acquires the request lock until the request completes.
132 //
133 // Fields within the "pref lock" category may only be accessed within the
134 // preference lock. In order to access "pref lock" fields, a method must first
135 // acquire the preference lock and check the mPrefConnected field to see if the
136 // preference services are connected. If not, the method must release the
137 // preference lock and not access any other field.
138 //
139 // Connect lock
140 //
141 // mConnected
142 // mPrefLock
143 // mDeviceLibrary
144 // mDeviceLibraryML
145 // mMountPath
146 // mITDB
147 // mITDBDirty
148 // mITDBDevice
149 // mMasterPlaylist
150 // mReqAddedEvent
151 // mReqThread
152 //
153 // Request lock
154 //
155 // mITDB
156 // mITDBDirty
157 // mITDBDevice
158 // mMasterPlaylist
159 // mIPDStatus
160 // mStatsUpdatePeriod
161 // mLastStatsUpdate
162 //
163 // Pref lock
164 //
165 // mPrefConnected
166 // mIPodPrefs
167 // mIPodPrefsDirty
168 // mSyncPlaylistList
169 // mSyncPlaylistListDirty
170 //
171 // Not locked
172 // mConnectLock
173 // mRequestLock
174 // mReqStopProcessing
175 // mDeviceContent
176 // mCreationProperties
177 // mCreationProperties2
178 // mProperties
179 // mCapabilities
180 // mSBMainLib
181 // mSBMainML
182 //
183 // Constant
184 // mDeviceID
185 // mControllerID
186 // mFileProtocolHandler
187 // mPropertyManager
188 // mLibraryManager
189 // mLocale
190 // mFirewireGUID
191 // mIPodEventHandler
192 //
193 //------------------------------------------------------------------------------
194 
195 
196 //------------------------------------------------------------------------------
197 //
198 // iPod device defs.
199 //
200 //------------------------------------------------------------------------------
201 
202 //
203 // iPod device configuration.
204 //
205 // IPOD_LOCALE_BUNDLE_PATH Path to localized string bundle.
206 // IPOD_STATS_UPDATE_PERIOD Period in milliseconds for updating the iPod
207 // statistics.
208 //
209 
210 #define IPOD_LOCALE_BUNDLE_PATH "chrome://ipod/locale/IPodDevice.properties"
211 #define IPOD_STATS_UPDATE_PERIOD 500
212 
213 
214 //------------------------------------------------------------------------------
215 //
216 // iPod device globals.
217 //
218 //------------------------------------------------------------------------------
219 
220 //
221 // sbIPDSupportedMediaList List of supported media file extensions derived
222 // from "http://docs.info.apple.com/article.html?artnum=304784".
223 // sbIPDSupportedMediaListLength Length of supported media file extension list.
224 // sbIPDSupportedAudioMediaList List of supported audio media file extensions
225 // derived from
226 // "http://docs.info.apple.com/article.html?artnum=304784".
227 // sbIPDSupportedAudioMediaListLength
228 // Length of supported audio media file extension
229 // list.
230 //
231 
232 extern const char *sbIPDSupportedMediaList[];
233 extern PRUint32 sbIPDSupportedMediaListLength;
234 extern const char *sbIPDSupportedAudioMediaList[];
235 extern PRUint32 sbIPDSupportedAudioMediaListLength;
236 
237 
238 //------------------------------------------------------------------------------
239 //
240 // iPod device classes.
241 //
242 //------------------------------------------------------------------------------
243 
249 class sbIPDDevice : public sbBaseDevice,
250  public nsIClassInfo
251 {
252  //----------------------------------------------------------------------------
253  //
254  // Class friends.
255  //
256  //----------------------------------------------------------------------------
257 
258  friend class sbIPDAutoDBFlush;
259  friend class sbIPDAutoIdle;
260  friend class sbIPDAutoTrack;
261  friend class sbIPDLibrary;
262  friend class sbIPDReqAddedEvent;
263  friend class sbIPDProperties;
264 
265 
266  //----------------------------------------------------------------------------
267  //
268  // Public interface.
269  //
270  //----------------------------------------------------------------------------
271 
272 public:
273 
274  //
275  // Inherited interfaces.
276  //
277 
279  NS_DECL_SBIDEVICE
280  NS_DECL_NSICLASSINFO
281 
282 
283  //
284  // Constructors/destructors.
285  //
286 
287  sbIPDDevice(const nsID& aControllerID,
288  nsIPropertyBag* aProperties);
289 
290  virtual ~sbIPDDevice();
291 
292 
293  //----------------------------------------------------------------------------
294  //
295  // Protected interface.
296  //
297  //----------------------------------------------------------------------------
298 
299 protected:
300 
301  //
302  // Internal iPod device services.
303  //
304 
305  nsresult Initialize();
306 
307  void Finalize();
308 
309  virtual nsresult DeviceSpecificDisconnect();
310 
311  //
312  // Internal iPod device properties services.
313  //
314 
315  virtual nsresult InitializeProperties();
316 
317 
318  //----------------------------------------------------------------------------
319  //
320  // Private interface.
321  //
322  //----------------------------------------------------------------------------
323 
324 private:
325 
326  //----------------------------------------------------------------------------
327  //
328  // iPod device sbIDevice services.
329  //
330  //----------------------------------------------------------------------------
331 
332  nsresult ConnectInternal();
333 
334 
335  //----------------------------------------------------------------------------
336  //
337  // iPod device mapping services.
338  //
339  //----------------------------------------------------------------------------
340 
341  //
342  // iPod device mapping services defs.
343  //
344  // TypeTrack Item is a track.
345  // TypePlaylist Item is a playlist.
346  //
347  // SBIDDelimiter Delimiter between fields in mapped Songbird
348  // ID's.
349  //
350 
351  static const int TypeTrack = 1;
352  static const int TypePlaylist = 2;
353 
354  static const char SBIDDelimiter = ':';
355 
356 
357  //
358  // iPod device mapping services.
359  //
360 
361  nsresult MapInitialize();
362 
363  void MapFinalize();
364 
365 
366  //
367  // iPod device ID mapping services.
368  //
369 
370  nsresult IDMapAdd(nsAString& aSBID,
371  guint64 aIPodID);
372 
373  nsresult IDMapRemove(guint64 aIPodID);
374 
375  nsresult IDMapGet(nsAString& aSBID,
376  nsTArray<guint64>& aIPodIDList);
377 
378  nsresult IDMapGet(nsAString& aSBID,
379  guint64* aIPodID);
380 
381  nsresult IDMapGet(guint64 aIPodID,
382  nsAString& aSBID);
383 
384  nsresult IDMapGet(guint64 aIPodID,
385  nsAString& aLibraryGUID,
386  nsAString& aResourceGUID);
387 
388  nsresult IDMapGet(guint64 aIPodID,
389  sbIMediaItem** aMediaItem);
390 
391  nsresult IDMapCreateDBQuery(sbIDatabaseQuery** aQuery);
392 
393  nsresult GetSBID(sbIMediaItem* aMediaItem,
394  nsAString& aSBID);
395 
396 
397  //
398  // Internal iPod device mapping services.
399  //
400 
401  nsresult IPodItemGetID(void* aIPodItem,
402  int aType,
403  guint64* aIPodID);
404 
405  nsresult DecodeSBID(const nsAString& aSBID,
406  nsAString& aLibraryGUID,
407  nsAString& aResourceGUID);
408 
409  nsresult EncodeSBID(nsAString& aSBID,
410  const nsAString& aLibraryGUID,
411  const nsAString& aResourceGUID);
412 
413  nsresult ExecuteQuery(sbIDatabaseQuery* aDBQuery,
414  const char* aQueryStr,
415  sbIDatabaseResult** aDBResult);
416 
417 
418  //----------------------------------------------------------------------------
419  //
420  // iPod device request services.
421  //
422  //----------------------------------------------------------------------------
423 
424  //
425  // Request services defs.
426  //
427  // REQUEST_WRITE_PREFS Use to write the device preferences.
428  // REQUEST_SET_PROPERTY Use to set device properties.
429  // REQUEST_SET_PREF Use to set device preferences.
430  //
431 
432  static const PRUint32 REQUEST_WRITE_PREFS =
434  static const PRUint32 REQUEST_SET_PROPERTY =
436  static const PRUint32 REQUEST_SET_PREF =
438 
439 
440  //
441  // Request services set named value class.
442  //
443  // name Name of value to set.
444  // value Value to set.
445  //
446 
447  class SetNamedValueRequest : public TransferRequest
448  {
449  public:
450  SetNamedValueRequest(PRUint32 aType)
451  {
452  SetType(REQUEST_SET_PROPERTY);
453  }
454  nsString name;
455  nsCOMPtr<nsIVariant> value;
456  };
457 
458  //
459  // iPod device request handler services.
460  //
461 
462  virtual nsresult ProcessBatch(Batch & aBatch);
463 
464  void ReqHandleMount(TransferRequest* aRequest);
465 
466  void ReqHandleWrite(TransferRequest* aRequest, PRUint32 aBatchCount);
467 
468  void ReqHandleWriteTrack(TransferRequest* aRequest, PRUint32 aBatchCount);
469 
470  void ReqHandleWritePlaylistTrack(TransferRequest* aRequest);
471 
472  void ReqHandleDelete(TransferRequest* aRequest,
473  PRUint32 aBatchCount);
474 
475  void ReqHandleDeleteTrack(TransferRequest* aRequest,
476  PRUint32 aBatchCount);
477 
478  void ReqHandleDeletePlaylistTrack(TransferRequest* aRequest);
479 
480  void ReqHandleDeletePlaylist(TransferRequest* aRequest);
481 
482  void ReqHandleWipe(TransferRequest* aRequest);
483 
484  void ReqHandleNewPlaylist(TransferRequest* aRequest);
485 
486  void ReqHandleUpdate(TransferRequest* aRequest);
487 
488  void ReqHandleMovePlaylistTrack(TransferRequest* aRequest);
489 
490  void ReqHandleFactoryReset(TransferRequest* aRequest);
491 
492  void ReqHandleWritePrefs(TransferRequest* aRequest);
493 
494  void ReqHandleSetProperty(TransferRequest* aRequest);
495 
496  void ReqHandleSetPref(SetNamedValueRequest* aRequest);
497 
498  //
499  // iPod device request services.
500  //
501 
502  nsresult ReqPushSetNamedValue(int aType,
503  const nsAString& aName,
504  nsIVariant* aValue);
505 
506 
507  //----------------------------------------------------------------------------
508  //
509  // iPod device track services.
510  //
511  //----------------------------------------------------------------------------
512 
513  //
514  // iPod device track services.
515  //
516 
517  nsresult ImportTracks();
518 
519  nsresult UploadTrack(sbIMediaItem* aMediaItem);
520 
521  nsresult AddTrack(sbIMediaItem* aMediaItem,
522  Itdb_Track** aTrack);
523 
524  nsresult DeleteTrack(sbIMediaItem* aMediaItem);
525 
526  nsresult DeleteTrack(Itdb_Track* aTrack);
527 
528  nsresult WipeDevice();
529 
530  nsresult GetTrack(sbIMediaItem* aMediaItem,
531  Itdb_Track** aTrack);
532 
533 
534  //
535  // iPod device track property services.
536  //
537 
538  void SetTrackProperties(Itdb_Track* aTrack,
539  sbIMediaItem* aMediaItem);
540 
541  void SetTrackProperties(sbIMediaItem* aMediaItem,
542  Itdb_Track* aTrack);
543 
544  nsresult GetTrackProperties(Itdb_Track* aTrack,
545  sbIPropertyArray** aPropertyArray);
546 
547  nsresult GetTrackProperties(Itdb_Track* aTrack,
548  nsIMutableArray* aPropertiesArrayArray);
549 
550  nsresult TrackUpdateProperties(sbIMediaItem* aMediaItem,
551  Itdb_Track* aTrack = NULL);
552 
553  nsresult GetTrackProp(sbIMediaItem* aMediaItem,
554  const char* aPropName,
555  gchar** aProp);
556 
557  nsresult SetTrackProp(sbIMediaItem* aMediaItem,
558  const char* aPropName,
559  gchar* aProp);
560 
561  nsresult SetTrackProp(sbIMutablePropertyArray* aPropertyArray,
562  const char* aPropName,
563  const nsAString& aProp);
564 
565  nsresult SetTrackProp(sbIMutablePropertyArray* aPropertyArray,
566  const char* aPropName,
567  gchar* aProp);
568 
569  nsresult GetTrackProp(sbIMediaItem* aMediaItem,
570  const char* aPropName,
571  gint* aProp);
572 
573  nsresult SetTrackProp(sbIMediaItem* aMediaItem,
574  const char* aPropName,
575  gint aProp);
576 
577  nsresult SetTrackProp(sbIMutablePropertyArray* aPropertyArray,
578  const char* aPropName,
579  gint aProp);
580 
581  nsresult GetTrackProp(sbIMediaItem* aMediaItem,
582  const char* aPropName,
583  guint32* aProp);
584 
585  nsresult SetTrackProp(sbIMediaItem* aMediaItem,
586  const char* aPropName,
587  guint32 aProp);
588 
589  nsresult SetTrackProp(sbIMutablePropertyArray* aPropertyArray,
590  const char* aPropName,
591  guint32 aProp);
592 
593  nsresult GetTrackProp(sbIMediaItem* aMediaItem,
594  const char* aPropName,
595  guint64* aProp);
596 
597  nsresult SetTrackProp(sbIMediaItem* aMediaItem,
598  const char* aPropName,
599  guint64 aProp);
600 
601  nsresult SetTrackProp(sbIMutablePropertyArray* aPropertyArray,
602  const char* aPropName,
603  guint64 aProp);
604 
605  nsresult GetTrackPropDur(sbIMediaItem* aMediaItem,
606  const char* aPropName,
607  gint* aProp);
608 
609  nsresult SetTrackPropDur(sbIMediaItem* aMediaItem,
610  const char* aPropName,
611  gint aProp);
612 
613  nsresult SetTrackPropDur(sbIMutablePropertyArray* aPropertyArray,
614  const char* aPropName,
615  gint aProp);
616 
617  nsresult GetTrackPropRating(sbIMediaItem* aMediaItem,
618  const char* aPropName,
619  guint32* aProp);
620 
621  nsresult SetTrackPropRating(sbIMediaItem* aMediaItem,
622  const char* aPropName,
623  guint32 aProp);
624 
625  nsresult SetTrackPropRating(sbIMutablePropertyArray* aPropertyArray,
626  const char* aPropName,
627  guint32 aProp);
628 
629  nsresult GetTrackPropFileType(sbIMediaItem* aMediaItem,
630  gchar** aProp);
631 
632 
633  //
634  // iPod device track info services.
635  //
636 
637  nsresult GetTrackURI(Itdb_Track* aTrack,
638  nsIURI** aTrackURI);
639 
640  nsresult TrackGetFile(Itdb_Track* aTrack,
641  nsIFile** aTrackFile);
642 
643 
644  //
645  // Internal iPod device track services.
646  //
647 
648  nsresult ImportTrackBatch(Itdb_Track** aTrackBatch,
649  PRUint32 aBatchCount);
650 
651  static nsresult ImportTrackBatch1(nsISupports* aUserData);
652 
653  nsresult ImportTrackBatch2(Itdb_Track** aTrackBatch,
654  PRUint32 aBatchCount);
655 
656  void RemoveTrackFromAllPlaylists(Itdb_Track* aTrack);
657 
658  PRBool IsMediaSupported(sbIMediaItem* aMediaItem);
659 
660  void AddUnsupportedMediaItem(sbIMediaItem* aMediaItem);
661 
662 
663  //----------------------------------------------------------------------------
664  //
665  // iPod device playlist services.
666  //
667  //----------------------------------------------------------------------------
668 
669  //
670  // iPod device playlist services configuration.
671  //
672  // TrackBatchSize Number of tracks to process in a batch.
673  //
674 
675  static const PRUint32 TrackBatchSize = 100;
676 
677 
678  //
679  // iPod device playlist import services.
680  //
681 
682  nsresult ImportPlaylists();
683 
684  nsresult ImportPlaylist(Itdb_Playlist* aPlaylist);
685 
686  nsresult ImportPlaylist(sbILibrary* aLibrary,
687  Itdb_Playlist* aPlaylist,
688  sbIMediaList** aMediaList = nsnull);
689 
690  nsresult ImportPlaylistTracks(Itdb_Playlist* aPlaylist,
691  sbIMediaList* aMediaList);
692 
693  nsresult ImportPlaylistTrackBatch(sbIMediaList* aMediaList,
694  Itdb_Track** aTrackBatch,
695  PRUint32 aBatchCount);
696 
697 
698  //
699  // iPod device playlist manipulation services.
700  //
701 
702  nsresult PlaylistAdd(sbIMediaList* aMediaList,
703  Itdb_Playlist** aPlaylist);
704 
705  nsresult PlaylistDelete(sbIMediaList* aMediaList);
706 
707  nsresult PlaylistUpdateProperties(sbIMediaList* aMediaList,
708  Itdb_Playlist* aPlaylist = NULL);
709 
710  nsresult PlaylistAddTrack(sbIMediaList* aMediaList,
711  sbIMediaItem* aMediaItem,
712  PRUint32 aIndex);
713 
714  nsresult PlaylistRemoveTrack(sbIMediaList* aMediaList,
715  sbIMediaItem* aMediaItem,
716  PRUint32 aIndex);
717 
718  nsresult PlaylistMoveTrack(sbIMediaList* aMediaList,
719  PRUint32 aIndexFrom,
720  PRUint32 aIndexTo);
721 
722  nsresult PlaylistWipe(sbIMediaList * aMediaList);
723 
724 
725  //
726  // iPod device on-the-go playlist services.
727  //
728 
729  nsresult ProcessOTGPlaylists();
730 
731  nsresult SetOTGPlaylistName(Itdb_Playlist* aPlaylist,
732  PRUint32 aPlaylistIndex);
733 
734 
735  //
736  // iPod device playlist services.
737  //
738 
739  nsresult GetPlaylist(sbIMediaItem* aMediaItem,
740  Itdb_Playlist** aPlaylist);
741 
742 
743  //----------------------------------------------------------------------------
744  //
745  // iPod device FairPlay services.
746  //
747  //----------------------------------------------------------------------------
748 
749  //
750  // FairPlay services fields.
751  //
752  // mFPUserIDList List of FairPlay user IDs for which the device
753  // is authorized.
754  //
755 
756  nsTArray<PRUint32> mFPUserIDList;
757 
758 
759  //
760  // FairPlay services.
761  //
762 
763  nsresult FPConnect();
764 
765  void FPDisconnect();
766 
767  nsresult FPCheckTrackAuth(Itdb_Track* aTrack);
768 
769  nsresult FPSetupTrackInfo(nsIFile* aTrackFile,
770  Itdb_Track* aTrack);
771 
772 
773  //
774  // Internal FairPlay services.
775  //
776 
777  nsresult FPGetKeyInfo();
778 
779  nsresult FPGetTrackAuthInfo(Itdb_Track* aTrack,
780  PRUint32* aUserID,
781  nsAString& aAccountName,
782  nsAString& aUserName);
783 
784 
785  //----------------------------------------------------------------------------
786  //
787  // iPod device connection services.
788  //
789  //----------------------------------------------------------------------------
790 
791  nsresult DBConnect();
792 
793  void DBDisconnect();
794 
795  nsresult LibraryConnect();
796 
797  void LibraryDisconnect();
798 
799  nsresult InitSysInfo();
800 
801 
802  //----------------------------------------------------------------------------
803  //
804  // iPod device preference services.
805  //
806  //----------------------------------------------------------------------------
807 
808  //
809  // Preference services fields.
810  //
811  // mPrefLock Preference lock.
812  // mPrefConnected True if preference services are connected.
813  // mIPodPrefs iPod preferences record.
814  // mIPodPrefsDirty True if the iPod preferences are dirty and need
815  // to be written.
816  // mSyncPlaylistList List of playlists from which to synchronize.
817  // mSyncPlaylistListDirty True if the sync playlist list is dirty and
818  // needs to be written.
819  //
820 
821  PRLock* mPrefLock;
822  PRBool mPrefConnected;
823  Itdb_Prefs* mIPodPrefs;
824  PRBool mIPodPrefsDirty;
825  nsTArray<guint64> mSyncPlaylistList;
826  PRBool mSyncPlaylistListDirty;
827 
828 
829  //
830  // Preference services.
831  //
832 
833  nsresult PrefInitialize();
834 
835  void PrefFinalize();
836 
837  nsresult PrefConnect();
838 
839  void PrefDisconnect();
840 
841 
842  //
843  // Preference sbIDeviceLibrary services.
844  //
845 
846  nsresult GetMgmtType(PRUint32* aMgmtType);
847 
848  nsresult SetMgmtType(PRUint32 aMgmtType);
849 
850  nsresult GetIsSetUp(PRBool* aIsSetUp);
851 
852  nsresult SetIsSetUp(PRBool aIsSetUp);
853 
854  nsresult GetSyncPlaylistList(nsIArray** aPlaylistList);
855 
856  nsresult SetSyncPlaylistList(nsIArray* aPlaylistList);
857 
858  nsresult AddToSyncPlaylistList(sbIMediaList* aPlaylist);
859 
860  nsresult GetSyncPlaylist(sbIMediaItem* aPlaylist,
861  guint64* aIPodID);
862 
863 
864  //
865  // Preference iPod preferences services.
866  //
867 
868  nsresult PrefConnectIPodPrefs();
869 
870  void PrefDisconnectIPodPrefs();
871 
872  nsresult PrefInitializeSyncPartner();
873 
874 
875  //----------------------------------------------------------------------------
876  //
877  // iPod device sync services.
878  //
879  //----------------------------------------------------------------------------
880 
881  //
882  // iPod device sync track services.
883  //
884 
885  nsresult SyncFromIPodTracks();
886 
887  nsresult SyncFromIPodTrack(Itdb_Track* aTrack);
888 
889 
890  //
891  // iPod device sync services.
892  //
893 
894  nsresult SyncFromDevice();
895 
896  nsresult SyncFromOTGPlaylists();
897 
898 
899  //----------------------------------------------------------------------------
900  //
901  // iPod device statistics services.
902  //
903  //----------------------------------------------------------------------------
904 
905  //
906  // Statistics services fields.
907  //
908  // mStatsUpdatePeriod Statistics update time period.
909  // mLastStatsUpdate Time of last statistics update.
910  //
911 
912  PRIntervalTime mStatsUpdatePeriod;
913  PRIntervalTime mLastStatsUpdate;
914 
915 
916  //
917  // Statistics services.
918  //
919 
920  nsresult StatsInitialize();
921 
922  void StatsFinalize();
923 
924  void StatsUpdate(PRBool aForceUpdate);
925 
926 
927  //----------------------------------------------------------------------------
928  //
929  // iPod device event services.
930  //
931  //----------------------------------------------------------------------------
932 
933  //
934  // mIPodEventHandler Handler for iPod specific events.
935  //
936 
937  nsCOMPtr<nsISupports> mIPodEventHandler;
938 
939 
940  //
941  // Device event services.
942  //
943 
944  nsresult CreateAndDispatchFairPlayEvent(PRUint32 aType,
945  PRUint32 aUserID,
946  nsAString& aAccountName,
947  nsAString& aUserName,
948  sbIMediaItem* aMediaItem = nsnull,
949  PRBool aAsync = PR_TRUE);
950 
951 
952  //----------------------------------------------------------------------------
953  //
954  // Internal iPod device services.
955  //
956  //----------------------------------------------------------------------------
957 
958  //
959  // Internal services fields.
960  //
961  // mConnectLock Connect lock.
962  // mRequestLock Request lock.
963  //
964  // mDeviceID ID of device.
965  // mControllerID ID of device controller.
966  // mDeviceContent Device content object.
967  // mDeviceLibrary Device library object.
968  // mDeviceLibraryML sbIMediaList interface for device library.
969  // mCreationProperties Set of device creation properties.
970  // mCreationProperties2 mCreationProperties as an nsIPropertyBag2.
971  // mProperties Set of device properties.
972  // mCapabilities Set of device capabilities.
973  //
974  // mITDB Libgpod iPod database data record.
975  // mITDBDirty True if the database is dirty and needs to be
976  // written.
977  // mITDBDevice Libgpod iPod device data record.
978  // mMasterPlaylist iPod database master playlist.
979  //
980  // mFileProtocolHandler File protocol handler object.
981  // mPropertyManager Media property manager object.
982  // mLibraryManager Songbird library manager object.
983  // mLocale Localized string bundle.
984  //
985  // mConnected True if device is connected.
986  // mFirewireGUID Device Firewire GUID.
987  // mIPDStatus iPod device status object.
988  // mMountPath iPod device file system mount path.
989  // mSBMainLib Songbird main library.
990  // mSBMainML Songbird main library media list.
991  //
992 
993  PRRWLock* mConnectLock;
994  PRMonitor* mDBLock;
995 
996  nsID mDeviceID;
997  nsID mControllerID;
998  nsCOMPtr<sbIDeviceContent> mDeviceContent;
999  nsRefPtr<sbIPDLibrary> mDeviceLibrary;
1000  nsCOMPtr<sbIMediaList> mDeviceLibraryML;
1001  nsCOMPtr<nsIPropertyBag> mCreationProperties;
1002  nsCOMPtr<nsIPropertyBag2> mCreationProperties2;
1003  nsRefPtr<sbIPDProperties> mProperties;
1004  nsCOMPtr<sbIDeviceCapabilities>
1005  mCapabilities;
1006 
1007  Itdb_iTunesDB* mITDB;
1008  PRBool mITDBDirty;
1009  Itdb_Device* mITDBDevice;
1010  Itdb_Playlist* mMasterPlaylist;
1011 
1012  nsCOMPtr<nsIFileProtocolHandler>
1013  mFileProtocolHandler;
1014  nsCOMPtr<sbIPropertyManager> mPropertyManager;
1015  nsCOMPtr<sbILibraryManager> mLibraryManager;
1016  nsCOMPtr<nsIStringBundle> mLocale;
1017 
1018  PRBool mConnected;
1019  nsString mFirewireGUID;
1020  sbIPDStatus* mIPDStatus;
1021  nsString mMountPath;
1022  nsCOMPtr<sbILibrary> mSBMainLib;
1023  nsCOMPtr<sbIMediaList> mSBMainML;
1024 
1025 
1026  //
1027  // Internal iPod device services.
1028  //
1029 
1030  nsresult ImportDatabase();
1031 
1032  nsresult DBFlush();
1033 
1034  nsresult CapabilitiesConnect();
1035 
1036  nsresult GetIPodID(sbIMediaItem* aMediaItem,
1037  guint64* aIPodID);
1038 
1039  nsresult CreateDeviceID(nsID* aDeviceID);
1040 
1041  nsresult AddNSIDHash(unsigned char* aBuffer,
1042  PRInt32& aOffset,
1043  nsIPropertyBag2* aPropBag,
1044  const nsAString& aProp);
1045 
1046  PRBool IsFileSystemSupported();
1047 
1048  nsresult SetUpIfNeeded();
1049 };
1050 
1051 
1057 class sbIPDReqAddedEvent : public nsIRunnable
1058 {
1059  //----------------------------------------------------------------------------
1060  //
1061  // Public interface.
1062  //
1063  //----------------------------------------------------------------------------
1064 
1065 public:
1066 
1067  //
1068  // Inherited interfaces.
1069  //
1070 
1072  NS_DECL_NSIRUNNABLE
1073 
1074 
1075  //
1076  // Public methods.
1077  //
1078 
1079  static nsresult New(sbIPDDevice* aDevice,
1080  nsIRunnable** aEvent);
1081 
1082 
1083  //----------------------------------------------------------------------------
1084  //
1085  // Public interface.
1086  //
1087  //----------------------------------------------------------------------------
1088 
1089 private:
1090 
1091  //
1092  // Private fields.
1093  //
1094  // mDevice Device associated with event.
1095  //
1096 
1097  nsRefPtr<sbIPDDevice> mDevice;
1098 
1099 
1100  // Make default constructor private to force use of factory methods.
1101  sbIPDReqAddedEvent() {};
1102 };
1103 
1104 
1120 SB_AUTO_CLASS(sbIPDAutoDBFlush,
1121  sbIPDDevice*,
1122  mValue,
1123  mValue->DBFlush(),
1124  mValue = nsnull);
1125 
1126 SB_AUTO_CLASS(sbIPDAutoIdle,
1127  sbIPDDevice*,
1128  mValue,
1129  mValue->mIPDStatus->Idle(),
1130  mValue = nsnull);
1131 
1132 SB_AUTO_CLASS2(sbIPDAutoTrack,
1133  Itdb_Track*,
1134  sbIPDDevice*,
1135  mValue,
1136  mValue2->DeleteTrack(mValue),
1137  mValue = NULL);
1138 
1139 SB_AUTO_CLASS(sbIPDAutoStopIgnoreLibrary,
1141  mValue,
1142  mValue->SetIgnoreListener(PR_FALSE),
1143  mValue = nsnull);
1144 
1145 SB_AUTO_CLASS(sbIPDAutoStopIgnoreMediaLists,
1146  sbIPDDevice*,
1147  mValue,
1148  mValue->SetIgnoreMediaListListeners(PR_FALSE),
1149  mValue = nsnull);
1150 
1151 SB_AUTO_CLASS(sbIPDAutoFalse,
1152  PRBool*,
1153  mValue,
1154  *mValue = PR_FALSE,
1155  mValue = nsnull);
1156 
1157 
1158 //------------------------------------------------------------------------------
1159 //
1160 // iPod device macros.
1161 //
1162 //------------------------------------------------------------------------------
1163 
1179 #define SB_IPD_DEVICE_AUTO_INVOKE(aName, aMethod) \
1180  SB_AUTO_CLASS(aName, sbIPDDevice*, mValue, mValue->aMethod, mValue = nsnull)
1181 
1182 
1183 #endif // __SB_IPD_DEVICE_H__
1184 
friend class sbIPDAutoTrack
Definition: sbIPDDevice.h:260
onPageChanged aValue
Definition: FeedWriter.js:1395
virtual nsresult InitializeProperties()
friend class sbIPDAutoIdle
Definition: sbIPDDevice.h:259
Songbird iPod Device Properties Definitions.
virtual nsresult DeviceSpecificDisconnect()
Songbird iPod Device Status Definitions.
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICE NS_DECL_NSICLASSINFO sbIPDDevice(const nsID &aControllerID, nsIPropertyBag *aProperties)
A brief description of the contents of this interface.
const char * sbIPDSupportedAudioMediaList[]
nsresult SetIgnoreListener(PRBool aIgnoreListener)
SB_AUTO_CLASS2(sbIPDAutoTrack, Itdb_Track *, sbIPDDevice *, mValue, mValue2->DeleteTrack(mValue), mValue=NULL)
NS_DECL_ISUPPORTS static NS_DECL_NSIRUNNABLE nsresult New(sbIPDDevice *aDevice, nsIRunnable **aEvent)
PRUint32 sbIPDSupportedAudioMediaListLength
An interface to carry around arrays of nsIProperty instances Note that implementations of the interfa...
friend class sbIPDAutoDBFlush
Definition: sbIPDDevice.h:258
const unsigned long REQUEST_FLAG_USER
Definition: sbIDevice.idl:252
virtual ~sbIPDDevice()
readonly attribute AString name
Definition: sbIDevice.idl:85
Songbird iPod Device Library Definitions.
SB_AUTO_CLASS(sbIPDAutoDBFlush, sbIPDDevice *, mValue, mValue->DBFlush(), mValue=nsnull)
Media library abstraction.
Definition: sbILibrary.idl:82
nsresult SetIgnoreMediaListListeners(PRBool aIgnoreListener)
An object containing the results of a database SELECT query.
const unsigned long REQUEST_FLAG_WRITE
Definition: sbIDevice.idl:253
_updateCookies aName
sbRequestThreadQueue::Batch Batch
Definition: sbBaseDevice.h:110
countRef value
Definition: FeedWriter.js:1423
PRUint32 sbIPDSupportedMediaListLength
An object responsible for executing SQL queries on the database.
Interface that defines a single item of media in the system.
nsresult Initialize()
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
const char * sbIPDSupportedMediaList[]
Definition: sbIPDDevice.cpp:93