summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2015-01-05 14:50:34 -0200
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2015-02-10 13:15:57 +0200
commit77196fd631b193f2c1cfaea9bafe17fb9600cc80 (patch)
tree8dec8bfa0a0c084d7210f836e0ed72a995ffca6f /client
parentc6923a75ae058a292c725061dd13785c6306c611 (diff)
downloadbluez-77196fd631b193f2c1cfaea9bafe17fb9600cc80.tar.gz
client: Add support for GattDescriptor1
This add support for GattDescriptor1 interface detection and prints when they are added or removed.
Diffstat (limited to 'client')
-rw-r--r--client/gatt.c66
-rw-r--r--client/gatt.h3
-rw-r--r--client/main.c4
3 files changed, 73 insertions, 0 deletions
diff --git a/client/gatt.c b/client/gatt.c
index 8fd113f49..47785a862 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -47,6 +47,7 @@
static GList *services;
static GList *characteristics;
+static GList *descriptors;
static void print_service(GDBusProxy *proxy, const char *description)
{
@@ -154,3 +155,68 @@ void gatt_remove_characteristic(GDBusProxy *proxy)
print_characteristic(proxy, COLORED_DEL);
}
+
+static void print_descriptor(GDBusProxy *proxy, const char *description)
+{
+ DBusMessageIter iter;
+ const char *uuid, *text;
+
+ if (g_dbus_proxy_get_property(proxy, "UUID", &iter) == FALSE)
+ return;
+
+ dbus_message_iter_get_basic(&iter, &uuid);
+
+ text = uuidstr_to_str(uuid);
+ if (!text)
+ text = uuid;
+
+ rl_printf("%s%s%sDescriptor %s %s\n",
+ description ? "[" : "",
+ description ? : "",
+ description ? "] " : "",
+ g_dbus_proxy_get_path(proxy),
+ text);
+}
+
+static gboolean descriptor_is_child(GDBusProxy *characteristic)
+{
+ GList *l;
+ DBusMessageIter iter;
+ const char *service, *path;
+
+ if (!g_dbus_proxy_get_property(characteristic, "Characteristic", &iter))
+ return FALSE;
+
+ dbus_message_iter_get_basic(&iter, &service);
+
+ for (l = characteristics; l; l = g_list_next(l)) {
+ GDBusProxy *proxy = l->data;
+
+ path = g_dbus_proxy_get_path(proxy);
+
+ if (!strcmp(path, service))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void gatt_add_descriptor(GDBusProxy *proxy)
+{
+ if (!descriptor_is_child(proxy))
+ return;
+
+ descriptors = g_list_append(descriptors, proxy);
+
+ print_descriptor(proxy, COLORED_NEW);
+}
+
+void gatt_remove_descriptor(GDBusProxy *proxy)
+{
+ if (!descriptor_is_child(proxy))
+ return;
+
+ descriptors = g_list_remove(descriptors, proxy);
+
+ print_descriptor(proxy, COLORED_DEL);
+}
diff --git a/client/gatt.h b/client/gatt.h
index 924c4d9c1..8b30668d6 100644
--- a/client/gatt.h
+++ b/client/gatt.h
@@ -26,3 +26,6 @@ void gatt_remove_service(GDBusProxy *proxy);
void gatt_add_characteristic(GDBusProxy *proxy);
void gatt_remove_characteristic(GDBusProxy *proxy);
+
+void gatt_add_descriptor(GDBusProxy *proxy);
+void gatt_remove_descriptor(GDBusProxy *proxy);
diff --git a/client/main.c b/client/main.c
index 3db18affe..059026675 100644
--- a/client/main.c
+++ b/client/main.c
@@ -340,6 +340,8 @@ static void proxy_added(GDBusProxy *proxy, void *user_data)
gatt_add_service(proxy);
} else if (!strcmp(interface, "org.bluez.GattCharacteristic1")) {
gatt_add_characteristic(proxy);
+ } else if (!strcmp(interface, "org.bluez.GattDescriptor1")) {
+ gatt_add_descriptor(proxy);
}
}
@@ -377,6 +379,8 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)
gatt_remove_service(proxy);
} else if (!strcmp(interface, "org.bluez.GattCharacteristic1")) {
gatt_remove_characteristic(proxy);
+ } else if (!strcmp(interface, "org.bluez.GattDescriptor1")) {
+ gatt_remove_descriptor(proxy);
}
}