From: ERAMOTO Masaya <eramoto.masaya@jp.fujitsu.com>
To: Yunhan Wang <yunhanw@google.com>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: [PATCH BlueZ v4] client: Fix default_ctrl change when new adapter is found
Date: Thu, 14 Sep 2017 11:50:49 +0900 [thread overview]
Message-ID: <ca2a0377-e617-e586-bf25-5a0df4fcc677@jp.fujitsu.com> (raw)
Since 4e111f3448a126786f3620be1b5ce969456edc65, when another adapter is
found, the default adapter would be changed, which is not expected.
Default adapter can only be changed by select command.
---
client/main.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
v4: add adapter_new() which allocates memory for a new adapter.
call find_ctrl() to find out the exist adapter.
diff --git a/client/main.c b/client/main.c
index 87eb131..2cb449f 100644
--- a/client/main.c
+++ b/client/main.c
@@ -525,17 +525,40 @@ static void device_added(GDBusProxy *proxy)
}
}
+static struct adapter *find_ctrl(GList *source, const char *path);
+
+static struct adapter *adapter_new(GDBusProxy *proxy)
+{
+ struct adapter *adapter = g_malloc0(sizeof(struct adapter));
+
+ ctrl_list = g_list_append(ctrl_list, adapter);
+
+ if (!default_ctrl)
+ default_ctrl = adapter;
+
+ return adapter;
+}
+
static void adapter_added(GDBusProxy *proxy)
{
- default_ctrl = g_malloc0(sizeof(struct adapter));
- default_ctrl->proxy = proxy;
- ctrl_list = g_list_append(ctrl_list, default_ctrl);
+ struct adapter *adapter;
+ adapter = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));
+ if (!adapter)
+ adapter = adapter_new(proxy);
+
+ adapter->proxy = proxy;
+
print_adapter(proxy, COLORED_NEW);
}
static void ad_manager_added(GDBusProxy *proxy)
{
- default_ctrl->ad_proxy = proxy;
+ struct adapter *adapter;
+ adapter = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));
+ if (!adapter)
+ adapter = adapter_new(proxy);
+
+ adapter->ad_proxy = proxy;
}
static void proxy_added(GDBusProxy *proxy, void *user_data)
--
2.7.4
next reply other threads:[~2017-09-14 2:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-14 2:50 ERAMOTO Masaya [this message]
2017-09-14 8:23 ` [PATCH BlueZ v4] client: Fix default_ctrl change when new adapter is found Luiz Augusto von Dentz
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=ca2a0377-e617-e586-bf25-5a0df4fcc677@jp.fujitsu.com \
--to=eramoto.masaya@jp.fujitsu.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=yunhanw@google.com \
/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