sbIPDController.cpp
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-2009 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 
32 //------------------------------------------------------------------------------
33 //
34 // iPod device controller imported services.
35 //
36 //------------------------------------------------------------------------------
37 
38 // Self imports.
39 #include "sbIPDController.h"
40 
41 // Local imports.
42 #include "sbIPDLog.h"
43 #include "sbIPDMarshall.h"
44 #include "sbIPDSysDevice.h"
45 #include "sbIPDUtils.h"
46 
47 // Songbird imports.
48 #include <sbDeviceCompatibility.h>
49 
50 // Mozilla imports.
51 #include <nsAutoPtr.h>
52 #include <nsIClassInfoImpl.h>
53 #include <nsIGenericFactory.h>
54 #include <nsIProgrammingLanguage.h>
55 #include <nsIPropertyBag.h>
56 #include <nsIVariant.h>
57 #include <nsIWritablePropertyBag.h>
58 #include <nsMemory.h>
59 #include <nsServiceManagerUtils.h>
60 
61 
62 //------------------------------------------------------------------------------
63 //
64 // iPod device controller component module implementation.
65 //
66 //------------------------------------------------------------------------------
67 
70 
71 
72 //------------------------------------------------------------------------------
73 //
74 // iPod device controller nsISupports and nsIClassInfo implementation.
75 //
76 //------------------------------------------------------------------------------
77 
78 // nsISupports implementation.
79 // NS_IMPL_THREADSAFE_ISUPPORTS1_CI(sbIPDController, sbIDeviceController)
82 NS_IMPL_QUERY_INTERFACE1_CI(sbIPDController, sbIDeviceController)
84 
85 // nsIClassInfo implementation.
86 NS_IMPL_THREADSAFE_CI(sbIPDController)
87 
88 
89 //------------------------------------------------------------------------------
90 //
91 // iPod device controller sbIDeviceController implementation.
92 //
93 //------------------------------------------------------------------------------
94 
100 NS_IMETHODIMP
101 sbIPDController::GetCompatibility(nsIPropertyBag* aParams,
102  sbIDeviceCompatibility** _retval)
103 {
104  // Validate parameters.
105  NS_ENSURE_ARG_POINTER(aParams);
106  NS_ENSURE_ARG_POINTER(_retval);
107 
108  // Function variables.
109  nsresult rv;
110 
111  // Create the device compatibility object.
112  nsRefPtr<sbDeviceCompatibility> deviceCompatibility;
113  NS_NEWXPCOM(deviceCompatibility, sbDeviceCompatibility);
114  NS_ENSURE_TRUE(deviceCompatibility, NS_ERROR_OUT_OF_MEMORY);
115 
116  // Get the device type.
117  nsCOMPtr<nsIVariant> property;
118  nsAutoString deviceType;
119  rv = aParams->GetProperty(NS_LITERAL_STRING("DeviceType"),
120  getter_AddRefs(property));
121  NS_ENSURE_SUCCESS(rv, rv);
122  rv = property->GetAsAString(deviceType);
123  NS_ENSURE_SUCCESS(rv, rv);
124 
125  // Set up the device compatibility.
126  if (deviceType.EqualsLiteral("iPod")) {
127  rv = deviceCompatibility->Init
130  } else {
131  rv = deviceCompatibility->Init
134  }
135  NS_ENSURE_SUCCESS(rv, rv);
136 
137  // Return results.
138  NS_ADDREF(*_retval = deviceCompatibility);
139 
140  return NS_OK;
141 }
142 
143 
148 NS_IMETHODIMP
149 sbIPDController::CreateDevice(nsIPropertyBag* aParams,
150  sbIDevice** _retval)
151 {
152  // Validate parameters.
153  NS_ENSURE_ARG_POINTER(aParams);
154  NS_ENSURE_ARG_POINTER(_retval);
155 
156  // Function variables.
157  nsresult rv;
158 
159  // Get the controller ID.
160  nsID controllerID;
161  rv = GetControllerIdInternal(controllerID);
162  NS_ENSURE_SUCCESS(rv, rv);
163 
164  // Create and initialize the device object.
165  nsRefPtr<sbIPDSysDevice> device = new sbIPDSysDevice(controllerID, aParams);
166  NS_ENSURE_TRUE(device, NS_ERROR_OUT_OF_MEMORY);
167  rv = device->Initialize();
168  NS_ENSURE_SUCCESS(rv, rv);
169 
170  // Add the device to the list of controlled devices.
171  rv = AddDeviceInternal(device);
172  NS_ENSURE_SUCCESS(rv, rv);
173 
174  // Return results.
175  NS_ADDREF(*_retval = device);
176 
177  return NS_OK;
178 }
179 
180 
185 NS_IMETHODIMP
186 sbIPDController::ControlsDevice(sbIDevice* aDevice,
187  PRBool* _retval)
188 {
189  return ControlsDeviceInternal(aDevice, _retval);
190 }
191 
192 
197 NS_IMETHODIMP
198 sbIPDController::ConnectDevices()
199 {
200  return ConnectDevicesInternal();
201 }
202 
203 
208 NS_IMETHODIMP
209 sbIPDController::DisconnectDevices()
210 {
211  return DisconnectDevicesInternal();
212 }
213 
214 
219 NS_IMETHODIMP
220 sbIPDController::ReleaseDevice(sbIDevice* aDevice)
221 {
222  return ReleaseDeviceInternal(aDevice);
223 }
224 
225 
230 NS_IMETHODIMP
231 sbIPDController::ReleaseDevices()
232 {
233  return ReleaseDevicesInternal();
234 }
235 
236 
237 //
238 // Getters/setters.
239 //
240 
245 NS_IMETHODIMP
246 sbIPDController::GetId(nsID** aId)
247 {
248  // Validate parameters.
249  NS_ENSURE_ARG_POINTER(aId);
250 
251  // Function variables.
252  nsresult rv;
253 
254  // Allocate an nsID and set it up for auto-disposal.
255  nsID* pId = static_cast<nsID*>(NS_Alloc(sizeof(nsID)));
256  NS_ENSURE_TRUE(pId, NS_ERROR_OUT_OF_MEMORY);
257  sbAutoNSMemPtr autoPId(pId);
258 
259  // Get the controller ID.
260  rv = GetControllerIdInternal(*pId);
261  NS_ENSURE_SUCCESS(rv, rv);
262 
263  // Return results.
264  *aId = static_cast<nsID*>(autoPId.forget());
265 
266  return NS_OK;
267 }
268 
269 
274 NS_IMETHODIMP
275 sbIPDController::GetName(nsAString& aName)
276 {
277  return GetControllerNameInternal(aName);
278 }
279 
280 
286 NS_IMETHODIMP
287 sbIPDController::GetMarshallId(nsID** aId)
288 {
289  // Validate parameters.
290  NS_ENSURE_ARG_POINTER(aId);
291 
292  // Function variables.
293  nsresult rv;
294 
295  // Allocate an nsID and set it up for auto-disposal.
296  nsID* pId = static_cast<nsID*>(NS_Alloc(sizeof(nsID)));
297  NS_ENSURE_TRUE(pId, NS_ERROR_OUT_OF_MEMORY);
298  sbAutoNSMemPtr autoPId(pId);
299 
300  // Get the controller ID.
301  rv = GetMarshallIdInternal(*pId);
302  NS_ENSURE_SUCCESS(rv, rv);
303 
304  // Return results.
305  *aId = static_cast<nsID*>(autoPId.forget());
306 
307  return NS_OK;
308 }
309 
310 
317 NS_IMETHODIMP
318 sbIPDController::GetDevices(nsIArray** aDevices)
319 {
320  return GetDevicesInternal(aDevices);
321 }
322 
323 
324 //------------------------------------------------------------------------------
325 //
326 // iPod device controller public services.
327 //
328 //------------------------------------------------------------------------------
329 
335 {
336  nsresult rv;
337 
338  // Initialize the logging services.
340 
341  // Set the controller ID.
342  static nsID const controllerID = SB_IPDCONTROLLER_CID;
343  rv = SetControllerIdInternal(controllerID);
344  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set controller ID.");
345 
346  // Set the marshall ID.
347  static nsID const marshallID = SB_IPDMARSHALL_CID;
348  rv = SetMarshallIdInternal(marshallID);
349  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set marshall ID.");
350 
351  // Set the controller name.
352  rv = SetControllerNameInternal(NS_LITERAL_STRING(SB_IPDCONTROLLER_CLASSNAME));
353  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set controller name.");
354 }
355 
356 
362 {
363 }
364 
365 
return NS_OK
Songbird iPod Device Utility Definitions.
nsresult ReleaseDeviceInternal(sbIDevice *aDevice)
nsresult GetMarshallIdInternal(nsID &aID)
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICECONTROLLER NS_DECL_NSICLASSINFO sbIPDController()
static void Initialize()
Definition: sbIPDLog.cpp:73
NS_IMPL_THREADSAFE_CI(sbMediaListEnumeratorWrapper)
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
virtual ~sbIPDController()
nsresult SetMarshallIdInternal(const nsID &aID)
[UNIMPLEMENTED UNTIL AFTER 0.3]
nsresult SetControllerNameInternal(const nsAString &aName)
const unsigned long PREFERENCE_SELECTED
nsresult GetControllerNameInternal(nsAString &aName)
Songbird iPod Device Logging Definitions.
[UNIMPLEMENTED UNTIL AFTER 0.3]
#define SB_IPDCONTROLLER_CONTRACTID
nsresult GetDevicesInternal(nsIArray **aDevices)
nsresult AddDeviceInternal(sbIDevice *aDevice)
nsresult GetControllerIdInternal(nsID &aID)
_updateCookies aName
const unsigned long COMPATIBLE_ENHANCED_SUPPORT
nsresult ControlsDeviceInternal(sbIDevice *aDevice, PRBool *_retval)
nsresult SetControllerIdInternal(const nsID &aID)
#define SB_IPDMARSHALL_CID
Definition: sbIPDMarshall.h:76
#define SB_IPDCONTROLLER_CID
const unsigned long PREFERENCE_UNKNOWN
SB_DEVICE_CONTROLLER_REGISTERSELF_IMPL(sbIPDController,"@songbirdnest.com/Songbird/IPDController;1") NS_IMETHODIMP sbIPDController
#define SB_IPDCONTROLLER_CLASSNAME
NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER1(CDatabaseQuery, sbIDatabaseQuery) CDatabaseQuery
const unsigned long INCOMPATIBLE