sbDeviceFirmwareUpdater.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-2010 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 __SB_DEVICEFIRMWAREUPDATER_H__
26 #define __SB_DEVICEFIRMWAREUPDATER_H__
27 
28 #include <sbIDeviceFirmwareUpdater.h>
29 
30 #include <nsIEventTarget.h>
31 #include <nsIObserver.h>
32 #include <nsIRunnable.h>
33 
34 #include <sbIDeviceEventListener.h>
35 #include <sbIDeviceFirmwareHandler.h>
36 #include <sbIDeviceFirmwareUpdate.h>
37 #include <sbIFileDownloader.h>
38 
39 #include <nsClassHashtable.h>
40 #include <nsCOMPtr.h>
41 #include <nsHashKeys.h>
42 #include <nsInterfaceHashtable.h>
43 #include <nsStringGlue.h>
44 #include <nsTArray.h>
45 #include <prmon.h>
46 
49 
52  public nsIObserver
53 {
54 public:
56  NS_DECL_NSIOBSERVER
57  NS_DECL_SBIDEVICEFIRMWAREUPDATER
58  NS_DECL_SBIDEVICEEVENTLISTENER
59 
61 
62  nsresult Init();
63  nsresult Shutdown();
64 
65  already_AddRefed<sbIDeviceFirmwareHandler>
66  GetRunningHandler(sbIDevice *aDevice);
67 
68  already_AddRefed<sbIDeviceFirmwareHandler>
69  GetRunningHandler(sbIDevice *aDevice,
70  PRUint32 aVendorID,
71  PRUint32 aProductID,
72  sbIDeviceEventListener *aListener,
73  PRBool aCreate);
74 
75  nsresult PutRunningHandler(sbIDevice *aDevice,
76  sbIDeviceFirmwareHandler *aHandler);
77 
80 
81  nsresult RequiresRecoveryMode(sbIDevice *aDevice,
82  sbIDeviceFirmwareHandler *aHandler);
83 
84  nsresult GetCachedFirmwareUpdate(sbIDevice *aDevice,
85  sbIDeviceFirmwareUpdate **aUpdate);
86 
87 private:
88  virtual ~sbDeviceFirmwareUpdater();
89 
90 protected:
91  template<class T>
92  static NS_HIDDEN_(PLDHashOperator)
93  EnumerateIntoArrayISupportsKey(nsISupports *aKey,
94  T* aData,
95  void* aArray);
96 
97 protected:
98  PRMonitor* mMonitor;
99  PRPackedBool mIsShutdown;
100 
101  typedef nsTArray<nsCString> firmwarehandlers_t;
103 
104  typedef
105  nsInterfaceHashtableMT<nsISupportsHashKey,
107  typedef
108  nsClassHashtableMT<nsISupportsHashKey,
110  typedef
111  nsInterfaceHashtableMT<nsISupportsHashKey,
113 
114  /* Hash table of sbIDevice -> sbIDeviceFirmwareHandler for firmware update
115  processes in progress */
117  /* Hash table of sbIDevice -> sbIDeviceFirmwareHandler
118  for device instances where we expect to resume firmware
119  updating later. Here, the sbIDevice key is the original device (not the
120  recovery mode device instance) */
122  /* Hash table of sbIDeviceFirmwareHandler -> sbIDeviceFirmwareHandlerStatus */
124  /* Hash table of sbIDevice -> sbIFileDownloaderListener */
126 
127  nsCOMPtr<nsIEventTarget> mThreadPool;
128 };
129 
131 {
132 public:
133  typedef enum {
138  } handlerstatus_t;
139 
140  typedef enum {
141  OP_NONE = 0,
147 
150 
151  nsresult Init();
152 
153  nsresult GetOperation(handleroperation_t *aOperation);
154  nsresult SetOperation(handleroperation_t aOperation);
155 
156  nsresult GetStatus(handlerstatus_t *aStatus);
157  nsresult SetStatus(handlerstatus_t aStatus);
158 
159 private:
160  PRMonitor* mMonitor;
161 
162  handleroperation_t mOperation;
163  handlerstatus_t mStatus;
164 };
165 
166 class sbDeviceFirmwareUpdaterRunner : public nsIRunnable
167 {
168 public:
170  NS_DECL_NSIRUNNABLE
171 
173 
174  nsresult Init(sbIDevice *aDevice,
175  sbIDeviceFirmwareUpdate *aUpdate,
176  sbIDeviceFirmwareHandler *aHandler,
177  PRBool aRecovery = PR_FALSE);
178 
179 private:
180  virtual ~sbDeviceFirmwareUpdaterRunner();
181 
182 protected:
183  nsCOMPtr<sbIDevice> mDevice;
184  nsCOMPtr<sbIDeviceFirmwareUpdate> mFirmwareUpdate;
185  nsCOMPtr<sbIDeviceFirmwareHandler> mHandler;
186 
187  PRPackedBool mRecovery;
188 };
189 
190 #define SB_DEVICEFIRMWAREUPDATER_DESCRIPTION \
191  "Songbird Device Firmware Updater"
192 #define SB_DEVICEFIRMWAREUPDATER_CONTRACTID \
193  "@songbirdnest.com/Songbird/Device/Firmware/Updater;1"
194 #define SB_DEVICEFIRMWAREUPDATER_CLASSNAME \
195  "Songbird Device Firmware Updater"
196 #define SB_DEVICEFIRMWAREUPDATER_CID \
197 { /* {9a84d24f-b02b-42bc-a2cb-b4792023aa70} */ \
198  0x9a84d24f, 0xb02b, 0x42bc, \
199  { 0xa2, 0xcb, 0xb4, 0x79, 0x20, 0x23, 0xaa, 0x70 } }
200 
201 #endif /*__SB_DEVICEFIRMWAREUPDATER_H__*/
nsInterfaceHashtableMT< nsISupportsHashKey, sbIFileDownloaderListener > downloaders_t
nsresult GetOperation(handleroperation_t *aOperation)
nsClassHashtableMT< nsISupportsHashKey, sbDeviceFirmwareHandlerStatus > handlerstatus_t
nsCOMPtr< nsIEventTarget > mThreadPool
nsresult RequiresRecoveryMode(sbIDevice *aDevice, sbIDeviceFirmwareHandler *aHandler)
NS_DECL_ISUPPORTS NS_DECL_NSIRUNNABLE sbDeviceFirmwareUpdaterRunner()
nsInterfaceHashtableMT< nsISupportsHashKey, sbIDeviceFirmwareHandler > runninghandlers_t
nsresult PutRunningHandler(sbIDevice *aDevice, sbIDeviceFirmwareHandler *aHandler)
nsCOMPtr< sbIDeviceFirmwareHandler > mHandler
nsresult Init(sbIDevice *aDevice, sbIDeviceFirmwareUpdate *aUpdate, sbIDeviceFirmwareHandler *aHandler, PRBool aRecovery=PR_FALSE)
NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER NS_DECL_SBIDEVICEFIRMWAREUPDATER NS_DECL_SBIDEVICEEVENTLISTENER sbDeviceFirmwareUpdater()
static NS_HIDDEN_(PLDHashOperator) EnumerateIntoArrayISupportsKey(nsISupports *aKey
nsresult SetStatus(handlerstatus_t aStatus)
nsresult GetStatus(handlerstatus_t *aStatus)
nsCOMPtr< sbIDeviceFirmwareUpdate > mFirmwareUpdate
runninghandlers_t mRecoveryModeHandlers
nsresult SetOperation(handleroperation_t aOperation)
nsTArray< nsCString > firmwarehandlers_t
nsresult GetCachedFirmwareUpdate(sbIDevice *aDevice, sbIDeviceFirmwareUpdate **aUpdate)
already_AddRefed< sbIDeviceFirmwareHandler > GetRunningHandler(sbIDevice *aDevice)
sbDeviceFirmwareHandlerStatus * GetHandlerStatus(sbIDeviceFirmwareHandler *aHandler)
firmwarehandlers_t mFirmwareHandlers