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 #include <sbDebugUtils.h>
50 
51 // Mozilla imports.
52 #include <nsAutoPtr.h>
53 #include <nsIClassInfoImpl.h>
54 #include <nsIGenericFactory.h>
55 #include <nsIProgrammingLanguage.h>
56 #include <nsIPropertyBag.h>
57 #include <nsIVariant.h>
58 #include <nsIWritablePropertyBag.h>
59 #include <nsMemory.h>
60 #include <nsServiceManagerUtils.h>
61 
62 
63 //------------------------------------------------------------------------------
64 //
65 // iPod device controller component module implementation.
66 //
67 //------------------------------------------------------------------------------
68 
71 
72 
73 //------------------------------------------------------------------------------
74 //
75 // iPod device controller nsISupports and nsIClassInfo implementation.
76 //
77 //------------------------------------------------------------------------------
78 
79 // nsISupports implementation.
80 // NS_IMPL_THREADSAFE_ISUPPORTS1_CI(sbIPDController, sbIDeviceController)
83 NS_IMPL_QUERY_INTERFACE1_CI(sbIPDController, sbIDeviceController)
85 
86 // nsIClassInfo implementation.
87 NS_IMPL_THREADSAFE_CI(sbIPDController)
88 
89 
90 //------------------------------------------------------------------------------
91 //
92 // iPod device controller sbIDeviceController implementation.
93 //
94 //------------------------------------------------------------------------------
95 
101 NS_IMETHODIMP
102 sbIPDController::GetCompatibility(nsIPropertyBag* aParams,
103  sbIDeviceCompatibility** _retval)
104 {
105  // Validate parameters.
106  NS_ENSURE_ARG_POINTER(aParams);
107  NS_ENSURE_ARG_POINTER(_retval);
108 
109  // Function variables.
110  nsresult rv;
111 
112  // Create the device compatibility object.
113  nsRefPtr<sbDeviceCompatibility> deviceCompatibility;
114  NS_NEWXPCOM(deviceCompatibility, sbDeviceCompatibility);
115  NS_ENSURE_TRUE(deviceCompatibility, NS_ERROR_OUT_OF_MEMORY);
116 
117  // Get the device type.
118  nsCOMPtr<nsIVariant> property;
119  nsAutoString deviceType;
120  rv = aParams->GetProperty(NS_LITERAL_STRING("DeviceType"),
121  getter_AddRefs(property));
122  NS_ENSURE_SUCCESS(rv, rv);
123  rv = property->GetAsAString(deviceType);
124  NS_ENSURE_SUCCESS(rv, rv);
125 
126  // Set up the device compatibility.
127  if (deviceType.EqualsLiteral("iPod")) {
128  rv = deviceCompatibility->Init
131  } else {
132  rv = deviceCompatibility->Init
135  }
136  NS_ENSURE_SUCCESS(rv, rv);
137 
138  // Return results.
139  NS_ADDREF(*_retval = deviceCompatibility);
140 
141  return NS_OK;
142 }
143 
144 
149 NS_IMETHODIMP
150 sbIPDController::CreateDevice(nsIPropertyBag* aParams,
151  sbIDevice** _retval)
152 {
153  // Validate parameters.
154  NS_ENSURE_ARG_POINTER(aParams);
155  NS_ENSURE_ARG_POINTER(_retval);
156 
157  // Function variables.
158  nsresult rv;
159 
160  LOG("sbIPDController::CreateDevice");
161 
162  // Get the controller ID.
163  nsID controllerID;
164  rv = GetControllerIdInternal(controllerID);
165  NS_ENSURE_SUCCESS(rv, rv);
166 
167  // Create the device object.
168  nsRefPtr<sbIPDSysDevice> device = new sbIPDSysDevice(controllerID, aParams);
169  NS_ENSURE_TRUE(device, NS_ERROR_OUT_OF_MEMORY);
170  rv = device->Initialize();
171  NS_ENSURE_SUCCESS(rv, rv);
172 
173  // Add the device to the list of controlled devices.
174  rv = AddDeviceInternal(device);
175  NS_ENSURE_SUCCESS(rv, rv);
176 
177  // Return results.
178  NS_ADDREF(*_retval = device);
179 
180  return NS_OK;
181 }
182 
183 
188 NS_IMETHODIMP
189 sbIPDController::ControlsDevice(sbIDevice* aDevice,
190  PRBool* _retval)
191 {
192  return ControlsDeviceInternal(aDevice, _retval);
193 }
194 
195 
200 NS_IMETHODIMP
201 sbIPDController::ConnectDevices()
202 {
203  return ConnectDevicesInternal();
204 }
205 
206 
211 NS_IMETHODIMP
212 sbIPDController::DisconnectDevices()
213 {
214  return DisconnectDevicesInternal();
215 }
216 
217 
222 NS_IMETHODIMP
223 sbIPDController::ReleaseDevice(sbIDevice* aDevice)
224 {
225  return ReleaseDeviceInternal(aDevice);
226 }
227 
228 
233 NS_IMETHODIMP
234 sbIPDController::ReleaseDevices()
235 {
236  return ReleaseDevicesInternal();
237 }
238 
239 
240 //
241 // Getters/setters.
242 //
243 
248 NS_IMETHODIMP
249 sbIPDController::GetId(nsID** aId)
250 {
251  // Validate parameters.
252  NS_ENSURE_ARG_POINTER(aId);
253 
254  // Function variables.
255  nsresult rv;
256 
257  // Allocate an nsID and set it up for auto-disposal.
258  nsID* pId = static_cast<nsID*>(NS_Alloc(sizeof(nsID)));
259  NS_ENSURE_TRUE(pId, NS_ERROR_OUT_OF_MEMORY);
260  sbAutoNSMemPtr autoPId(pId);
261 
262  // Get the controller ID.
263  rv = GetControllerIdInternal(*pId);
264  NS_ENSURE_SUCCESS(rv, rv);
265 
266  // Return results.
267  *aId = static_cast<nsID*>(autoPId.forget());
268 
269  return NS_OK;
270 }
271 
272 
277 NS_IMETHODIMP
278 sbIPDController::GetName(nsAString& aName)
279 {
280  return GetControllerNameInternal(aName);
281 }
282 
283 
289 NS_IMETHODIMP
290 sbIPDController::GetMarshallId(nsID** aId)
291 {
292  // Validate parameters.
293  NS_ENSURE_ARG_POINTER(aId);
294 
295  // Function variables.
296  nsresult rv;
297 
298  // Allocate an nsID and set it up for auto-disposal.
299  nsID* pId = static_cast<nsID*>(NS_Alloc(sizeof(nsID)));
300  NS_ENSURE_TRUE(pId, NS_ERROR_OUT_OF_MEMORY);
301  sbAutoNSMemPtr autoPId(pId);
302 
303  // Get the controller ID.
304  rv = GetMarshallIdInternal(*pId);
305  NS_ENSURE_SUCCESS(rv, rv);
306 
307  // Return results.
308  *aId = static_cast<nsID*>(autoPId.forget());
309 
310  return NS_OK;
311 }
312 
313 
320 NS_IMETHODIMP
321 sbIPDController::GetDevices(nsIArray** aDevices)
322 {
323  return GetDevicesInternal(aDevices);
324 }
325 
326 
327 //------------------------------------------------------------------------------
328 //
329 // iPod device controller public services.
330 //
331 //------------------------------------------------------------------------------
332 
338 {
339  nsresult rv;
340 
342 
343  // Initialize the logging services.
345 
346  // Set the controller ID.
347  static nsID const controllerID = SB_IPDCONTROLLER_CID;
348  rv = SetControllerIdInternal(controllerID);
349  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set controller ID.");
350 
351  // Set the marshall ID.
352  static nsID const marshallID = SB_IPDMARSHALL_CID;
353  rv = SetMarshallIdInternal(marshallID);
354  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set marshall ID.");
355 
356  // Set the controller name.
357  rv = SetControllerNameInternal(NS_LITERAL_STRING(SB_IPDCONTROLLER_CLASSNAME));
358  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set controller name.");
359 }
360 
361 
367 {
368 }
369 
370 
#define SB_PRLOG_SETUP(x)
Definition: sbDebugUtils.h:115
return NS_OK
#define LOG(args)
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