28 #include <nsISupportsPrimitives.h>
29 #include <nsIMutableArray.h>
30 #include <nsICategoryManager.h>
31 #include <nsComponentManagerUtils.h>
32 #include <nsServiceManagerUtils.h>
33 #include <sbIDeviceControllerRegistrar.h>
34 #include <sbIDeviceController.h>
35 #include <sbIDeviceCompatibility.h>
36 #include <nsIPropertyBag.h>
37 #include <nsIUUIDGenerator.h>
40 mCategoryName(categoryName), mIsMonitoring(PR_TRUE)
46 NS_ASSERTION(!mIsMonitoring,
47 "A device marshaller is being released with monitoring enabled");
53 nsCOMPtr<nsISimpleEnumerator> enumerator;
55 && NS_SUCCEEDED(controllers->Enumerate(getter_AddRefs(enumerator)))
58 while (NS_SUCCEEDED(enumerator->HasMoreElements(&more)) && more) {
59 nsCOMPtr<nsISupports> comPtr;
60 if (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(comPtr))) && comPtr) {
61 nsCOMPtr<sbIDeviceController> controller(do_QueryInterface(comPtr));
62 registrar->RegisterController(controller);
70 nsCOMPtr<nsIMutableArray> & controllers)
73 nsCOMPtr<nsISupportsCString> stringValue(do_QueryInterface(ptr));
74 nsCString controllerName;
76 if (stringValue && NS_SUCCEEDED(stringValue->GetData(controllerName))) {
77 nsCOMPtr<sbIDeviceController> deviceController =
78 do_CreateInstance(controllerName.get() , &rv);
79 NS_ENSURE_SUCCESS(rv, );
82 nsCOMPtr<sbIDeviceControllerRegistrar> controllerRegistrar =
83 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2", &rv);
84 NS_ENSURE_SUCCESS(rv, );
86 nsID* controllerId = nsnull;
87 rv = deviceController->GetId(&controllerId);
88 NS_ENSURE_SUCCESS(rv, );
90 nsCOMPtr<sbIDeviceController> existingController;
91 rv = controllerRegistrar->GetController(controllerId,
92 getter_AddRefs(existingController));
93 NS_Free(controllerId);
95 if (NS_SUCCEEDED(rv) && existingController) {
96 deviceController = existingController;
99 controllers->AppendElement(deviceController, PR_FALSE);
103 nsCOMPtr<nsIMutableArray> & controllers)
106 nsresult rv = controllers->Clear();
107 NS_ENSURE_SUCCESS(rv, rv);
111 while (NS_SUCCEEDED(enumerator->HasMoreElements(&more)) && more) {
112 nsCOMPtr<nsISupports> ptr;
113 if (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(ptr))) && ptr) {
116 NS_ENSURE_SUCCESS(rv, rv);
126 mControllers = do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
128 NS_ERROR(
"unable to create an nsArray");
132 nsCOMPtr<nsIMutableArray> controllers(do_QueryInterface(mControllers));
133 nsCOMPtr<nsISimpleEnumerator> categoryEnumerator;
134 if (NS_SUCCEEDED(GetCategoryManagerEnumerator(categoryEnumerator))) {
141 nsresult sbBaseDeviceMarshall::GetCategoryManagerEnumerator(nsCOMPtr<nsISimpleEnumerator> & enumerator)
143 nsCOMPtr<nsICategoryManager>
cm(do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
144 return cm->EnumerateCategory(PromiseFlatCString(mCategoryName).
get(), getter_AddRefs(enumerator));
157 return (comp1 && NS_SUCCEEDED(comp1->GetCompatibility(&compVal1))) ||
158 ((comp2 && NS_SUCCEEDED(comp2->GetCompatibility(&compVal2))) &&
159 compVal2 > compVal1 &&
164 nsIPropertyBag * deviceParameters)
166 nsCOMPtr<sbIDeviceCompatibility> compatibility;
167 if (NS_SUCCEEDED(controller->GetCompatibility(deviceParameters,
168 getter_AddRefs(compatibility)))
182 nsCOMPtr<nsISimpleEnumerator> enumerator;
184 && NS_SUCCEEDED(controllers->Enumerate(getter_AddRefs(enumerator)))
188 while (NS_SUCCEEDED(enumerator->HasMoreElements(&more)) && more) {
189 nsCOMPtr<sbIDeviceController> controller;
190 if (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(controller)))
192 nsCOMPtr<sbIDeviceCompatibility> compatibilityObj;
193 if (!deviceComparer.
Compare(controller, deviceParams))
nsIArray * GetControllers() const
PRBool CompareCompatibility(sbIDeviceCompatibility *comp1, sbIDeviceCompatibility *comp2)
virtual PRBool Compare(sbIDeviceController *controller, nsIPropertyBag *deviceParams)
sbBaseDeviceMarshall(nsACString const &categoryName)
sbIDeviceController * FindCompatibleControllers(nsIPropertyBag *deviceParams)
[UNIMPLEMENTED UNTIL AFTER 0.3]
static nsresult CopyCategoriesToArray(nsCOMPtr< nsISimpleEnumerator > &enumerator, nsCOMPtr< nsIMutableArray > &controllers)
void RegisterControllers(sbIDeviceControllerRegistrar *registrar)
[UNIMPLEMENTED UNTIL AFTER 0.3]
[UNIMPLEMENTED UNTIL AFTER 0.3]
void AppendDeviceController(nsCOMPtr< nsISupports > &ptr, nsCOMPtr< nsIMutableArray > &controllers)
sbIDeviceController * GetBestMatch() const
nsIArray * RefreshControllers()
virtual ~sbBaseDeviceMarshall()
const unsigned long INCOMPATIBLE
void SetBestMatch(sbIDeviceController *deviceController, sbIDeviceCompatibility *compatibility)