client: Enable list-attributes to print local attributes
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 29 Jan 2019 14:20:41 +0000 (16:20 +0200)
committerhimanshu <h.himanshu@samsung.com>
Wed, 22 Jan 2020 13:46:22 +0000 (19:16 +0530)
This enable passing "local" to list-attributes to print the attributes
registered locally:

> list-attributes local
Primary Service (Handle 0x0400)
/org/bluez/app/service0x74ccb0
0x1820
Internet Protocol Support

Change-Id: I13a383687c6c653097917093388f1ec41ce656f4
Signed-off-by: himanshu <h.himanshu@samsung.com>
client/gatt.c
client/main.c

index 4f8566b..9a43c34 100755 (executable)
@@ -413,8 +413,50 @@ static void list_attributes(const char *path, GList *source)
        }
 }
 
+static void list_descs(GList *descs)
+{
+       GList *l;
+
+       for (l = descs; l; l = g_list_next(l)) {
+               struct desc *desc = l->data;
+
+               print_desc(desc, NULL);
+       }
+}
+
+static void list_chrcs(GList *chrcs)
+{
+       GList *l;
+
+       for (l = chrcs; l; l = g_list_next(l)) {
+               struct chrc *chrc = l->data;
+
+               print_chrc(chrc, NULL);
+
+               list_descs(chrc->descs);
+       }
+}
+
+static void list_services(void)
+{
+       GList *l;
+
+       for (l = local_services; l; l = g_list_next(l)) {
+               struct service *service = l->data;
+
+               print_service(service, NULL);
+
+               list_chrcs(service->chrcs);
+       }
+}
+
 void gatt_list_attributes(const char *path)
 {
+       if (path && !strcmp(path, "local")) {
+               list_services();
+               return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+       }
+
        list_attributes(path, services);
        return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
index 0ee417b..c17111c 100644 (file)
@@ -1910,12 +1910,21 @@ static void cmd_disconn(int argc, char *argv[])
 static void cmd_list_attributes(int argc, char *argv[])
 {
        GDBusProxy *proxy;
+       const char *path;
+
+       if (argc > 1 && !strcmp(argv[1], "local")) {
+               path = argv[1];
+               goto done;
+       }
 
        proxy = find_device(argc, argv);
        if (!proxy)
                return bt_shell_noninteractive_quit(EXIT_FAILURE);
 
-       gatt_list_attributes(g_dbus_proxy_get_path(proxy));
+       path = g_dbus_proxy_get_path(proxy);
+
+done:
+       gatt_list_attributes(path);
 
        return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
@@ -2601,8 +2610,8 @@ static const struct bt_shell_menu gatt_menu = {
        .name = "gatt",
        .desc = "Generic Attribute Submenu",
        .entries = {
-       { "list-attributes", "[dev]", cmd_list_attributes, "List attributes",
-                                                       dev_generator },
+       { "list-attributes", "[dev/local]", cmd_list_attributes,
+                               "List attributes", dev_generator },
        { "select-attribute", "<attribute/UUID>",  cmd_select_attribute,
                                "Select attribute", attribute_generator },
        { "attribute-info", "[attribute/UUID]",  cmd_attribute_info,