diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2007-08-17 20:28:47 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2007-08-17 20:28:47 +0000 |
commit | 86892be8d38960096f9b9c5613ba28fc9003d288 (patch) | |
tree | fdf1987d0e4f261112ea3fb4561c3cb4fd50e943 /hcid/device.c | |
parent | c2f12da34adf0e5d2a04b7b3dbeb3753cb77f5d7 (diff) |
Add initial steps for generic device handling
Diffstat (limited to 'hcid/device.c')
-rw-r--r-- | hcid/device.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/hcid/device.c b/hcid/device.c index e7e3fbda..3c4f960d 100644 --- a/hcid/device.c +++ b/hcid/device.c @@ -38,11 +38,20 @@ #include <bluetooth/hci.h> #include <bluetooth/hci_lib.h> +#include <glib.h> + +#include <dbus/dbus.h> + +#include "dbus-helper.h" + #include "hcid.h" +#include "logging.h" #include "textfile.h" #include "oui.h" +#include "device.h" + #define MAX_DEVICES 16 struct hci_peer { @@ -660,3 +669,82 @@ int get_encryption_key_size(uint16_t dev_id, const bdaddr_t *baddr) return size; } + +static DBusConnection *connection = NULL; + +static GSList *device_list = NULL; + +gboolean device_init(DBusConnection *conn) +{ + connection = dbus_connection_ref(conn); + if (connection == NULL) + return FALSE; + + return TRUE; +} + +static void device_destroy(struct device_data *device) +{ + debug("Removing device %s", device->path); + + dbus_connection_destroy_object_path(connection, device->path); +} + +void device_cleanup(void) +{ + g_slist_foreach(device_list, (GFunc) device_destroy, NULL); + g_slist_free(device_list); + + if (connection == NULL) + return; + + dbus_connection_unref(connection); +} + +void device_foreach(GFunc func, gpointer user_data) +{ + g_slist_foreach(device_list, func, user_data); +} + +static void device_free(struct device_data *device) +{ + g_free(device->path); + g_free(device); +} + +static void device_unregister(DBusConnection *conn, void *user_data) +{ + struct device_data *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) +{ + struct device_data *device; + + device = g_try_malloc0(sizeof(struct device_data)); + if (device == NULL) + return NULL; + + device->path = g_strdup_printf("/device/%s_%s", adapter, address); + g_strdelimit(device->path, ":", '_'); + + debug("Creating device %s", device->path); + + if (dbus_connection_create_object_path(connection, device->path, + device, device_unregister) == FALSE) { + device_free(device); + return NULL; + } + + device_list = g_slist_append(device_list, device); + + return device; +} + +void device_remove(const char *path) +{ +} |