From: Szymon Janc <szymon.janc@codecoup.pl>
To: linux-bluetooth@vger.kernel.org
Cc: Szymon Janc <szymon.janc@codecoup.pl>
Subject: [PATCH V2 09/10] tools/btpclient: Store devices per adapter
Date: Fri, 8 Dec 2017 15:03:48 +0100 [thread overview]
Message-ID: <20171208140348.30342-10-szymon.janc@codecoup.pl> (raw)
In-Reply-To: <20171208140348.30342-1-szymon.janc@codecoup.pl>
This make it easier to handle devices from specified adapter.
---
tools/btpclient.c | 54 +++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 45 insertions(+), 9 deletions(-)
diff --git a/tools/btpclient.c b/tools/btpclient.c
index 50112c3a3..89b2d2801 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -39,6 +39,7 @@ struct btp_adapter {
uint8_t index;
uint32_t supported_settings;
uint32_t current_settings;
+ struct l_queue *devices;
};
struct btp_device {
@@ -46,7 +47,6 @@ struct btp_device {
};
static struct l_queue *adapters;
-static struct l_queue *devices;
static char *socket_path;
static struct btp *btp;
@@ -82,6 +82,21 @@ static struct btp_adapter *find_adapter_by_index(uint8_t index)
return NULL;
}
+static struct btp_adapter *find_adapter_by_path(const char *path)
+{
+ const struct l_queue_entry *entry;
+
+ for (entry = l_queue_get_entries(adapters); entry;
+ entry = entry->next) {
+ struct btp_adapter *adapter = entry->data;
+
+ if (!strcmp(l_dbus_proxy_get_path(adapter->proxy), path))
+ return adapter;
+ }
+
+ return NULL;
+}
+
static void btp_gap_read_commands(uint8_t index, const void *param,
uint16_t length, void *user_data)
{
@@ -469,14 +484,16 @@ static void signal_handler(struct l_signal *signal, uint32_t signo,
}
}
-static void btp_adapter_free(struct btp_adapter *adapter)
+static void btp_device_free(struct btp_device *device)
{
- l_free(adapter);
+ l_free(device);
}
-static void btp_device_free(struct btp_device *device)
+static void btp_adapter_free(struct btp_adapter *adapter)
{
- l_free(device);
+ l_queue_destroy(adapter->devices,
+ (l_queue_destroy_func_t)btp_device_free);
+ l_free(adapter);
}
static void extract_settings(struct l_dbus_proxy *proxy, uint32_t *current,
@@ -535,6 +552,7 @@ static void proxy_added(struct l_dbus_proxy *proxy, void *user_data)
adapter = l_new(struct btp_adapter, 1);
adapter->proxy = proxy;
adapter->index = l_queue_length(adapters);
+ adapter->devices = l_queue_new();
extract_settings(proxy, &adapter->current_settings,
&adapter->supported_settings);
@@ -544,12 +562,21 @@ static void proxy_added(struct l_dbus_proxy *proxy, void *user_data)
}
if (!strcmp(interface, "org.bluez.Device1")) {
+ struct btp_adapter *adapter;
struct btp_device *device;
+ char *str;
+
+ if (!l_dbus_proxy_get_property(proxy, "Adapter", "o", &str))
+ return;
+
+ adapter = find_adapter_by_path(str);
+ if (!adapter)
+ return;
device = l_new(struct btp_device, 1);
device->proxy = proxy;
- l_queue_push_tail(devices, device);
+ l_queue_push_tail(adapter->devices, device);
return;
}
}
@@ -576,7 +603,18 @@ static void proxy_removed(struct l_dbus_proxy *proxy, void *user_data)
}
if (!strcmp(interface, "org.bluez.Device1")) {
- l_queue_remove_if(devices, device_match_by_proxy, proxy);
+ struct btp_adapter *adapter;
+ char *str;
+
+ if (!l_dbus_proxy_get_property(proxy, "Adapter", "o", &str))
+ return;
+
+ adapter = find_adapter_by_path(str);
+ if (!adapter)
+ return;
+
+ l_queue_remove_if(adapter->devices, device_match_by_proxy,
+ proxy);
return;
}
@@ -742,7 +780,6 @@ int main(int argc, char *argv[])
adapters = l_queue_new();
- devices = l_queue_new();
sigemptyset(&mask);
sigaddset(&mask, SIGINT);
@@ -768,7 +805,6 @@ int main(int argc, char *argv[])
l_signal_remove(signal);
btp_cleanup(btp);
- l_queue_destroy(devices, (l_queue_destroy_func_t)btp_device_free);
l_queue_destroy(adapters, (l_queue_destroy_func_t)btp_adapter_free);
l_free(socket_path);
--
2.14.3
next prev parent reply other threads:[~2017-12-08 14:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-08 14:03 [PATCH V2 00/10] Initial code for BTP client Szymon Janc
2017-12-08 14:03 ` [PATCH V2 01/10] shared/btp: Add initial code for library Szymon Janc
2017-12-08 14:03 ` [PATCH V2 02/10] tools/btpclient: Add initial code Szymon Janc
2017-12-08 14:03 ` [PATCH V2 03/10] shared/btp: Add definitions for GAP service Szymon Janc
2017-12-08 14:03 ` [PATCH V2 04/10] tools/btpclient: Add initial support " Szymon Janc
2017-12-08 14:03 ` [PATCH V2 05/10] tools/btpclient: Add initial support for read controller info command Szymon Janc
2017-12-08 14:03 ` [PATCH V2 06/10] tools/btpclient: Get initial values for adapter setttings Szymon Janc
2017-12-08 14:03 ` [PATCH V2 07/10] tools/btpclient: Add support for tracking mutable adapter settings Szymon Janc
2017-12-08 14:03 ` [PATCH V2 08/10] tools/btpclient: Add support for configuring " Szymon Janc
2017-12-08 14:03 ` Szymon Janc [this message]
2017-12-14 9:12 ` [PATCH V2 00/10] Initial code for BTP client Szymon Janc
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=20171208140348.30342-10-szymon.janc@codecoup.pl \
--to=szymon.janc@codecoup.pl \
--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;
as well as URLs for NNTP newsgroup(s).