50 #include <dbus/dbus-glib-lowlevel.h>
68 mpDBusConnection(NULL)
85 libhal_ctx_shutdown(mpLibHalCtx, NULL);
86 libhal_ctx_free(mpLibHalCtx);
91 dbus_connection_unref(mpDBusConnection);
108 dbus_error_init(&dBusError);
111 mpLibHalCtx = libhal_ctx_new();
113 rv = NS_ERROR_OUT_OF_MEMORY;
116 if (NS_SUCCEEDED(rv))
118 mpDBusConnection = dbus_bus_get(DBUS_BUS_SYSTEM, &dBusError);
119 if (!mpDBusConnection)
120 rv = NS_ERROR_OUT_OF_MEMORY;
122 if (NS_SUCCEEDED(rv))
123 dbus_connection_setup_with_g_main(mpDBusConnection, NULL);
126 if (NS_SUCCEEDED(rv))
128 success = libhal_ctx_set_dbus_connection(mpLibHalCtx, mpDBusConnection);
130 rv = NS_ERROR_FAILURE;
134 if (NS_SUCCEEDED(rv))
135 success = libhal_ctx_init(mpLibHalCtx, &dBusError);
138 if (dbus_error_is_set(&dBusError))
140 LOG(
"sbLibHalCtx::Initialize error %s: %s\n",
143 dbus_error_init(&dBusError);
147 dbus_error_free(&dBusError);
174 success = libhal_ctx_set_user_data(mpLibHalCtx, aUserData);
175 NS_ENSURE_TRUE(success, NS_ERROR_UNEXPECTED);
191 nsCStringArray &aDeviceList)
193 char **deviceList = NULL;
200 dbus_error_init(&dBusError);
203 deviceList = libhal_get_all_devices(mpLibHalCtx, &deviceCnt, &dBusError);
205 rv = NS_ERROR_UNEXPECTED;
208 if (NS_SUCCEEDED(rv))
211 for (i = 0; i < deviceCnt; i++)
213 aDeviceList.AppendCString(nsCString(deviceList[i]));
218 if (dbus_error_is_set(&dBusError))
220 LOG(
"sbLibHalCtx::GetAllDevices error %s: %s\n",
223 dbus_error_init(&dBusError);
227 dbus_error_free(&dBusError);
229 libhal_free_string_array(deviceList);
248 const nsACString &aUDI,
257 NS_ASSERTION(aKey,
"aKey is null");
258 NS_ASSERTION(apExists,
"apExists is null");
261 dbus_error_init(&dBusError);
264 exists = libhal_device_property_exists(mpLibHalCtx,
270 if (dbus_error_is_set(&dBusError))
272 LOG(
"sbLibHalCtx::DevicePropertyExists error %s: %s\n",
275 dbus_error_init(&dBusError);
276 rv = NS_ERROR_UNEXPECTED;
280 dbus_error_free(&dBusError);
283 if (NS_SUCCEEDED(rv))
288 *apExists = PR_FALSE;
307 const nsACString &aUDI,
309 nsCString &aProperty)
311 char *
property = NULL;
316 NS_ASSERTION(aKey,
"aKey is null");
319 dbus_error_init(&dBusError);
322 property = libhal_device_get_property_string(mpLibHalCtx,
327 aProperty.AssignLiteral(property);
329 rv = NS_ERROR_FAILURE;
334 dbus_error_free(&dBusError);
336 libhal_free_string(property);
354 const nsACString &aUDI,
363 NS_ASSERTION(aKey,
"aKey is null");
364 NS_ASSERTION(aProperty,
"aProperty is null");
367 dbus_error_init(&dBusError);
370 property = libhal_device_get_property_int(mpLibHalCtx,
374 if (!dbus_error_is_set(&dBusError))
375 *aProperty = property;
377 rv = NS_ERROR_FAILURE;
382 dbus_error_free(&dBusError);
400 const nsACString &aUDI,
404 dbus_bool_t property;
409 NS_ASSERTION(aKey,
"aKey is null");
410 NS_ASSERTION(aProperty,
"aProperty is null");
413 dbus_error_init(&dBusError);
416 property = libhal_device_get_property_bool(mpLibHalCtx,
420 if (!dbus_error_is_set(&dBusError))
421 *aProperty = property;
423 rv = NS_ERROR_FAILURE;
428 dbus_error_free(&dBusError);
446 const nsACString &aUDI,
448 nsTArray<nsCString> &aProperty)
450 char **
property = NULL;
455 NS_ASSERTION(aKey,
"aKey is null");
458 dbus_error_init(&dBusError);
461 property = libhal_device_get_property_strlist(mpLibHalCtx,
469 pPropStr = &(
property[0]);
472 aProperty.AppendElement(*pPropStr);
478 rv = NS_ERROR_FAILURE;
484 dbus_error_free(&dBusError);
486 libhal_free_string_array(property);
502 LibHalDeviceAdded aCallback)
507 NS_ASSERTION(aCallback,
"aCallback is null");
510 success = libhal_ctx_set_device_added(mpLibHalCtx, aCallback);
511 NS_ENSURE_TRUE(success, NS_ERROR_UNEXPECTED);
527 LibHalDeviceRemoved aCallback)
532 NS_ASSERTION(aCallback,
"aCallback is null");
535 success = libhal_ctx_set_device_removed(mpLibHalCtx, aCallback);
536 NS_ENSURE_TRUE(success, NS_ERROR_UNEXPECTED);
552 LibHalDevicePropertyModified
558 NS_ASSERTION(aCallback,
"aCallback is null");
561 success = libhal_ctx_set_device_property_modified(mpLibHalCtx, aCallback);
562 NS_ENSURE_TRUE(success, NS_ERROR_UNEXPECTED);
582 dbus_error_init(&dBusError);
585 success = libhal_device_property_watch_all(mpLibHalCtx, &dBusError);
587 rv = NS_ERROR_UNEXPECTED;
590 if (dbus_error_is_set(&dBusError))
592 LOG(
"sbLibHalCtx::DevicePropertyWatchAll error %s: %s\n",
595 dbus_error_init(&dBusError);
599 dbus_error_free(&dBusError);
624 const nsACString &aUDI,
625 const char *aInterface,
626 PRBool *aHasInterface)
628 nsTArray<nsCString> interfaceList;
629 PRUint32 interfaceCount;
636 NS_ENSURE_SUCCESS(rv, rv);
639 *aHasInterface = PR_FALSE;
645 NS_ENSURE_SUCCESS(rv, rv);
648 interfaceCount = interfaceList.Length();
649 for (i = 0; i < interfaceCount; i++)
651 if (interfaceList[i].EqualsLiteral(aInterface))
653 *aHasInterface = PR_TRUE;
659 *aHasInterface = PR_FALSE;
680 nsCString &aDeviceUDI)
682 return (DeviceCallMethod(aDeviceUDI,
683 "org.freedesktop.Hal.Device.Volume",
698 nsCString &aDeviceUDI)
700 return (DeviceCallMethod(aDeviceUDI,
701 "org.freedesktop.Hal.Device.Volume",
723 nsresult sbLibHalCtx::DeviceCallMethod(
724 nsCString &aDeviceUDI,
725 const char *aInterface,
728 DBusMessage *pDBusMessage = NULL;
729 DBusMessage *pDBusReply = NULL;
738 NS_ASSERTION(aInterface,
"aInterface is null");
739 NS_ASSERTION(aMethod,
"aMethod is null");
742 dbus_error_init(&dBusError);
745 pDBusMessage = dbus_message_new_method_call(
"org.freedesktop.Hal",
750 rv = NS_ERROR_OUT_OF_MEMORY;
751 if (NS_SUCCEEDED(rv))
753 success = dbus_message_append_args(pDBusMessage,
760 rv = NS_ERROR_UNEXPECTED;
764 if (NS_SUCCEEDED(rv))
766 pDBusReply = dbus_connection_send_with_reply_and_block
772 rv = NS_ERROR_FAILURE;
777 if (NS_SUCCEEDED(rv))
779 rv = DeviceGetMethodRetCode(pDBusReply, &halRetCode);
780 if (NS_SUCCEEDED(rv) && halRetCode)
781 rv = NS_ERROR_FAILURE;
787 if (dbus_error_is_set(&dBusError))
789 LOG(
"sbLibHalCtx::DeviceCallMethod error %s: %s\n",
792 dbus_error_init(&dBusError);
796 dbus_error_free(&dBusError);
798 dbus_message_unref(pDBusMessage);
800 dbus_message_unref(pDBusReply);
816 nsresult sbLibHalCtx::DeviceGetMethodRetCode(
817 DBusMessage *apDBusReply,
820 DBusMessageIter dBusMessageIter;
828 NS_ASSERTION(apDBusReply,
"apDBusReply is null");
829 NS_ASSERTION(apRetCode,
"apRetCode is null");
832 dbus_error_init(&dBusError);
835 success = dbus_message_iter_init(apDBusReply, &dBusMessageIter);
837 rv = NS_ERROR_UNEXPECTED;
841 argType = dbus_message_iter_get_arg_type(&dBusMessageIter);
842 if ((argType != DBUS_TYPE_INT32) && (argType != DBUS_TYPE_UINT32))
844 LOG(
"sbLibHalCtx::DeviceGetMethodRetCode "
845 "unexpected return code type %d\n",
847 rv = NS_ERROR_UNEXPECTED;
851 if (NS_SUCCEEDED(rv))
852 dbus_message_iter_get_basic(&dBusMessageIter, &retCode);
855 if (dbus_error_is_set(&dBusError))
857 LOG(
"sbLibHalCtx::DeviceGetMethodRetCode error %s: %s\n",
860 dbus_error_init(&dBusError);
864 dbus_error_free(&dBusError);
867 if (NS_SUCCEEDED(rv))
868 *apRetCode = retCode;
nsresult SetDevicePropertyModified(LibHalDevicePropertyModified aCallback)
#define SB_PRLOG_SETUP(x)
nsresult DeviceVolumeEject(nsCString &aDeviceUDI)
nsresult GetAllDevices(nsCStringArray &aDeviceList)
nsresult DeviceHasInterface(const nsACString &aUDI, const char *aInterface, PRBool *aHasInterface)
nsresult DeviceGetPropertyInt(const nsACString &aUDI, const char *aKey, PRUint32 *aProperty)
nsresult DevicePropertyWatchAll()
nsresult DevicePropertyExists(const nsACString &aUDI, const char *aKey, PRBool *apExists)
nsresult SetDeviceRemoved(LibHalDeviceRemoved aCallback)
nsresult DeviceVolumeUnmount(nsCString &aDeviceUDI)
nsresult DeviceGetPropertyStringList(const nsACString &aUDI, const char *aKey, nsTArray< nsCString > &aProperty)
nsresult SetDeviceAdded(LibHalDeviceAdded aCallback)
nsresult DeviceGetPropertyBool(const nsACString &aUDI, const char *aKey, PRBool *aProperty)
nsresult SetUserData(void *aUserData)
_getSelectedPageStyle s i
nsresult DeviceGetPropertyString(const nsACString &aUDI, const char *aKey, nsCString &aProperty)