Diff between 8144c2ff585aac8951bf6f4b9469f8151b71d4a8 and 496b6abf743440e937222c62768e0a3b31f47f02

Changed Files

File Additions Deletions Status
client/gatt.c +29 -0 modified
client/gatt.h +2 -0 modified
client/main.c +13 -0 modified

Full Patch

diff --git a/client/gatt.c b/client/gatt.c
index 47785a8..7c44a9f 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -220,3 +220,32 @@ void gatt_remove_descriptor(GDBusProxy *proxy)
 
 	print_descriptor(proxy, COLORED_DEL);
 }
+
+static void list_attributes(const char *path, GList *source)
+{
+	GList *l;
+
+	for (l = source; l; l = g_list_next(l)) {
+		GDBusProxy *proxy = l->data;
+		const char *proxy_path;
+
+		proxy_path = g_dbus_proxy_get_path(proxy);
+
+		if (!g_str_has_prefix(proxy_path, path))
+			continue;
+
+		if (source == services) {
+			print_service(proxy, NULL);
+			list_attributes(proxy_path, characteristics);
+		} else if (source == characteristics) {
+			print_characteristic(proxy, NULL);
+			list_attributes(proxy_path, descriptors);
+		} else if (source == descriptors)
+			print_descriptor(proxy, NULL);
+	}
+}
+
+void gatt_list_attributes(const char *path)
+{
+	list_attributes(path, services);
+}
diff --git a/client/gatt.h b/client/gatt.h
index 8b30668..5785073 100644
--- a/client/gatt.h
+++ b/client/gatt.h
@@ -29,3 +29,5 @@ void gatt_remove_characteristic(GDBusProxy *proxy);
 
 void gatt_add_descriptor(GDBusProxy *proxy);
 void gatt_remove_descriptor(GDBusProxy *proxy);
+
+void gatt_list_attributes(const char *device);
diff --git a/client/main.c b/client/main.c
index 72223d5..7cdb19a 100644
--- a/client/main.c
+++ b/client/main.c
@@ -1150,6 +1150,17 @@ static void cmd_disconn(const char *arg)
 	rl_printf("Attempting to disconnect from %s\n", arg);
 }
 
+static void cmd_list_attributes(const char *arg)
+{
+	GDBusProxy *proxy;
+
+	proxy = find_device(arg);
+	if (!proxy)
+		return;
+
+	gatt_list_attributes(g_dbus_proxy_get_path(proxy));
+}
+
 static void cmd_version(const char *arg)
 {
 	rl_printf("Version %s\n", VERSION);
@@ -1268,6 +1279,8 @@ static const struct {
 							dev_generator },
 	{ "disconnect",   "[dev]",    cmd_disconn, "Disconnect device",
 							dev_generator },
+	{ "list-attributes", "[dev]", cmd_list_attributes, "List attributes",
+							dev_generator },
 	{ "version",      NULL,       cmd_version, "Display version" },
 	{ "quit",         NULL,       cmd_quit, "Quit program" },
 	{ "exit",         NULL,       cmd_quit },