linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 12/16] network: Bypass manager for profile server
Date: Tue, 25 Jun 2013 18:24:45 +0200	[thread overview]
Message-ID: <1372177489-6858-13-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 adopt the btd_profile signature regarding adapter probe in
server.h in order to avoid boilerplate code in manager.c.
---
 profiles/network/manager.c | 72 ++++------------------------------------------
 profiles/network/server.c  | 32 ++++++++++++++-------
 profiles/network/server.h  |  4 +--
 3 files changed, 30 insertions(+), 78 deletions(-)

diff --git a/profiles/network/manager.c b/profiles/network/manager.c
index 1ec2db2..4f897dd 100644
--- a/profiles/network/manager.c
+++ b/profiles/network/manager.c
@@ -75,66 +75,6 @@ done:
 				conf_security ? "true" : "false");
 }
 
-static int panu_server_probe(struct btd_server *server)
-{
-	struct btd_adapter *adapter = btd_server_get_adapter(server);
-	const char *path = adapter_get_path(adapter);
-
-	DBG("path %s", path);
-
-	return server_register(adapter, BNEP_SVC_PANU);
-}
-
-static void panu_server_remove(struct btd_server *server)
-{
-	struct btd_adapter *adapter = btd_server_get_adapter(server);
-	const char *path = adapter_get_path(adapter);
-
-	DBG("path %s", path);
-
-	server_unregister(adapter, BNEP_SVC_PANU);
-}
-
-static int gn_server_probe(struct btd_server *server)
-{
-	struct btd_adapter *adapter = btd_server_get_adapter(server);
-	const char *path = adapter_get_path(adapter);
-
-	DBG("path %s", path);
-
-	return server_register(adapter, BNEP_SVC_GN);
-}
-
-static void gn_server_remove(struct btd_server *server)
-{
-	struct btd_adapter *adapter = btd_server_get_adapter(server);
-	const char *path = adapter_get_path(adapter);
-
-	DBG("path %s", path);
-
-	server_unregister(adapter, BNEP_SVC_GN);
-}
-
-static int nap_server_probe(struct btd_server *server)
-{
-	struct btd_adapter *adapter = btd_server_get_adapter(server);
-	const char *path = adapter_get_path(adapter);
-
-	DBG("path %s", path);
-
-	return server_register(adapter, BNEP_SVC_NAP);
-}
-
-static void nap_server_remove(struct btd_server *server)
-{
-	struct btd_adapter *adapter = btd_server_get_adapter(server);
-	const char *path = adapter_get_path(adapter);
-
-	DBG("path %s", path);
-
-	server_unregister(adapter, BNEP_SVC_NAP);
-}
-
 static struct btd_profile panu_profile = {
 	.name		= "network-panu",
 	.local_uuid	= NAP_UUID,
@@ -143,8 +83,8 @@ static struct btd_profile panu_profile = {
 	.device_remove	= connection_unregister,
 	.connect	= connection_connect,
 	.disconnect	= connection_disconnect,
-	.adapter_probe	= panu_server_probe,
-	.adapter_remove	= panu_server_remove,
+	.adapter_probe	= network_server_probe,
+	.adapter_remove	= network_server_remove,
 };
 
 static struct btd_profile gn_profile = {
@@ -155,8 +95,8 @@ static struct btd_profile gn_profile = {
 	.device_remove	= connection_unregister,
 	.connect	= connection_connect,
 	.disconnect	= connection_disconnect,
-	.adapter_probe	= gn_server_probe,
-	.adapter_remove	= gn_server_remove,
+	.adapter_probe	= network_server_probe,
+	.adapter_remove	= network_server_remove,
 };
 
 static struct btd_profile nap_profile = {
@@ -167,8 +107,8 @@ static struct btd_profile nap_profile = {
 	.device_remove	= connection_unregister,
 	.connect	= connection_connect,
 	.disconnect	= connection_disconnect,
-	.adapter_probe	= nap_server_probe,
-	.adapter_remove	= nap_server_remove,
+	.adapter_probe	= network_server_probe,
+	.adapter_remove	= network_server_remove,
 };
 
 static int network_init(void)
diff --git a/profiles/network/server.c b/profiles/network/server.c
index ace31c5..a0b7754 100644
--- a/profiles/network/server.c
+++ b/profiles/network/server.c
@@ -43,6 +43,8 @@
 #include "lib/uuid.h"
 #include "../src/dbus-common.h"
 #include "../src/adapter.h"
+#include "../src/profile.h"
+#include "../src/server.h"
 
 #include "log.h"
 #include "error.h"
@@ -786,11 +788,18 @@ static struct network_adapter *create_adapter(struct btd_adapter *adapter)
 	return na;
 }
 
-int server_register(struct btd_adapter *adapter, uint16_t id)
+int network_server_probe(struct btd_server *server)
 {
+	struct btd_adapter *adapter = btd_server_get_adapter(server);
 	struct network_adapter *na;
 	struct network_server *ns;
-	const char *path;
+	const char *path = adapter_get_path(adapter);
+	const char *uuid = btd_server_get_profile(server)->remote_uuid;
+	uint16_t id;
+
+	DBG("path %s uuid %s", path, uuid);
+
+	id = bnep_service_id(uuid);
 
 	na = find_adapter(adapters, adapter);
 	if (!na) {
@@ -808,8 +817,6 @@ int server_register(struct btd_adapter *adapter, uint16_t id)
 
 	ns->name = g_strdup("Network service");
 
-	path = adapter_get_path(adapter);
-
 	if (g_slist_length(na->servers) > 0)
 		goto done;
 
@@ -836,28 +843,33 @@ done:
 	return 0;
 }
 
-int server_unregister(struct btd_adapter *adapter, uint16_t id)
+void network_server_remove(struct btd_server *server)
 {
+	struct btd_adapter *adapter = btd_server_get_adapter(server);
 	struct network_adapter *na;
 	struct network_server *ns;
+	const char *uuid = btd_server_get_profile(server)->remote_uuid;
+	uint16_t id;
+
+	DBG("path %s uuid %s", adapter_get_path(adapter), uuid);
+
+	id = bnep_service_id(uuid);
 
 	na = find_adapter(adapters, adapter);
 	if (!na)
-		return -EINVAL;
+		return;
 
 	ns = find_server(na, id);
 	if (!ns)
-		return -EINVAL;
+		return;
 
 	na->servers = g_slist_remove(na->servers, ns);
 	server_free(ns);
 
 	if (g_slist_length(na->servers) > 0)
-		return 0;
+		return;
 
 	g_dbus_unregister_interface(btd_get_dbus_connection(),
 						adapter_get_path(adapter),
 						NETWORK_SERVER_INTERFACE);
-
-	return 0;
 }
diff --git a/profiles/network/server.h b/profiles/network/server.h
index 2edd342..2d8b41c 100644
--- a/profiles/network/server.h
+++ b/profiles/network/server.h
@@ -23,5 +23,5 @@
 
 int server_init(gboolean secure);
 void server_exit(void);
-int server_register(struct btd_adapter *adapter, uint16_t id);
-int server_unregister(struct btd_adapter *adapter, uint16_t id);
+int network_server_probe(struct btd_server *server);
+void network_server_remove(struct btd_server *server);
-- 
1.8.1.4


  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 ` [RFC BlueZ v0 11/16] network: Replace list with network_adapter Mikel Astiz
2013-06-25 16:24 ` Mikel Astiz [this message]
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-13-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).