diff options
author | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2012-06-01 16:11:24 +0200 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-06-04 16:18:15 +0300 |
commit | 4344bf7ca674f2a31edbdd248eec6d7d6ecfb22a (patch) | |
tree | 644b1f3e8df460e84f0f58adca8a3b80a97161e8 /plugins | |
parent | cf3be4a7368339c710b107e81ee9c0e145e869c3 (diff) | |
download | connman-4344bf7ca674f2a31edbdd248eec6d7d6ecfb22a.tar.gz connman-4344bf7ca674f2a31edbdd248eec6d7d6ecfb22a.tar.bz2 connman-4344bf7ca674f2a31edbdd248eec6d7d6ecfb22a.zip |
dundee: Create connman device
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/dundee.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/plugins/dundee.c b/plugins/dundee.c index 10572355..afa639c2 100644 --- a/plugins/dundee.c +++ b/plugins/dundee.c @@ -23,6 +23,7 @@ #include <config.h> #endif +#include <string.h> #include <errno.h> #include <gdbus.h> @@ -52,6 +53,8 @@ struct dundee_data { char *path; char *name; + struct connman_device *device; + connman_bool_t active; int index; @@ -62,10 +65,69 @@ struct dundee_data { char *nameservers; }; +static char *get_ident(const char *path) +{ + char *pos; + + if (*path != '/') + return NULL; + + pos = strrchr(path, '/'); + if (pos == NULL) + return NULL; + + return pos + 1; +} + +static void create_device(struct dundee_data *info) +{ + struct connman_device *device; + char *ident; + + DBG("%s", info->path); + + ident = g_strdup(get_ident(info->path)); + device = connman_device_create(ident, CONNMAN_DEVICE_TYPE_BLUETOOTH); + if (device == NULL) + goto out; + + DBG("device %p", device); + + connman_device_set_ident(device, ident); + + connman_device_set_string(device, "Path", info->path); + + connman_device_set_data(device, info); + + if (connman_device_register(device) < 0) { + connman_error("Failed to register DUN device"); + connman_device_unref(device); + goto out; + } + + info->device = device; + +out: + g_free(ident); +} + +static void destroy_device(struct dundee_data *info) +{ + connman_device_set_powered(info->device, FALSE); + + connman_device_unregister(info->device); + connman_device_unref(info->device); + + info->device = NULL; +} + static void device_destroy(gpointer data) { struct dundee_data *info = data; + if (info->device != NULL) + destroy_device(info); + g_free(info->path); g_free(info->name); @@ -292,6 +354,8 @@ static void add_device(const char *path, DBusMessageIter *properties) } g_hash_table_insert(dundee_devices, g_strdup(path), info); + + create_device(info); } static gboolean device_added(DBusConnection *connection, DBusMessage *message, |