From: Daniel Wagner <[email protected]>

---
 plugins/dundee.c |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/plugins/dundee.c b/plugins/dundee.c
index 7969d56..dd78817 100644
--- a/plugins/dundee.c
+++ b/plugins/dundee.c
@@ -37,10 +37,13 @@
 
 #define DUNDEE_SERVICE                 "org.ofono.dundee"
 #define DUNDEE_MANAGER_INTERFACE       DUNDEE_SERVICE ".Manager"
+#define DUNDEE_DEVICE_INTERFACE                DUNDEE_SERVICE ".Device"
 
 #define DEVICE_ADDED                   "DeviceAdded"
 #define DEVICE_REMOVED                 "DeviceRemoved"
+#define PROPERTY_CHANGED               "PropertyChanged"
 
+#define GET_PROPERTIES                 "GetProperties"
 #define GET_DEVICES                    "GetDevices"
 
 #define TIMEOUT 40000
@@ -86,7 +89,6 @@ static void create_device(struct dundee_data *info)
 
        DBG("%s", info->path);
 
-
        ident = g_strdup(get_ident(info->path));
        device = connman_device_create(ident, CONNMAN_DEVICE_TYPE_BLUETOOTH);
        if (device == NULL)
@@ -306,6 +308,54 @@ out:
        g_free(gateway);
 }
 
+static gboolean device_changed(DBusConnection *connection,
+                               DBusMessage *message,
+                               void *user_data)
+{
+       const char *path = dbus_message_get_path(message);
+       struct dundee_data *info = NULL;
+       DBusMessageIter iter, value;
+       const char *key;
+
+       info = g_hash_table_lookup(dundee_devices, path);
+       if (info == NULL)
+               return TRUE;
+
+       if (dbus_message_iter_init(message, &iter) == FALSE)
+               return TRUE;
+
+       dbus_message_iter_get_basic(&iter, &key);
+
+       dbus_message_iter_next(&iter);
+       dbus_message_iter_recurse(&iter, &value);
+
+       /*
+        * Dundee guarantees the ordering of Settings and
+        * Active. Settings will always be send before Active = True.
+        * That means we don't have to order here.
+        */
+       if (g_str_equal(key, "Active") == TRUE) {
+               dbus_message_iter_get_basic(&value, &info->active);
+
+               DBG("%s Active %d", info->path, info->active);
+       } else if (g_str_equal(key, "Settings") == TRUE) {
+               DBG("%s Settings", info->path);
+
+               extract_settings(&value, info);
+       } else if (g_str_equal(key, "Name") == TRUE) {
+               char *name;
+
+               dbus_message_iter_get_basic(&value, &name);
+
+               g_free(info->name);
+               info->name = g_strdup_printf("%s (DUN)", name);
+
+               DBG("%s Name %s", info->path, info->name);
+       }
+
+       return TRUE;
+}
+
 static void add_device(const char *path, DBusMessageIter *properties)
 {
        struct dundee_data *info;
@@ -344,7 +394,7 @@ static void add_device(const char *path, DBusMessageIter 
*properties)
 
                        dbus_message_iter_get_basic(&value, &name);
 
-                       info->name = g_strdup(name);
+                       info->name = g_strdup_printf("%s (DUN)", name);
 
                        DBG("%s Name %s", info->path, info->name);
                }
@@ -494,6 +544,7 @@ static void dundee_disconnect(DBusConnection *connection, 
void *user_data)
 static guint watch;
 static guint added_watch;
 static guint removed_watch;
+static guint device_watch;
 
 static int dundee_init(void)
 {
@@ -516,7 +567,15 @@ static int dundee_init(void)
                                                DEVICE_REMOVED, device_removed,
                                                NULL, NULL);
 
-       if (watch == 0 || added_watch == 0 || removed_watch == 0) {
+       device_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+                                               DUNDEE_DEVICE_INTERFACE,
+                                               PROPERTY_CHANGED,
+                                               device_changed,
+                                               NULL, NULL);
+
+
+       if (watch == 0 || added_watch == 0 || removed_watch == 0 ||
+                       device_watch == 0) {
                err = -EIO;
                goto remove;
        }
@@ -537,6 +596,7 @@ remove:
        g_dbus_remove_watch(connection, watch);
        g_dbus_remove_watch(connection, added_watch);
        g_dbus_remove_watch(connection, removed_watch);
+       g_dbus_remove_watch(connection, device_watch);
 
        dbus_connection_unref(connection);
 
@@ -548,6 +608,7 @@ static void dundee_exit(void)
        g_dbus_remove_watch(connection, watch);
        g_dbus_remove_watch(connection, added_watch);
        g_dbus_remove_watch(connection, removed_watch);
+       g_dbus_remove_watch(connection, device_watch);
 
        connman_device_driver_unregister(&dundee_driver);
        connman_network_driver_unregister(&network_driver);
-- 
1.7.8.110.g4cb5d1

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

Reply via email to