From: Daniel Wagner <[email protected]>
---
plugins/elect.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 64 insertions(+), 3 deletions(-)
diff --git a/plugins/elect.c b/plugins/elect.c
index 11541b6..9236f3c 100644
--- a/plugins/elect.c
+++ b/plugins/elect.c
@@ -37,10 +37,13 @@
#define ELECT_SERVICE "org.ofono.elect"
#define ELECT_MANAGER_INTERFACE ELECT_SERVICE ".Manager"
+#define ELECT_DEVICE_INTERFACE ELECT_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 elect_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)
@@ -328,6 +330,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 elect_data *info = NULL;
+ DBusMessageIter iter, value;
+ const char *key;
+
+ info = g_hash_table_lookup(elect_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);
+
+ /*
+ * Elect 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 elect_data *info;
@@ -366,7 +416,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);
}
@@ -516,6 +566,7 @@ static void elect_disconnect(DBusConnection *connection,
void *user_data)
static guint watch;
static guint added_watch;
static guint removed_watch;
+static guint device_watch;
static int elect_init(void)
{
@@ -538,7 +589,15 @@ static int elect_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,
+ ELECT_DEVICE_INTERFACE,
+ PROPERTY_CHANGED,
+ device_changed,
+ NULL, NULL);
+
+
+ if (watch == 0 || added_watch == 0 || removed_watch == 0 ||
+ device_watch == 0) {
err = -EIO;
goto remove;
}
@@ -559,6 +618,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);
@@ -570,6 +630,7 @@ static void elect_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(&elect_driver);
connman_network_driver_unregister(&network_driver);
--
1.7.8.110.g4cb5d1
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman