sbCDDevice.h
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2011 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 #ifndef SBCDDEVICE_H_
26 #define SBCDDEVICE_H_
27 
28 #include <sbAutoRWLock.h>
29 #include <sbBaseDevice.h>
30 #include <sbICDDevice.h>
31 #include <sbDeviceCapabilities.h>
32 #include <sbIDeviceProperties.h>
33 #include <sbITranscodeManager.h>
34 #include <sbIMetadataLookupManager.h>
35 #include <sbIMetadataLookupProvider.h>
36 #include <sbIMetadataLookupData.h>
37 #include <sbMemoryUtils.h>
38 
39 #include <nsID.h>
40 #include <nsIRunnable.h>
41 #include <nsIThread.h>
42 
43 class sbIDeviceContent;
44 class nsIPropertyBag;
45 class sbIDeviceContent;
46 class nsIPropertyBag;
47 
48 //------------------------------------------------------------------------------
49 //
50 // Thread support strategy:
51 //
52 // The CD device base services provide support for multi-threaded access
53 // using a combination of locks and request queues. Certain CD device object
54 // fields may only be accessed from the request thread.
55 // The CD device base object fields are divided into different categories
56 // depending upon their access policy.
57 //
58 // Fields within the "not locked" category are created during initialization
59 // and may be accessed at any time without acquiring a lock.
60 //
61 // Fields within the "connect lock" category must only be accessed within the
62 // connect lock, mConnectLock. All of these fields except mConnected are only
63 // usable when the device is connected. These fields are initialized during
64 // device connection and finalized when the device is disconnected.
65 // The connect lock is a read/write lock. Only the Connect and Disconnect
66 // methods acquire a write lock on the connect lock. All other methods acquire
67 // read locks.
68 // In order to access the "connect lock" fields, a method must first acquire a
69 // read lock on the connect lock and check the mConnected field to see if the
70 // device is connected. If the device is not connected, the method must release
71 // the connect lock and not access any other "connect lock" field. If the
72 // device is connected, the method may access any "connect lock" field as long
73 // as it hold the connect lock.
74 // Since the connect lock is a read/write lock, acquiring a read lock does not
75 // lock out other threads from acquiring a read lock. This allows the request
76 // thread to maintain a long lived read lock on the connect lock without locking
77 // out other threads; it only locks out device disconnect.
78 // The "connect lock" only ensures that the "connect lock" fields won't be
79 // finalized from a disconnect. Some "connect lock" fields may need to be
80 // protected with another lock to ensure thread safety.
81 //
82 // Fields within the "Request Thread" category may only be accessed from the
83 // request thread.
84 //
85 // Fields within the "properties lock" category must only be accessed within
86 // the properties lock. While the properties object itself may be thread-safe,
87 // code that reads and conditionally writes properties requires locks (e.g.,
88 // property udpates).
89 //
90 // Connect lock
91 //
92 // mConnected
93 // mMountPath
94 // mMountURI
95 // mReqThread
96 // mReqWaitMonitor
97 // mDeviceLibrary
98 // mCapabilities
99 //
100 // Request Thread
101 //
102 // mTranscodeManager
103 //
104 // Properties lock
105 // mProperties
106 // mPrevFriendlyNameInitialized;
107 // mPrevFriendlyName;
108 // mPrevFriendlyNameExists;
109 //
110 // Not locked
111 //
112 // mConnectLock
113 // mDeviceID
114 // mControllerID
115 // mCreationProperties
116 // mAbortRequests
117 // mIsHandlingRequests
118 // mDeviceContent
119 // mDeviceSettingsLock
120 // mPropertiesLock
121 //
122 //------------------------------------------------------------------------------
123 
124 // Preference keys
125 #define PREF_CDDEVICE_RIPBRANCH "songbird.cdrip."
126 #define PREF_CDDEVICE_AUTOEJECT "oncomplete.autoeject"
127 #define PREF_CDDEVICE_NOTIFYSOUND "oncomplete.notifysound"
128 #define PREF_CDDEVICE_RIPFORMAT "format"
129 #define PREF_CDDEVICE_RIPQUALITY "quality"
130 
135 class sbCDDevice : public sbBaseDevice,
136  public sbIJobProgressListener,
137  public nsIClassInfo
138 {
139 public:
140  //
141  // Implemented interfaces.
142  //
143 
145  NS_DECL_SBIDEVICE
146  NS_DECL_SBIJOBPROGRESSLISTENER
147  NS_DECL_NSICLASSINFO
148 
152  sbCDDevice(const nsID & aControllerId,
153  nsIPropertyBag *aProperties);
154 
158  virtual ~sbCDDevice();
159 
163  virtual nsresult InitDevice();
164 
168  static nsresult New(const nsID & aControllerId,
169  nsIPropertyBag *aProperties,
170  sbCDDevice **aOutCDDevice);
171 
172  virtual PRBool IsRequestAborted();
173 private:
177  PRMonitor* mPropertiesLock;
178 
184  PRRWLock* mConnectLock;
185 
189  nsCOMPtr<sbITranscodeManager> mTranscodeManager;
190 
191 
195  nsID mDeviceID;
196 
200  nsID mControllerID;
201 
202  nsCOMPtr<sbICDDevice> mCDDevice;
203 
207  nsCOMPtr<sbIDeviceLibrary> mDeviceLibrary;
208 
212  nsCOMPtr<sbIDeviceCapabilities> mCapabilities;
213 
217  nsCOMPtr<nsIPropertyBag> mCreationProperties;
218 
222  nsCOMPtr<sbIDeviceProperties> mProperties;
223 
227  nsCOMPtr<sbIDeviceContent> mDeviceContent;
228 
232  nsString mDeviceLibraryPath;
233 
237  nsCOMPtr<sbITranscodeProfile> mTranscodeProfile;
238  nsString mTranscodeBitrateStr;
239 
243  PRBool mPrefAutoEject;
244  PRBool mPrefNotifySound;
245 
246  /* Initialize request handler */
247  void InitRequestHandler();
248 
252  virtual nsresult DeviceSpecificDisconnect();
253 
257  nsresult InitializeProperties();
258 
262  nsresult CapabilitiesReset();
263 
267  nsresult CreateDeviceID(nsID* aDeviceID);
268 
276  nsresult Mount(sbBaseDeviceVolume* aVolume);
277 
285  nsresult Unmount(sbBaseDeviceVolume* aVolume);
286 
290  virtual nsresult ProcessBatch(Batch & aBatch);
291 
300  nsresult ReqHandleMount(TransferRequest* aRequest);
301 
309  nsresult UpdateDeviceLibrary(sbIDeviceLibrary* aLibrary);
310 
314  nsresult GetMediaFiles(nsIArray ** aURIList);
315 
319  nsresult GetMediaProperties(nsIArray ** aPropertyList);
320 
325  nsresult AttemptCDLookup();
326 
332  nsresult CompleteCDLookup(sbIJobProgress *aJob);
333 
338  nsresult ReqHandleUpdate(TransferRequest * aRequest);
339 
343  void ProxyCDLookup();
344 
354  nsresult ShowMetadataLookupDialog(const char *aLookupDialogURI,
355  nsISimpleEnumerator *aLookupResultsEnum,
356  PRBool aShouldReportEvents);
357 
363  nsresult HandleRipEnd();
364 
368  void ProxyHandleRipEnd();
369 
374  nsresult QueryUserViewErrors();
375 
379  void ProxyQueryUserViewErrors();
380 
387  nsresult GetCDDiscHash(sbICDDevice* aCDDevice,
388  nsAString& aCDDiscHash);
389 
390  /* Override base class to get all profiles, not just those we can write to
391  * the CD (i.e. none) */
392  nsresult GetSupportedTranscodeProfiles(PRUint32 aType,
393  nsIArray **aSupportedProfiles);
394 
395  /* Override base class to avoid popping up read-only dialog box */
396  nsresult CheckAccess(sbIDeviceLibrary* aDevLib);
397 
402  nsresult GenerateFilename(sbIMediaItem *aItem,
403  nsACString & aOutFilename);
404 
409  nsresult ReqHandleRead(TransferRequest * aRequest, PRUint32 aBatchCount);
410 
414  nsresult GetBitrateFromProfile(PRUint32 * bitrate);
415 };
416 
417 #define SB_CD_DEVICE_AUTO_INVOKE(aName, aMethod) \
418  SB_AUTO_NULL_CLASS(aName, sbCDDevice*, mValue->aMethod)
419 
420 #endif /* SBCDDEVICE_H_ */
Generic interface for exposing long running jobs to the UI.
[UNIMPLEMENTED UNTIL AFTER 0.3]
virtual ~sbCDDevice()
Definition: sbCDDevice.cpp:99
virtual nsresult InitDevice()
Definition: sbCDDevice.cpp:169
Implemented to receive notifications from sbIJobProgress interfaces.
static nsresult New(const nsID &aControllerId, nsIPropertyBag *aProperties, sbCDDevice **aOutCDDevice)
Definition: sbCDDevice.cpp:259
Interface that defines a single item of media in the system.
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICE NS_DECL_SBIJOBPROGRESSLISTENER NS_DECL_NSICLASSINFO sbCDDevice(const nsID &aControllerId, nsIPropertyBag *aProperties)
Definition: sbCDDevice.cpp:83
virtual PRBool IsRequestAborted()
Definition: sbCDDevice.cpp:979