summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-03-21 19:35:35 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-03-21 19:35:35 +0000
commit4128274b3b8c47a58f6895e1dbe5b1949887b9e1 (patch)
tree6249833d50bf99ca832d129ff3868272e53a0092 /common
parent63ce134711eab575a35d2b4a5cbc62f1446d6a73 (diff)
Add functions for creating and removing HAL devices
Diffstat (limited to 'common')
-rw-r--r--common/hal-dummy.c7
-rw-r--r--common/hal-libhal.c56
-rw-r--r--common/hal.h3
3 files changed, 54 insertions, 12 deletions
diff --git a/common/hal-dummy.c b/common/hal-dummy.c
index 8d6be05f..a516ed1b 100644
--- a/common/hal-dummy.c
+++ b/common/hal-dummy.c
@@ -36,7 +36,12 @@ void hal_cleanup(void)
{
}
-int hal_add_device(struct hal_device *device)
+int hal_create_device(struct hal_device *device)
+{
+ return 0;
+}
+
+int hal_remove_device(struct hal_device *device)
{
return 0;
}
diff --git a/common/hal-libhal.c b/common/hal-libhal.c
index 4ae97098..cf8ece1f 100644
--- a/common/hal-libhal.c
+++ b/common/hal-libhal.c
@@ -38,6 +38,19 @@
static LibHalContext *hal_ctx = NULL;
+static DBusHandlerResult filter_function(DBusConnection *connection,
+ DBusMessage *message, void *userdata)
+{
+ info("filter_function: sender=%s destination=%s obj_path=%s interface=%s method=%s",
+ dbus_message_get_sender (message),
+ dbus_message_get_destination (message),
+ dbus_message_get_path (message),
+ dbus_message_get_interface (message),
+ dbus_message_get_member (message));
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
int hal_init(DBusConnection *conn)
{
hal_ctx = libhal_ctx_new();
@@ -46,6 +59,8 @@ int hal_init(DBusConnection *conn)
conn = init_dbus(NULL, NULL, NULL);
+ dbus_connection_add_filter(conn, filter_function, NULL, NULL);
+
if (libhal_ctx_set_dbus_connection(hal_ctx, conn) == FALSE) {
error("Failed to connect HAL via system bus");
libhal_ctx_free(hal_ctx);
@@ -75,18 +90,14 @@ void hal_cleanup(void)
hal_ctx = NULL;
}
-int hal_add_device(struct hal_device *device)
+int hal_create_device(struct hal_device *device)
{
+ DBusError err;
char udi[128], *dev;
char *str = "00000000-0000-1000-8000-00805f9b34fb";
dev = libhal_new_device(hal_ctx, NULL);
- if (libhal_device_add_capability(hal_ctx, dev,
- "bluetooth", NULL) == FALSE) {
- error("Failed to add device capability");
- }
-
if (libhal_device_set_property_string(hal_ctx, dev,
"bluetooth.uuid", str, NULL) == FALSE) {
error("Failed to add UUID property");
@@ -97,14 +108,39 @@ int hal_add_device(struct hal_device *device)
error("Failed to add connected state property");
}
- sprintf(udi, "/org/freedesktop/Hal/devices/bluetooth_network_connection_aabbccddeeff");
+ if (libhal_device_add_capability(hal_ctx, dev,
+ "bluetooth", NULL) == FALSE) {
+ error("Failed to add device capability");
+ }
- if (libhal_remove_device(hal_ctx, udi, NULL) == FALSE) {
- error("Can't remove old HAL device");
+ sprintf(udi, "/org/freedesktop/Hal/devices/bluetooth_test");
+
+ dbus_error_init(&err);
+ if (libhal_device_claim_interface(hal_ctx, dev,
+ "org.freedesktop.Hal.Device.MyBluetooth",
+ " <method name=\"Connect\">\n"
+ " </method>\n"
+ " <method name=\"Disconnect\">\n"
+ " </method>\n",
+ &err) == FALSE) {
+ error("Failed to claim to interface: ", err.message);
}
if (libhal_device_commit_to_gdl(hal_ctx, dev, udi, NULL) == FALSE) {
- error("Failed to add new HAL device");
+ error("Failed to create HAL device");
+ }
+
+ return 0;
+}
+
+int hal_remove_device(struct hal_device *device)
+{
+ char udi[128];
+
+ sprintf(udi, "/org/freedesktop/Hal/devices/bluetooth_test");
+
+ if (libhal_remove_device(hal_ctx, udi, NULL) == FALSE) {
+ error("Failed to remove HAL device");
}
return 0;
diff --git a/common/hal.h b/common/hal.h
index f2afacad..5f80fb92 100644
--- a/common/hal.h
+++ b/common/hal.h
@@ -31,4 +31,5 @@ struct hal_device {
char uuid[37];
};
-int hal_add_device(struct hal_device *);
+int hal_create_device(struct hal_device *);
+int hal_remove_device(struct hal_device *);