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 11/16] network: Replace list with network_adapter
Date: Tue, 25 Jun 2013 18:24:44 +0200 [thread overview]
Message-ID: <1372177489-6858-12-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>
Trivially refactor the code such that find_server() receives a pointer
to struct network_adapter instead of a GSList, given that the codebase
always searches within the network_adapter->servers list.
---
profiles/network/server.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/profiles/network/server.c b/profiles/network/server.c
index de48bec..ace31c5 100644
--- a/profiles/network/server.c
+++ b/profiles/network/server.c
@@ -97,9 +97,12 @@ static struct network_adapter *find_adapter(GSList *list,
return NULL;
}
-static struct network_server *find_server(GSList *list, uint16_t id)
+static struct network_server *find_server(struct network_adapter *na,
+ uint16_t id)
{
- for (; list; list = list->next) {
+ GSList *list;
+
+ for (list = na->servers; list; list = list->next) {
struct network_server *ns = list->data;
if (ns->id == id)
@@ -109,10 +112,12 @@ static struct network_server *find_server(GSList *list, uint16_t id)
return NULL;
}
-static struct network_server *find_server_by_uuid(GSList *list,
+static struct network_server *find_server_by_uuid(struct network_adapter *na,
const char *uuid)
{
- for (; list; list = list->next) {
+ GSList *list;
+
+ for (list = na->servers; list; list = list->next) {
struct network_server *ns = list->data;
if (strcasecmp(uuid, bnep_uuid(ns->id)) == 0)
@@ -441,7 +446,7 @@ static gboolean bnep_setup(GIOChannel *chan,
rsp = BNEP_CONN_NOT_ALLOWED;
- ns = find_server(na->servers, dst_role);
+ ns = find_server(na, dst_role);
if (!ns) {
error("Server unavailable: (0x%x)", dst_role);
goto reply;
@@ -538,7 +543,7 @@ static void confirm_event(GIOChannel *chan, gpointer user_data)
goto drop;
}
- ns = find_server(na->servers, BNEP_SVC_NAP);
+ ns = find_server(na, BNEP_SVC_NAP);
if (!ns)
goto drop;
@@ -648,7 +653,7 @@ static DBusMessage *register_server(DBusConnection *conn,
DBUS_TYPE_STRING, &bridge, DBUS_TYPE_INVALID))
return btd_error_invalid_args(msg);
- ns = find_server_by_uuid(na->servers, uuid);
+ ns = find_server_by_uuid(na, uuid);
if (ns == NULL)
return btd_error_failed(msg, "Invalid UUID");
@@ -685,7 +690,7 @@ static DBusMessage *unregister_server(DBusConnection *conn,
DBUS_TYPE_INVALID))
return btd_error_invalid_args(msg);
- ns = find_server_by_uuid(na->servers, uuid);
+ ns = find_server_by_uuid(na, uuid);
if (!ns)
return btd_error_failed(msg, "Invalid UUID");
@@ -795,7 +800,7 @@ int server_register(struct btd_adapter *adapter, uint16_t id)
adapters = g_slist_append(adapters, na);
}
- ns = find_server(na->servers, id);
+ ns = find_server(na, id);
if (ns)
return 0;
@@ -840,7 +845,7 @@ int server_unregister(struct btd_adapter *adapter, uint16_t id)
if (!na)
return -EINVAL;
- ns = find_server(na->servers, id);
+ ns = find_server(na, id);
if (!ns)
return -EINVAL;
--
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 ` [RFC BlueZ v0 08/16] cyclingspeed: " Mikel Astiz
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 ` Mikel Astiz [this message]
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-12-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).