diff options
-rw-r--r-- | common/hal-dummy.c | 7 | ||||
-rw-r--r-- | common/hal-libhal.c | 56 | ||||
-rw-r--r-- | common/hal.h | 3 | ||||
-rw-r--r-- | network/main.c | 4 |
4 files changed, 57 insertions, 13 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 *); diff --git a/network/main.c b/network/main.c index d6c3ac0d..16a173c5 100644 --- a/network/main.c +++ b/network/main.c @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) hal_init(NULL); - hal_add_device(NULL); + hal_create_device(NULL); if (network_init() == -1) goto fail; @@ -81,6 +81,8 @@ int main(int argc, char *argv[]) network_exit(); + hal_remove_device(NULL); + hal_cleanup(); fail: |