From: Daniel Wagner <[email protected]>

---
 plugins/dundee.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/plugins/dundee.c b/plugins/dundee.c
index dc69e31..7969d56 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,16 +65,77 @@ 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);
 
        g_free(info);
 }
 
+
 static int network_probe(struct connman_network *network)
 {
        DBG("network %p", network);
@@ -289,6 +353,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,
-- 
1.7.8.110.g4cb5d1

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to