From: Mikel Astiz <mikel.astiz.oss@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Mikel Astiz <mikel.astiz@bmw-carit.de>
Subject: [RFC BlueZ v0 08/16] cyclingspeed: Use btd_server userdata
Date: Tue, 25 Jun 2013 18:24:41 +0200 [thread overview]
Message-ID: <1372177489-6858-9-git-send-email-mikel.astiz.oss@gmail.com> (raw)
In-Reply-To: <1372177489-6858-1-git-send-email-mikel.astiz.oss@gmail.com>
From: Mikel Astiz <mikel.astiz@bmw-carit.de>
Exploit the userdata pointer to avoid maintainig a list with instances
of struct csc_adapter.
---
profiles/cyclingspeed/cyclingspeed.c | 32 +++++++-------------------------
1 file changed, 7 insertions(+), 25 deletions(-)
diff --git a/profiles/cyclingspeed/cyclingspeed.c b/profiles/cyclingspeed/cyclingspeed.c
index 14c2df7..8b7e2e1 100644
--- a/profiles/cyclingspeed/cyclingspeed.c
+++ b/profiles/cyclingspeed/cyclingspeed.c
@@ -138,8 +138,6 @@ struct characteristic {
char uuid[MAX_LEN_UUID_STR + 1];
};
-static GSList *csc_adapters = NULL;
-
static const char * const location_enum[] = {
"other", "top-of-shoe", "in-shoe", "hip", "front-wheel", "left-crank",
"right-crank", "left-pedal", "right-pedal", "front-hub",
@@ -167,17 +165,6 @@ static int str2location(const char *location)
return -1;
}
-static int cmp_adapter(gconstpointer a, gconstpointer b)
-{
- const struct csc_adapter *cadapter = a;
- const struct btd_adapter *adapter = b;
-
- if (adapter == cadapter->adapter)
- return 0;
-
- return -1;
-}
-
static int cmp_device(gconstpointer a, gconstpointer b)
{
const struct csc *csc = a;
@@ -204,12 +191,13 @@ static int cmp_watcher(gconstpointer a, gconstpointer b)
static struct csc_adapter *find_csc_adapter(struct btd_adapter *adapter)
{
- GSList *l = g_slist_find_custom(csc_adapters, adapter, cmp_adapter);
+ struct btd_server *server;
- if (!l)
+ server = btd_adapter_get_server(adapter, CYCLING_SC_UUID);
+ if (server == NULL)
return NULL;
- return l->data;
+ return btd_server_get_user_data(server);
}
static void destroy_watcher(gpointer user_data)
@@ -978,21 +966,14 @@ static int csc_adapter_probe(struct btd_server *server)
return -EIO;
}
- csc_adapters = g_slist_prepend(csc_adapters, cadapter);
+ btd_server_set_user_data(server, cadapter);
return 0;
}
static void csc_adapter_remove(struct btd_server *server)
{
- struct btd_adapter *adapter = btd_server_get_adapter(server);
- struct csc_adapter *cadapter;
-
- cadapter = find_csc_adapter(adapter);
- if (cadapter == NULL)
- return;
-
- csc_adapters = g_slist_remove(csc_adapters, cadapter);
+ struct csc_adapter *cadapter = btd_server_get_user_data(server);
g_dbus_unregister_interface(btd_get_dbus_connection(),
adapter_get_path(cadapter->adapter),
@@ -1259,6 +1240,7 @@ static void csc_device_remove(struct btd_service *service)
static struct btd_profile cscp_profile = {
.name = "Cycling Speed and Cadence GATT Driver",
+ .local_uuid = CYCLING_SC_UUID,
.remote_uuid = CYCLING_SC_UUID,
.adapter_probe = csc_adapter_probe,
--
1.8.1.4
next prev parent reply other threads:[~2013-06-25 16:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-25 16:24 [RFC BlueZ v0 00/16] Introduce btd_server Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 01/16] core: Add btd_server Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 02/16] adapter: Create btd_server instances when probing Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 03/16] profile: Use btd_server to probe adapters Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 04/16] input: Bypass manager for profile server Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 05/16] input: Use btd_server userdata for input_server Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 06/16] thermometer: Remove boilerplate code Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 07/16] thermometer: Use btd_server userdata Mikel Astiz
2013-06-25 16:24 ` Mikel Astiz [this message]
2013-06-25 16:24 ` [RFC BlueZ v0 09/16] heartrate: Remove boilerplate code Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 10/16] heartrate: Use btd_server userdata Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 11/16] network: Replace list with network_adapter Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 12/16] network: Bypass manager for profile server Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 13/16] network: Simplify search-by-UUID Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 14/16] network: Add a dedicated btd_profile for BNEP Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 15/16] network: Create network_adapter during BNEP probe Mikel Astiz
2013-06-25 16:24 ` [RFC BlueZ v0 16/16] network: Use btd_server userdata for network_server Mikel Astiz
2013-07-02 7:11 ` [RFC BlueZ v0 00/16] Introduce btd_server Mikel Astiz
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=1372177489-6858-9-git-send-email-mikel.astiz.oss@gmail.com \
--to=mikel.astiz.oss@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=mikel.astiz@bmw-carit.de \
/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).