All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/2] client: Add support to pass UUIDs to select-attribute
@ 2017-03-14 11:52 Luiz Augusto von Dentz
  2017-03-14 11:52 ` [PATCH BlueZ 2/2] client: Use selected attribute when selecting by UUID Luiz Augusto von Dentz
  2017-03-15 15:23 ` [PATCH BlueZ 1/2] client: Add support to pass UUIDs to select-attribute Luiz Augusto von Dentz
  0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2017-03-14 11:52 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds support to match attributes by UUID instead of object path.
---
 client/gatt.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 client/main.c |  4 ++--
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/client/gatt.c b/client/gatt.c
index 37f222d..f7a2f0c 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -299,7 +299,7 @@ static GDBusProxy *select_proxy(const char *path, GList *source)
 	return NULL;
 }
 
-GDBusProxy *gatt_select_attribute(const char *path)
+static GDBusProxy *select_attribute(const char *path)
 {
 	GDBusProxy *proxy;
 
@@ -314,6 +314,50 @@ GDBusProxy *gatt_select_attribute(const char *path)
 	return select_proxy(path, descriptors);
 }
 
+static GDBusProxy *select_proxy_by_uuid(const char *uuid, GList *source)
+{
+	GList *l;
+	const char *value;
+	DBusMessageIter iter;
+
+	for (l = source; l; l = g_list_next(l)) {
+		GDBusProxy *proxy = l->data;
+
+		if (g_dbus_proxy_get_property(proxy, "UUID", &iter) == FALSE)
+			continue;
+
+		dbus_message_iter_get_basic(&iter, &value);
+
+		if (strcasecmp(uuid, value) == 0)
+			return proxy;
+	}
+
+	return NULL;
+}
+
+static GDBusProxy *select_attribute_by_uuid(const char *uuid)
+{
+	GDBusProxy *proxy;
+
+	proxy = select_proxy_by_uuid(uuid, services);
+	if (proxy)
+		return proxy;
+
+	proxy = select_proxy_by_uuid(uuid, characteristics);
+	if (proxy)
+		return proxy;
+
+	return select_proxy_by_uuid(uuid, descriptors);
+}
+
+GDBusProxy *gatt_select_attribute(const char *arg)
+{
+	if (arg[0] == '/')
+		return select_attribute(arg);
+
+	return select_attribute_by_uuid(arg);
+}
+
 static char *attribute_generator(const char *text, int state, GList *source)
 {
 	static int index, len;
diff --git a/client/main.c b/client/main.c
index e1198a8..d01e5fa 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2130,9 +2130,9 @@ static const struct {
 	{ "list-attributes", "[dev]", cmd_list_attributes, "List attributes",
 							dev_generator },
 	{ "set-alias",    "<alias>",  cmd_set_alias, "Set device alias" },
-	{ "select-attribute", "<attribute>",  cmd_select_attribute,
+	{ "select-attribute", "<attribute/UUID>",  cmd_select_attribute,
 				"Select attribute", attribute_generator },
-	{ "attribute-info", "[attribute]",  cmd_attribute_info,
+	{ "attribute-info", "[attribute/UUID]",  cmd_attribute_info,
 				"Select attribute", attribute_generator },
 	{ "read",         NULL,       cmd_read, "Read attribute value" },
 	{ "write",        "<data=[xx xx ...]>", cmd_write,
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH BlueZ 2/2] client: Use selected attribute when selecting by UUID
  2017-03-14 11:52 [PATCH BlueZ 1/2] client: Add support to pass UUIDs to select-attribute Luiz Augusto von Dentz
@ 2017-03-14 11:52 ` Luiz Augusto von Dentz
  2017-03-15 15:23 ` [PATCH BlueZ 1/2] client: Add support to pass UUIDs to select-attribute Luiz Augusto von Dentz
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2017-03-14 11:52 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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.
---
 client/gatt.c | 26 +++++++++++++++++++-------
 client/gatt.h |  2 +-
 client/main.c |  4 ++--
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/client/gatt.c b/client/gatt.c
index f7a2f0c..79bc7a3 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -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)
diff --git a/client/gatt.h b/client/gatt.h
index 689bb4d..7a91975 100644
--- a/client/gatt.h
+++ b/client/gatt.h
@@ -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);
diff --git a/client/main.c b/client/main.c
index d01e5fa..857c111 100644
--- a/client/main.c
+++ b/client/main.c
@@ -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;
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH BlueZ 1/2] client: Add support to pass UUIDs to select-attribute
  2017-03-14 11:52 [PATCH BlueZ 1/2] client: Add support to pass UUIDs to select-attribute Luiz Augusto von Dentz
  2017-03-14 11:52 ` [PATCH BlueZ 2/2] client: Use selected attribute when selecting by UUID Luiz Augusto von Dentz
@ 2017-03-15 15:23 ` Luiz Augusto von Dentz
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2017-03-15 15:23 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Tue, Mar 14, 2017 at 1:52 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> This adds support to match attributes by UUID instead of object path.
> ---
>  client/gatt.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
>  client/main.c |  4 ++--
>  2 files changed, 47 insertions(+), 3 deletions(-)
>
> diff --git a/client/gatt.c b/client/gatt.c
> index 37f222d..f7a2f0c 100644
> --- a/client/gatt.c
> +++ b/client/gatt.c
> @@ -299,7 +299,7 @@ static GDBusProxy *select_proxy(const char *path, GList *source)
>         return NULL;
>  }
>
> -GDBusProxy *gatt_select_attribute(const char *path)
> +static GDBusProxy *select_attribute(const char *path)
>  {
>         GDBusProxy *proxy;
>
> @@ -314,6 +314,50 @@ GDBusProxy *gatt_select_attribute(const char *path)
>         return select_proxy(path, descriptors);
>  }
>
> +static GDBusProxy *select_proxy_by_uuid(const char *uuid, GList *source)
> +{
> +       GList *l;
> +       const char *value;
> +       DBusMessageIter iter;
> +
> +       for (l = source; l; l = g_list_next(l)) {
> +               GDBusProxy *proxy = l->data;
> +
> +               if (g_dbus_proxy_get_property(proxy, "UUID", &iter) == FALSE)
> +                       continue;
> +
> +               dbus_message_iter_get_basic(&iter, &value);
> +
> +               if (strcasecmp(uuid, value) == 0)
> +                       return proxy;
> +       }
> +
> +       return NULL;
> +}
> +
> +static GDBusProxy *select_attribute_by_uuid(const char *uuid)
> +{
> +       GDBusProxy *proxy;
> +
> +       proxy = select_proxy_by_uuid(uuid, services);
> +       if (proxy)
> +               return proxy;
> +
> +       proxy = select_proxy_by_uuid(uuid, characteristics);
> +       if (proxy)
> +               return proxy;
> +
> +       return select_proxy_by_uuid(uuid, descriptors);
> +}
> +
> +GDBusProxy *gatt_select_attribute(const char *arg)
> +{
> +       if (arg[0] == '/')
> +               return select_attribute(arg);
> +
> +       return select_attribute_by_uuid(arg);
> +}
> +
>  static char *attribute_generator(const char *text, int state, GList *source)
>  {
>         static int index, len;
> diff --git a/client/main.c b/client/main.c
> index e1198a8..d01e5fa 100644
> --- a/client/main.c
> +++ b/client/main.c
> @@ -2130,9 +2130,9 @@ static const struct {
>         { "list-attributes", "[dev]", cmd_list_attributes, "List attributes",
>                                                         dev_generator },
>         { "set-alias",    "<alias>",  cmd_set_alias, "Set device alias" },
> -       { "select-attribute", "<attribute>",  cmd_select_attribute,
> +       { "select-attribute", "<attribute/UUID>",  cmd_select_attribute,
>                                 "Select attribute", attribute_generator },
> -       { "attribute-info", "[attribute]",  cmd_attribute_info,
> +       { "attribute-info", "[attribute/UUID]",  cmd_attribute_info,
>                                 "Select attribute", attribute_generator },
>         { "read",         NULL,       cmd_read, "Read attribute value" },
>         { "write",        "<data=[xx xx ...]>", cmd_write,
> --
> 2.9.3


Applied.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-15 15:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-14 11:52 [PATCH BlueZ 1/2] client: Add support to pass UUIDs to select-attribute Luiz Augusto von Dentz
2017-03-14 11:52 ` [PATCH BlueZ 2/2] client: Use selected attribute when selecting by UUID Luiz Augusto von Dentz
2017-03-15 15:23 ` [PATCH BlueZ 1/2] client: Add support to pass UUIDs to select-attribute Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.