diff options
author | Vinicius Gomes <vinicius.gomes@openbossa.org> | 2008-03-05 22:19:25 +0000 |
---|---|---|
committer | Vinicius Gomes <vinicius.gomes@openbossa.org> | 2008-03-05 22:19:25 +0000 |
commit | 2c1effee41e974f97b21aec1bdd1a232ba48056a (patch) | |
tree | 29639d210af0cc5a9bada750dbc72420af80b936 | |
parent | 190c8e73dc79edd6eb7485ad3663e89fb757aafa (diff) |
Adding Device Interface
-rw-r--r-- | hcid/adapter.c | 11 | ||||
-rw-r--r-- | hcid/device.c | 50 | ||||
-rw-r--r-- | hcid/device.h | 4 |
3 files changed, 51 insertions, 14 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c index 6d9b08fd..c683761e 100644 --- a/hcid/adapter.c +++ b/hcid/adapter.c @@ -50,11 +50,12 @@ #include "hcid.h" #include "dbus.h" + +#include "adapter.h" #include "device.h" #include "textfile.h" #include "oui.h" -#include "adapter.h" #include "dbus-common.h" #include "dbus-helper.h" #include "dbus-hci.h" @@ -3126,7 +3127,7 @@ static DBusHandlerResult adapter_list_trusts(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static void do_append_device(struct device_data *device, DBusMessageIter *iter) +static void do_append_device(struct device *device, DBusMessageIter *iter) { const char *path = device->path; @@ -3177,7 +3178,7 @@ static DBusHandlerResult create_device(DBusConnection *conn, DBusMessage *msg, void *data) { struct adapter *adapter = data; - struct device_data *device; + struct device *device; DBusMessage *reply; const char *address, *path; @@ -3195,7 +3196,7 @@ static DBusHandlerResult create_device(DBusConnection *conn, if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - device = device_create(adapter->address, address); + device = device_create(adapter, address); path = device->path; @@ -3321,7 +3322,7 @@ static DBusMethodVTable adapter_methods[] = { /* BlueZ 4.0 API */ { "GetProperties", get_properties, "", "a{sv}" }, - { "SetProperty", set_property, "", "sv" }, + { "SetProperty", set_property, "sv", "" }, { "DiscoverDevices", adapter_discover_devices, "", "" }, { "CancelDiscovery", adapter_cancel_discovery, "", "" }, { "ListDevices", list_devices, "", "ao" }, diff --git a/hcid/device.c b/hcid/device.c index 002b77ab..bf84ad2c 100644 --- a/hcid/device.c +++ b/hcid/device.c @@ -52,10 +52,13 @@ #include "textfile.h" #include "oui.h" +#include "adapter.h" #include "device.h" #define MAX_DEVICES 16 +#define DEVICE_INTERFACE "org.bluez.Device" + struct hci_peer { struct timeval lastseen; struct timeval lastused; @@ -717,7 +720,7 @@ gboolean device_init(DBusConnection *conn) return TRUE; } -static void device_destroy(struct device_data *device) +static void device_destroy(struct device *device) { debug("Removing device %s", device->path); @@ -740,7 +743,7 @@ void device_foreach(GFunc func, gpointer user_data) g_slist_foreach(device_list, func, user_data); } -static void device_free(struct device_data *device) +static void device_free(struct device *device) { g_free(device->path); g_free(device); @@ -748,22 +751,53 @@ static void device_free(struct device_data *device) static void device_unregister(DBusConnection *conn, void *user_data) { - struct device_data *device = user_data; + struct device *device = user_data; device_list = g_slist_remove(device_list, device); device_free(device); } -struct device_data *device_create(const char *adapter, const char *address) +static DBusHandlerResult disconnect(DBusConnection *conn, + DBusMessage *msg, void *user_data) +{ + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +static DBusHandlerResult get_properties(DBusConnection *conn, + DBusMessage *msg, void *user_data) +{ + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +static DBusHandlerResult set_property(DBusConnection *conn, + DBusMessage *msg, void *user_data) +{ + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +static DBusMethodVTable device_methods[] = { + { "GetProperties", get_properties, "", "a{sv}" }, + { "SetProperty", set_property, "sv", "" }, + { "Disconnect", disconnect, "", "" }, + { NULL, NULL, NULL, NULL } +}; + +static DBusSignalVTable device_signals[] = { + { "PropertyChanged", "sv" }, + { "DisconnectRequested", "" }, + { NULL, NULL } +}; + +struct device *device_create(struct adapter *adapter, const char *address) { - struct device_data *device; + struct device *device; - device = g_try_malloc0(sizeof(struct device_data)); + device = g_try_malloc0(sizeof(struct device)); if (device == NULL) return NULL; - device->path = g_strdup_printf("%s/dev_%s", adapter, address); + device->path = g_strdup_printf("%s/dev_%s", adapter->address, address); g_strdelimit(device->path, ":", '_'); debug("Creating device %s", device->path); @@ -773,6 +807,8 @@ struct device_data *device_create(const char *adapter, const char *address) device_free(device); return NULL; } + dbus_connection_register_interface(connection, device->path, + DEVICE_INTERFACE, device_methods, device_signals, NULL); device_list = g_slist_append(device_list, device); diff --git a/hcid/device.h b/hcid/device.h index 2f8f7943..e0277de7 100644 --- a/hcid/device.h +++ b/hcid/device.h @@ -22,12 +22,12 @@ * */ -struct device_data { +struct device { char *path; }; gboolean device_init(DBusConnection *conn); void device_cleanup(void); void device_foreach(GFunc func, gpointer user_data); -struct device_data *device_create(const char *adapter, const char *address); +struct device *device_create(struct adapter *adapter, const char *address); void device_remove(const char *path); |