mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-15 08:14:28 +08:00
client: Use selected attribute when selecting by UUID
There could be multiple instances of the same UUID, like e.g CCC and CEP, so instead of matching the first one found from the beginning this uses the current selected attribute as parent looking up existing child attributes first.
This commit is contained in:
parent
7dd5e10bf3
commit
d4ecd13f8c
@ -314,7 +314,8 @@ static GDBusProxy *select_attribute(const char *path)
|
||||
return select_proxy(path, descriptors);
|
||||
}
|
||||
|
||||
static GDBusProxy *select_proxy_by_uuid(const char *uuid, GList *source)
|
||||
static GDBusProxy *select_proxy_by_uuid(GDBusProxy *parent, const char *uuid,
|
||||
GList *source)
|
||||
{
|
||||
GList *l;
|
||||
const char *value;
|
||||
@ -323,6 +324,10 @@ static GDBusProxy *select_proxy_by_uuid(const char *uuid, GList *source)
|
||||
for (l = source; l; l = g_list_next(l)) {
|
||||
GDBusProxy *proxy = l->data;
|
||||
|
||||
if (parent && !g_str_has_prefix(g_dbus_proxy_get_path(proxy),
|
||||
g_dbus_proxy_get_path(parent)))
|
||||
continue;
|
||||
|
||||
if (g_dbus_proxy_get_property(proxy, "UUID", &iter) == FALSE)
|
||||
continue;
|
||||
|
||||
@ -335,27 +340,34 @@ static GDBusProxy *select_proxy_by_uuid(const char *uuid, GList *source)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GDBusProxy *select_attribute_by_uuid(const char *uuid)
|
||||
static GDBusProxy *select_attribute_by_uuid(GDBusProxy *parent,
|
||||
const char *uuid)
|
||||
{
|
||||
GDBusProxy *proxy;
|
||||
|
||||
proxy = select_proxy_by_uuid(uuid, services);
|
||||
proxy = select_proxy_by_uuid(parent, uuid, services);
|
||||
if (proxy)
|
||||
return proxy;
|
||||
|
||||
proxy = select_proxy_by_uuid(uuid, characteristics);
|
||||
proxy = select_proxy_by_uuid(parent, uuid, characteristics);
|
||||
if (proxy)
|
||||
return proxy;
|
||||
|
||||
return select_proxy_by_uuid(uuid, descriptors);
|
||||
return select_proxy_by_uuid(parent, uuid, descriptors);
|
||||
}
|
||||
|
||||
GDBusProxy *gatt_select_attribute(const char *arg)
|
||||
GDBusProxy *gatt_select_attribute(GDBusProxy *parent, const char *arg)
|
||||
{
|
||||
if (arg[0] == '/')
|
||||
return select_attribute(arg);
|
||||
|
||||
return select_attribute_by_uuid(arg);
|
||||
if (parent) {
|
||||
GDBusProxy *proxy = select_attribute_by_uuid(parent, arg);
|
||||
if (proxy)
|
||||
return proxy;
|
||||
}
|
||||
|
||||
return select_attribute_by_uuid(parent, arg);
|
||||
}
|
||||
|
||||
static char *attribute_generator(const char *text, int state, GList *source)
|
||||
|
@ -31,7 +31,7 @@ void gatt_add_descriptor(GDBusProxy *proxy);
|
||||
void gatt_remove_descriptor(GDBusProxy *proxy);
|
||||
|
||||
void gatt_list_attributes(const char *device);
|
||||
GDBusProxy *gatt_select_attribute(const char *path);
|
||||
GDBusProxy *gatt_select_attribute(GDBusProxy *parent, const char *path);
|
||||
char *gatt_attribute_generator(const char *text, int state);
|
||||
|
||||
void gatt_read_attribute(GDBusProxy *proxy);
|
||||
|
@ -1704,7 +1704,7 @@ static void cmd_select_attribute(const char *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
proxy = gatt_select_attribute(arg);
|
||||
proxy = gatt_select_attribute(default_attr, arg);
|
||||
if (proxy)
|
||||
set_default_attribute(proxy);
|
||||
}
|
||||
@ -1720,7 +1720,7 @@ static struct GDBusProxy *find_attribute(const char *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
proxy = gatt_select_attribute(arg);
|
||||
proxy = gatt_select_attribute(default_attr, arg);
|
||||
if (!proxy) {
|
||||
rl_printf("Attribute %s not available\n", arg);
|
||||
return NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user