Diff between aab6835b0ab1843c5d1a8f6c5defd3f6358924be and c6923a75ae058a292c725061dd13785c6306c611

Changed Files

File Additions Deletions Status
client/gatt.c +66 -0 modified
client/gatt.h +3 -0 modified
client/main.c +4 -0 modified

Full Patch

diff --git a/client/gatt.c b/client/gatt.c
index 7de5c7b..8fd113f 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -46,6 +46,7 @@
 #define COLORED_DEL	COLOR_RED "DEL" COLOR_OFF
 
 static GList *services;
+static GList *characteristics;
 
 static void print_service(GDBusProxy *proxy, const char *description)
 {
@@ -88,3 +89,68 @@ void gatt_remove_service(GDBusProxy *proxy)
 
 	print_service(proxy, COLORED_DEL);
 }
+
+static void print_characteristic(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%sCharacteristic %s %s\n",
+				description ? "[" : "",
+				description ? : "",
+				description ? "] " : "",
+				g_dbus_proxy_get_path(proxy),
+				text);
+}
+
+static gboolean characteristic_is_child(GDBusProxy *characteristic)
+{
+	GList *l;
+	DBusMessageIter iter;
+	const char *service, *path;
+
+	if (!g_dbus_proxy_get_property(characteristic, "Service", &iter))
+		return FALSE;
+
+	dbus_message_iter_get_basic(&iter, &service);
+
+	for (l = services; 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_characteristic(GDBusProxy *proxy)
+{
+	if (!characteristic_is_child(proxy))
+		return;
+
+	characteristics = g_list_append(characteristics, proxy);
+
+	print_characteristic(proxy, COLORED_NEW);
+}
+
+void gatt_remove_characteristic(GDBusProxy *proxy)
+{
+	if (!characteristic_is_child(proxy))
+		return;
+
+	characteristics = g_list_remove(characteristics, proxy);
+
+	print_characteristic(proxy, COLORED_DEL);
+}
diff --git a/client/gatt.h b/client/gatt.h
index f049039..924c4d9 100644
--- a/client/gatt.h
+++ b/client/gatt.h
@@ -23,3 +23,6 @@
 
 void gatt_add_service(GDBusProxy *proxy);
 void gatt_remove_service(GDBusProxy *proxy);
+
+void gatt_add_characteristic(GDBusProxy *proxy);
+void gatt_remove_characteristic(GDBusProxy *proxy);
diff --git a/client/main.c b/client/main.c
index ab644ba..3db18af 100644
--- a/client/main.c
+++ b/client/main.c
@@ -338,6 +338,8 @@ static void proxy_added(GDBusProxy *proxy, void *user_data)
 	} else if (!strcmp(interface, "org.bluez.GattService1")) {
 		if (service_is_child(proxy))
 			gatt_add_service(proxy);
+	} else if (!strcmp(interface, "org.bluez.GattCharacteristic1")) {
+		gatt_add_characteristic(proxy);
 	}
 }
 
@@ -373,6 +375,8 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)
 	} else if (!strcmp(interface, "org.bluez.GattService1")) {
 		if (service_is_child(proxy))
 			gatt_remove_service(proxy);
+	} else if (!strcmp(interface, "org.bluez.GattCharacteristic1")) {
+		gatt_remove_characteristic(proxy);
 	}
 }