sbCDDeviceController.cpp
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-2009 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 
27 #include "sbCDDeviceController.h"
28 
29 #include "sbCDDevice.h"
30 #include "sbCDDeviceDefines.h"
31 
32 #include <sbDeviceCompatibility.h>
33 
34 #include <nsIClassInfoImpl.h>
35 #include <nsIGenericFactory.h>
36 #include <nsIProgrammingLanguage.h>
37 #include <nsMemory.h>
38 #include <nsServiceManagerUtils.h>
39 #include <nsIPropertyBag2.h>
40 
41 
44 
47 NS_IMPL_QUERY_INTERFACE1_CI(sbCDDeviceController, sbIDeviceController)
49 
50 // nsIClassInfo implementation.
51 NS_DECL_CLASSINFO(sbCDDeviceController)
52 NS_IMPL_THREADSAFE_CI(sbCDDeviceController)
53 
54 sbCDDeviceController::sbCDDeviceController()
55 {
56  static nsID const id = SB_CDDEVICE_CONTROLLER_CID;
57  nsresult rv = SetControllerIdInternal(id);
58  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set controller id");
59 
60  static nsID const marshallId = SB_CDDEVICE_MARSHALL_CID;
61  rv = SetMarshallIdInternal(marshallId);
62  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set controller id");
63 
64  rv = SetControllerNameInternal(NS_LITERAL_STRING("sbCDDeviceController"));
65  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set controller name");
66 }
67 
69 {
70 }
71 
72 //------------------------------------------------------------------------------
73 // sbIDeviceController
74 
75 NS_IMETHODIMP
76 sbCDDeviceController::GetCompatibility(nsIPropertyBag *aParams,
77  sbIDeviceCompatibility **aRetVal)
78 {
79  NS_ENSURE_ARG_POINTER(aParams);
80  NS_ENSURE_ARG_POINTER(aRetVal);
81 
82  nsresult rv;
83 
84  // Create the device compatibility object.
85  nsRefPtr<sbDeviceCompatibility> deviceCompatibility;
86  NS_NEWXPCOM(deviceCompatibility, sbDeviceCompatibility);
87  NS_ENSURE_TRUE(deviceCompatibility, NS_ERROR_OUT_OF_MEMORY);
88 
89  // Get the device type.
90  nsCOMPtr<nsIVariant> property;
91  rv = aParams->GetProperty(NS_LITERAL_STRING("DeviceType"),
92  getter_AddRefs(property));
93  NS_ENSURE_SUCCESS(rv, rv);
94 
95  nsString deviceType;
96  rv = property->GetAsAString(deviceType);
97  NS_ENSURE_SUCCESS(rv, rv);
98 
99  if (deviceType.EqualsLiteral("CD")) {
100  rv = deviceCompatibility->Init(
103  }
104  else {
105  rv = deviceCompatibility->Init(sbIDeviceCompatibility::INCOMPATIBLE,
107  }
108 
109  NS_ENSURE_SUCCESS(rv, rv);
110 
111  // Return results.
112  NS_ADDREF(*aRetVal = deviceCompatibility);
113  return NS_OK;
114 }
115 
116 NS_IMETHODIMP
117 sbCDDeviceController::CreateDevice(nsIPropertyBag *aParams,
118  sbIDevice **aRetVal)
119 {
120  NS_ENSURE_ARG_POINTER(aParams);
121  NS_ENSURE_ARG_POINTER(aRetVal);
122 
123  nsID id;
124  nsresult rv = GetControllerIdInternal(id);
125  NS_ENSURE_SUCCESS(rv, rv);
126 
127  nsRefPtr<sbCDDevice> cdDevice;
128  rv = sbCDDevice::New(id, aParams, getter_AddRefs(cdDevice));
129  NS_ENSURE_SUCCESS(rv, rv);
130 
131  // Add the device to the internal list
132  rv = AddDeviceInternal(cdDevice);
133  NS_ENSURE_SUCCESS(rv, rv);
134 
135  // Return the new CD device.
136  NS_ADDREF(*aRetVal = cdDevice);
137 
138  return NS_OK;
139 }
140 
141 NS_IMETHODIMP
142 sbCDDeviceController::ControlsDevice(sbIDevice *aDevice, PRBool *aRetVal)
143 {
144  return ControlsDeviceInternal(aDevice, aRetVal);
145 }
146 
147 NS_IMETHODIMP
148 sbCDDeviceController::ConnectDevices()
149 {
150  return ConnectDevicesInternal();
151 }
152 
153 NS_IMETHODIMP
154 sbCDDeviceController::DisconnectDevices()
155 {
156  return DisconnectDevicesInternal();
157 }
158 
159 NS_IMETHODIMP
160 sbCDDeviceController::ReleaseDevice(sbIDevice *aDevice)
161 {
162  return ReleaseDeviceInternal(aDevice);
163 }
164 
165 NS_IMETHODIMP
166 sbCDDeviceController::ReleaseDevices()
167 {
168  return ReleaseDevicesInternal();
169 }
170 
171 NS_IMETHODIMP
172 sbCDDeviceController::GetId(nsID **aId)
173 {
174  NS_ENSURE_ARG_POINTER(aId);
175 
176  *aId = nsnull;
177  *aId = static_cast<nsID *>(NS_Alloc(sizeof(nsID)));
178  nsresult rv = GetControllerIdInternal(**aId);
179 
180  if (NS_FAILED(rv)) {
181  NS_Free(*aId);
182  *aId = nsnull;
183  }
184 
185  return NS_OK;
186 }
187 
188 NS_IMETHODIMP
189 sbCDDeviceController::GetName(nsAString & aName)
190 {
191  return GetControllerNameInternal(aName);
192 }
193 
194 NS_IMETHODIMP
195 sbCDDeviceController::GetMarshallId(nsID **aId)
196 {
197  NS_ENSURE_ARG_POINTER(aId);
198 
199  *aId = nsnull;
200  *aId = static_cast<nsID *>(NS_Alloc(sizeof(nsID)));
201  nsresult rv = GetMarshallIdInternal(**aId);
202 
203  if (NS_FAILED(rv)) {
204  NS_Free(*aId);
205  *aId = nsnull;
206  }
207 
208  return NS_OK;
209 }
210 
211 NS_IMETHODIMP
212 sbCDDeviceController::GetDevices(nsIArray **aDevices)
213 {
214  return GetDevicesInternal(aDevices);
215 }
216 
return NS_OK
nsresult ReleaseDeviceInternal(sbIDevice *aDevice)
nsresult GetMarshallIdInternal(nsID &aID)
#define SB_CDDEVICE_CONTROLLER_CONTRACTID
NS_IMPL_THREADSAFE_CI(sbMediaListEnumeratorWrapper)
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
readonly attribute nsIDPtr id
[UNIMPLEMENTED UNTIL AFTER 0.3]
SB_DEVICE_CONTROLLER_REGISTERSELF_IMPL(sbCDDeviceController,"@songbirdnest.com/Songbird/CDDeviceController;1") sbCDDeviceController
const unsigned long PREFERENCE_SELECTED
nsresult GetControllerNameInternal(nsAString &aName)
#define SB_CDDEVICE_CONTROLLER_CID
[UNIMPLEMENTED UNTIL AFTER 0.3]
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)
#define SB_CDDEVICE_MARSHALL_CID
sbIJobCancelable NS_DECL_CLASSINFO(sbGstreamerMediaInspector)
static nsresult New(const nsID &aControllerId, nsIPropertyBag *aProperties, sbCDDevice **aOutCDDevice)
Definition: sbCDDevice.cpp:259
const unsigned long PREFERENCE_UNKNOWN
NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER1(CDatabaseQuery, sbIDatabaseQuery) CDatabaseQuery
const unsigned long INCOMPATIBLE