From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [RFC v2 11/12] client: Add support for DeviceSet proxy
Date: Tue, 7 Mar 2023 14:24:21 -0800 [thread overview]
Message-ID: <20230307222422.2608483-11-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20230307222422.2608483-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
client/main.c | 113 +++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 103 insertions(+), 10 deletions(-)
diff --git a/client/main.c b/client/main.c
index e5cf1e203ed1..e4a39896b2c6 100644
--- a/client/main.c
+++ b/client/main.c
@@ -51,6 +51,7 @@ struct adapter {
GDBusProxy *ad_proxy;
GDBusProxy *adv_monitor_proxy;
GList *devices;
+ GList *sets;
};
static struct adapter *default_ctrl;
@@ -232,7 +233,7 @@ static void print_experimental(GDBusProxy *proxy)
}
}
-static gboolean device_is_child(GDBusProxy *device, GDBusProxy *parent)
+static gboolean proxy_is_child(GDBusProxy *device, GDBusProxy *parent)
{
DBusMessageIter iter;
const char *adapter, *path;
@@ -269,14 +270,14 @@ static gboolean service_is_child(GDBusProxy *service)
"org.bluez.Device1") != NULL;
}
-static struct adapter *find_parent(GDBusProxy *device)
+static struct adapter *find_parent(GDBusProxy *proxy)
{
GList *list;
for (list = g_list_first(ctrl_list); list; list = g_list_next(list)) {
struct adapter *adapter = list->data;
- if (device_is_child(device, adapter->proxy) == TRUE)
+ if (proxy_is_child(proxy, adapter->proxy) == TRUE)
return adapter;
}
return NULL;
@@ -399,6 +400,27 @@ static void admon_manager_added(GDBusProxy *proxy)
adv_monitor_register_app(dbus_conn);
}
+static void print_set(GDBusProxy *proxy, const char *description)
+{
+ bt_shell_printf("%s%s%sDeviceSet %s\n",
+ description ? "[" : "",
+ description ? : "",
+ description ? "] " : "",
+ g_dbus_proxy_get_path(proxy));
+}
+
+static void set_added(GDBusProxy *proxy)
+{
+ struct adapter *adapter = find_parent(proxy);
+
+ if (!adapter)
+ return;
+
+ adapter->sets = g_list_append(adapter->sets, proxy);
+ print_set(proxy, COLORED_NEW);
+ bt_shell_set_env(g_dbus_proxy_get_path(proxy), proxy);
+}
+
static void proxy_added(GDBusProxy *proxy, void *user_data)
{
const char *interface;
@@ -434,6 +456,8 @@ static void proxy_added(GDBusProxy *proxy, void *user_data)
} else if (!strcmp(interface,
"org.bluez.AdvertisementMonitorManager1")) {
admon_manager_added(proxy);
+ } else if (!strcmp(interface, "org.bluez.DeviceSet1")) {
+ set_added(proxy);
}
}
@@ -484,6 +508,7 @@ static void adapter_removed(GDBusProxy *proxy)
ctrl_list = g_list_remove_link(ctrl_list, ll);
g_list_free(adapter->devices);
+ g_list_free(adapter->sets);
g_free(adapter);
g_list_free(ll);
return;
@@ -491,6 +516,19 @@ static void adapter_removed(GDBusProxy *proxy)
}
}
+static void set_removed(GDBusProxy *proxy)
+{
+ struct adapter *adapter = find_parent(proxy);
+
+ if (!adapter)
+ return;
+
+ adapter->sets = g_list_remove(adapter->sets, proxy);
+
+ print_set(proxy, COLORED_DEL);
+ bt_shell_set_env(g_dbus_proxy_get_path(proxy), NULL);
+}
+
static void proxy_removed(GDBusProxy *proxy, void *user_data)
{
const char *interface;
@@ -531,6 +569,8 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)
} else if (!strcmp(interface,
"org.bluez.AdvertisementMonitorManager1")) {
adv_monitor_remove_manager(dbus_conn);
+ } else if (!strcmp(interface, "org.bluez.DeviceSet1")) {
+ set_removed(proxy);
}
}
@@ -557,7 +597,7 @@ static void property_changed(GDBusProxy *proxy, const char *name,
interface = g_dbus_proxy_get_interface(proxy);
if (!strcmp(interface, "org.bluez.Device1")) {
- if (default_ctrl && device_is_child(proxy,
+ if (default_ctrl && proxy_is_child(proxy,
default_ctrl->proxy) == TRUE) {
DBusMessageIter addr_iter;
char *str;
@@ -1559,6 +1599,39 @@ static struct GDBusProxy *find_device(int argc, char *argv[])
return proxy;
}
+static struct GDBusProxy *find_set(int argc, char *argv[])
+{
+ GDBusProxy *proxy;
+
+ if (check_default_ctrl() == FALSE)
+ return NULL;
+
+ proxy = find_proxies_by_path(default_ctrl->sets, argv[1]);
+ if (!proxy) {
+ bt_shell_printf("DeviceSet %s not available\n", argv[1]);
+ return NULL;
+ }
+
+ return proxy;
+}
+
+static void cmd_set_info(int argc, char *argv[])
+{
+ GDBusProxy *proxy;
+
+ proxy = find_set(argc, argv);
+ if (!proxy)
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+ bt_shell_printf("DeviceSet %s\n", g_dbus_proxy_get_path(proxy));
+
+ print_property(proxy, "AutoConnect");
+ print_property(proxy, "Devices");
+ print_property(proxy, "Size");
+
+ return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
+
static void cmd_info(int argc, char *argv[])
{
GDBusProxy *proxy;
@@ -1568,7 +1641,7 @@ static void cmd_info(int argc, char *argv[])
proxy = find_device(argc, argv);
if (!proxy)
- return bt_shell_noninteractive_quit(EXIT_FAILURE);
+ return cmd_set_info(argc, argv);
if (g_dbus_proxy_get_property(proxy, "Address", &iter) == FALSE)
return bt_shell_noninteractive_quit(EXIT_FAILURE);
@@ -1605,6 +1678,7 @@ static void cmd_info(int argc, char *argv[])
print_property(proxy, "TxPower");
print_property(proxy, "AdvertisingFlags");
print_property(proxy, "AdvertisingData");
+ print_property(proxy, "Sets");
battery_proxy = find_proxies_by_path(battery_proxies,
g_dbus_proxy_get_path(proxy));
@@ -2298,11 +2372,13 @@ static char *generic_generator(const char *text, int state,
index++;
- if (g_dbus_proxy_get_property(proxy, property, &iter) == FALSE)
+ if (!property)
+ str = g_dbus_proxy_get_path(proxy);
+ else if (g_dbus_proxy_get_property(proxy, property, &iter))
+ dbus_message_iter_get_basic(&iter, &str);
+ else
continue;
- dbus_message_iter_get_basic(&iter, &str);
-
if (!strncasecmp(str, text, len))
return strdup(str);
}
@@ -2348,6 +2424,23 @@ static char *dev_generator(const char *text, int state)
default_ctrl ? default_ctrl->devices : NULL, "Address");
}
+static char *set_generator(const char *text, int state)
+{
+ return generic_generator(text, state,
+ default_ctrl ? default_ctrl->sets : NULL, NULL);
+}
+
+static char *dev_set_generator(const char *text, int state)
+{
+ char *str;
+
+ str = dev_generator(text, state);
+ if (str)
+ return str;
+
+ return set_generator(text, state);
+}
+
static char *attribute_generator(const char *text, int state)
{
return gatt_attribute_generator(text, state);
@@ -2965,8 +3058,8 @@ static const struct bt_shell_menu main_menu = {
{ "set-alias", "<alias>", cmd_set_alias, "Set device alias" },
{ "scan", "<on/off/bredr/le>", cmd_scan,
"Scan for devices", scan_generator },
- { "info", "[dev]", cmd_info, "Device information",
- dev_generator },
+ { "info", "[dev/set]", cmd_info, "Device/Set information",
+ dev_set_generator },
{ "pair", "[dev]", cmd_pair, "Pair with device",
dev_generator },
{ "cancel-pairing", "[dev]", cmd_cancel_pairing,
--
2.39.2
next prev parent reply other threads:[~2023-03-07 22:26 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-07 22:24 [RFC v2 01/12] shared/crypto: Add bt_crypto_sirk Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 02/12] shared/ad: Add RSI data type Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 03/12] doc: Add set-api Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 04/12] device-api: Add Set property Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 05/12] core: Add initial implementation of DeviceSet interface Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 06/12] core: Check if device has RSI Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 07/12] main.conf: Add CSIP profile configurable options Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 08/12] shared/csip: Add initial code for handling CSIP Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 09/12] profiles: Add initial code for csip plugin Luiz Augusto von Dentz
2023-03-07 22:24 ` [RFC v2 10/12] tools: Add support to generate RSI using SIRK Luiz Augusto von Dentz
2023-03-07 22:24 ` Luiz Augusto von Dentz [this message]
2023-03-07 22:24 ` [RFC v2 12/12] client: Use AdvertisingFlags when available Luiz Augusto von Dentz
2023-03-08 2:12 ` [RFC,v2,01/12] shared/crypto: Add bt_crypto_sirk bluez.test.bot
2023-03-11 0:40 ` [RFC v2 01/12] " patchwork-bot+bluetooth
2023-03-13 5:36 ` Luiz Augusto von Dentz
2023-03-13 23:29 ` Pauli Virtanen
2023-03-14 0:18 ` Luiz Augusto von Dentz
2023-03-14 0:57 ` Pauli Virtanen
2023-04-06 0:16 ` Luiz Augusto von Dentz
2023-04-06 18:08 ` Pauli Virtanen
2023-04-06 20:14 ` Luiz Augusto von Dentz
2023-04-13 18:48 ` Luiz Augusto von Dentz
2023-04-13 21:14 ` Pauli Virtanen
2023-04-14 21:56 ` Luiz Augusto von Dentz
2023-04-15 14:57 ` Pauli Virtanen
2023-04-13 20:11 ` Pauli Virtanen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230307222422.2608483-11-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox