sbBaseDeviceFirmwareHandler.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_BASEDEVICEFIRMWAREHANDLER_H__
26 #define __SB_BASEDEVICEFIRMWAREHANDLER_H__
27 
28 #include <sbIDeviceFirmwareHandler.h>
29 
30 #include <nsIMutableArray.h>
31 #include <nsITimer.h>
32 #include <nsIURI.h>
33 #include <nsIXMLHttpRequest.h>
34 
35 #include <nsCOMPtr.h>
36 #include <nsStringGlue.h>
37 #include <prmon.h>
38 
39 #include <sbIDevice.h>
40 #include <sbIDeviceEvent.h>
41 #include <sbIDeviceEventListener.h>
42 #include <sbIDeviceManager.h>
43 
45  public nsITimerCallback
46 {
47 public:
49  NS_DECL_NSITIMERCALLBACK
50  NS_DECL_SBIDEVICEFIRMWAREHANDLER
51 
52  typedef enum {
58 
60 
61  nsresult Init();
62 
66  nsresult AppendSupportedDevice(const nsAString &aDeviceFriendlyName,
67  const PRUint32 aDeviceVendorID,
68  const PRUint32 aDeviceProductID);
69 
70  nsresult AppendSupportedDeviceProductID(const nsAString &aDeviceFriendlyName,
71  const PRUint32 aDeviceProductID);
72 
79  nsresult CreateProxiedURI(const nsACString &aURISpec,
80  nsIURI **aURI);
81 
99  nsresult SendHttpRequest(const nsACString &aMethod,
100  const nsACString &aUrl,
101  const nsAString &aUsername = EmptyString(),
102  const nsAString &aPassword = EmptyString(),
103  const nsACString &aContentType = EmptyCString(),
104  nsIVariant *aRequestBody = nsnull);
105 
106 
110  nsresult AbortHttpRequest();
111 
115  nsresult CreateDeviceEvent(PRUint32 aType,
116  nsIVariant *aData,
117  sbIDeviceEvent **aEvent);
118 
122  nsresult SendDeviceEvent(sbIDeviceEvent *aEvent, PRBool aAsync = PR_TRUE);
123 
127  nsresult SendDeviceEvent(PRUint32 aType,
128  nsIVariant *aData,
129  PRBool aAsync = PR_TRUE);
130 
135 
139  nsresult SetState(handlerstate_t aState);
140 
148  nsresult CheckForError(const nsresult &aResult,
149  PRUint32 aEventType,
150  nsIVariant *aData = nsnull);
151 
152  // override me, see cpp file for implementation notes
153  virtual nsresult OnInit();
154 
155  // override me, see cpp file for implementation notes
156  virtual nsresult OnGetCurrentFirmwareVersion(PRUint32 *aCurrentFirmwareVersion);
157  // override me, see cpp file for implementation notes
158  virtual nsresult OnGetCurrentFirmwareReadableVersion(nsAString &aCurrentFirmwareReadableVersion);
159  // override me, see cpp file for implementation notes
160  virtual nsresult OnGetRecoveryMode(PRBool *aRecoveryMode);
161 
162  // override me, see cpp file for implementation notes
163  virtual nsresult OnGetDeviceModelNumber(nsAString &aModelNumber);
164  // override me, see cpp file for implementation notes
165  virtual nsresult OnGetDeviceModelVersion(nsAString &aModelVersion);
166  // override me, see cpp file for implementation notes
167  virtual nsresult OnGetDeviceVendor(nsAString &aDeviceVendor);
168 
169  // override me, see cpp file for implementation notes
170  virtual nsresult OnGetSupportedDevices(nsISimpleEnumerator **aSupportedDevices);
171 
172  // override me, see cpp file for implementation notes
173  virtual nsresult OnCanUpdate(sbIDevice *aDevice,
174  PRUint32 aDeviceVendorID,
175  PRUint32 aDeviceProductID,
176  PRBool *_retval);
177  // override me, see cpp file for implementation notes
178  virtual nsresult OnBeginRecoveryModeSwitch(PRUint32 aDeviceVendorID,
179  PRUint32 aDeviceProductID);
180  // override me, see cpp file for implementation notes
181  virtual nsresult OnEndRecoveryModeSwitch();
182  // override me, see cpp file for implementation notes
183  virtual nsresult OnRebind(sbIDevice *aDevice,
184  sbIDeviceEventListener *aListener,
185  PRBool *_retval);
186  // override me, see cpp file for implementation notes
187  virtual nsresult OnCancel();
188  // override me, see cpp file for implementation notes
189  virtual nsresult OnRefreshInfo();
190  // override me, see cpp file for implementation notes
191  virtual nsresult OnUpdate(sbIDeviceFirmwareUpdate *aFirmwareUpdate);
192  // override me, see cpp file for implementation notes
193  virtual nsresult OnRecover(sbIDeviceFirmwareUpdate *aFirmwareUpdate);
194  // override me, see cpp file for implementation notes
195  virtual nsresult OnVerifyDevice();
196  // override me, see cpp file for implementation notes
197  virtual nsresult OnVerifyUpdate(sbIDeviceFirmwareUpdate *aFirmwareUpdate);
198  // override me, see cpp file for implementation notes
199  virtual nsresult OnHttpRequestCompleted();
200 
201 protected:
203 
204  PRMonitor* mMonitor;
205 
206  nsCOMPtr<sbIDevice> mDevice;
207  nsCOMPtr<sbIDeviceEventListener> mListener;
208  nsCOMPtr<sbIDeviceEventListener> mProxiedListener;
209 
213 
214  nsString mContractId;
217 
218  nsCOMPtr<nsIURI> mDefaultFirmwareLocation;
219  nsCOMPtr<nsIURI> mFirmwareLocation;
221  nsCOMPtr<nsIURI> mReleaseNotesLocation;
222  nsCOMPtr<nsIURI> mResetInstructionsLocation;
224  nsCOMPtr<nsIURI> mSupportLocation;
225  nsCOMPtr<nsIURI> mRegisterLocation;
226 
227  PRPackedBool mNeedsRecoveryMode;
228  PRPackedBool mRecoveryMode;
229 
230  nsCOMPtr<nsIXMLHttpRequest> mXMLHttpRequest;
231  nsCOMPtr<nsITimer> mXMLHttpRequestTimer;
232 
233  nsCOMPtr<nsIMutableArray> mSupportedDevices;
234 };
235 
236 #endif /*__SB_BASEDEVICEFIRMWAREHANDLER_H__*/
virtual nsresult OnCanUpdate(sbIDevice *aDevice, PRUint32 aDeviceVendorID, PRUint32 aDeviceProductID, PRBool *_retval)
virtual nsresult OnBeginRecoveryModeSwitch(PRUint32 aDeviceVendorID, PRUint32 aDeviceProductID)
nsresult AppendSupportedDeviceProductID(const nsAString &aDeviceFriendlyName, const PRUint32 aDeviceProductID)
nsCOMPtr< sbIDeviceEventListener > mProxiedListener
nsresult SetState(handlerstate_t aState)
Get internal state.
virtual nsresult OnRebind(sbIDevice *aDevice, sbIDeviceEventListener *aListener, PRBool *_retval)
nsresult CheckForError(const nsresult &aResult, PRUint32 aEventType, nsIVariant *aData=nsnull)
Check nsresult value, send error event if nsresult value is an error.
virtual nsresult OnGetCurrentFirmwareVersion(PRUint32 *aCurrentFirmwareVersion)
virtual nsresult OnGetRecoveryMode(PRBool *aRecoveryMode)
handlerstate_t GetState()
Set internal state.
nsresult AbortHttpRequest()
Abort an HTTP request.
nsresult SendDeviceEvent(sbIDeviceEvent *aEvent, PRBool aAsync=PR_TRUE)
Send a device event.
virtual nsresult OnGetDeviceVendor(nsAString &aDeviceVendor)
nsresult AppendSupportedDevice(const nsAString &aDeviceFriendlyName, const PRUint32 aDeviceVendorID, const PRUint32 aDeviceProductID)
Append an entry to the list of supported devices.
nsCOMPtr< nsIXMLHttpRequest > mXMLHttpRequest
virtual nsresult OnGetDeviceModelVersion(nsAString &aModelVersion)
virtual nsresult OnVerifyUpdate(sbIDeviceFirmwareUpdate *aFirmwareUpdate)
nsCOMPtr< nsIMutableArray > mSupportedDevices
virtual nsresult OnGetSupportedDevices(nsISimpleEnumerator **aSupportedDevices)
virtual nsresult OnRecover(sbIDeviceFirmwareUpdate *aFirmwareUpdate)
nsresult CreateDeviceEvent(PRUint32 aType, nsIVariant *aData, sbIDeviceEvent **aEvent)
Create a device event.
nsresult CreateProxiedURI(const nsACString &aURISpec, nsIURI **aURI)
Create an nsIURI from a spec string (e.g. http://some.url.com/path) in a thread-safe manner...
virtual nsresult OnGetCurrentFirmwareReadableVersion(nsAString &aCurrentFirmwareReadableVersion)
nsCOMPtr< sbIDeviceEventListener > mListener
virtual nsresult OnGetDeviceModelNumber(nsAString &aModelNumber)
virtual nsresult OnUpdate(sbIDeviceFirmwareUpdate *aFirmwareUpdate)
restoreWindow aState
nsITimerCallback
nsresult SendHttpRequest(const nsACString &aMethod, const nsACString &aUrl, const nsAString &aUsername=EmptyString(), const nsAString &aPassword=EmptyString(), const nsACString &aContentType=EmptyCString(), nsIVariant *aRequestBody=nsnull)
Send an HTTP request.
_updateTextAndScrollDataForFrame aData