DeviceManager.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://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 
32 #ifndef __SB_DEVICEMANAGER_H__
33 #define __SB_DEVICEMANAGER_H__
34 
35 #include "sbIDeviceManager.h"
36 
37 #include <nsCOMArray.h>
38 #include <nsIObserver.h>
39 #include <nsStringGlue.h>
40 #include <prlock.h>
41 
42 // DEFINES ====================================================================
43 #define SONGBIRD_OBSOLETE_DEVICEMANAGER_DESCRIPTION \
44  "Songbird Obsolete DeviceManager Service"
45 #define SONGBIRD_OBSOLETE_DEVICEMANAGER_CONTRACTID \
46  "@songbirdnest.com/Songbird/DeviceManager;1"
47 #define SONGBIRD_OBSOLETE_DEVICEMANAGER_CLASSNAME \
48  "Songbird Obsolete Device Manager"
49 #define SONGBIRD_OBSOLETE_DEVICEMANAGER_CID \
50 { /* d0b017c4-f388-4e78-abf3-5f48ca616a94 */ \
51  0xd0b017c4, \
52  0xf388, \
53  0x4e78, \
54  { 0xab, 0xf3, 0x5f, 0x48, 0xca, 0x61, 0x6a, 0x94 } \
55 }
56 // CLASSES ====================================================================
57 
59 {
60 public:
62  NS_DECL_NSIOBSERVER
63  NS_DECL_SBIDEVICEMANAGER
64 
66 
67  // Initializes the service. This will fail if we have already been
68  // initialized, even thought that should never happen with getService.
69  NS_IMETHOD Initialize();
70 
71 private:
72  ~sbDeviceManagerObsolete();
73 
74  // Iterate through the registered contractIDs looking for supported devices.
75  NS_IMETHOD LoadSupportedDevices();
76 
77  // Finalizes the service and informs all devices that they need to quit.
78  NS_IMETHOD Finalize();
79 
80  // A helper function to handle has/get device requests
81  NS_IMETHOD GetIndexForCategory(const nsAString& aCategory,
82  PRUint32* _retval);
83 
84  // This is a simple static to make sure that we aren't initialized more than
85  // once. Consumers should use getService instead of createInstance, but we do
86  // this just in case they forget.
87  static PRBool sServiceInitialized;
88 
89  // Set after our LoadSupportedDevices has been called.
90  static PRBool sDevicesLoaded;
91 
92  // This is a sanity check to make sure that we're finalizing properly
93  static PRBool sServiceFinalized;
94 
95  // The lock that protects mSupportedDevices
96  PRLock* mLock;
97 
98  // An array of the supported devices that have been initialized.
99  nsCOMArray<sbIDeviceBase> mSupportedDevices;
100 
101  // Variables that are set to optimize for the case when consumers call
102  // hasDeviceForCategory immediately followed by getDeviceForCategory.
103  PRUint32 mLastRequestedIndex;
104  nsString mLastRequestedCategory;
105 };
106 
107 #endif /* __SB_DEVICEMANAGER_H__ */
NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER NS_DECL_SBIDEVICEMANAGER sbDeviceManagerObsolete()