Diff between 0819e1aafdbabf36ac2e45fa908b97523495a253 and dc288fc6589bcf92d16682bf3225bfc27b9e9888

Changed Files

File Additions Deletions Status
Makefile.plugins +1 -2 modified
profiles/network/connection.c +7 -13 modified
profiles/network/connection.h +2 -8 modified
profiles/network/main.c +0 -46 deleted
profiles/network/manager.c +48 -41 modified
profiles/network/manager.h +2 -2 modified

Full Patch

diff --git a/Makefile.plugins b/Makefile.plugins
index 3df5eb1..eb16765 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -48,8 +48,7 @@ builtin_sources += profiles/audio/main.c \
 			profiles/audio/a2dp-codecs.h
 
 builtin_modules += network
-builtin_sources += profiles/network/main.c \
-			profiles/network/manager.h profiles/network/manager.c \
+builtin_sources += profiles/network/manager.h profiles/network/manager.c \
 			profiles/network/common.h profiles/network/common.c \
 			profiles/network/server.h profiles/network/server.c \
 			profiles/network/connection.h \
diff --git a/profiles/network/connection.c b/profiles/network/connection.c
index 1856eb8..3157e31 100644
--- a/profiles/network/connection.c
+++ b/profiles/network/connection.c
@@ -46,6 +46,7 @@
 
 #include "error.h"
 #include "common.h"
+#include "manager.h"
 #include "connection.h"
 
 #define NETWORK_PEER_INTERFACE "org.bluez.Network"
@@ -64,8 +65,6 @@ struct network_peer {
 };
 
 struct network_conn {
-	btd_connection_cb cb;
-	void		*cb_data;
 	char		dev[16];	/* Interface name */
 	uint16_t	id;		/* Role: Service Class Identifier */
 	conn_state	state;
@@ -136,6 +135,8 @@ static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,
 	device_remove_disconnect_watch(nc->peer->device, nc->dc_id);
 	nc->dc_id = 0;
 
+	network_disconnected(nc->peer->device, nc->id, 0);
+
 	info("%s disconnected", nc->dev);
 
 	bnep_if_down(nc->dev);
@@ -153,8 +154,7 @@ static void cancel_connection(struct network_conn *nc, int err)
 		nc->timeout_source = 0;
 	}
 
-	if (nc->cb)
-		nc->cb(nc->peer->device, err, NULL, nc->cb_data);
+	network_connected(nc->peer->device, nc->id, err);
 
 	g_io_channel_shutdown(nc->io, TRUE, NULL);
 	g_io_channel_unref(nc->io);
@@ -258,8 +258,7 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
 
 	bnep_if_up(nc->dev);
 
-	if (nc->cb)
-		nc->cb(nc->peer->device, 0, nc->dev, nc->cb_data);
+	network_connected(nc->peer->device, nc->id, 0);
 
 	conn = btd_get_dbus_connection();
 	path = device_get_path(nc->peer->device);
@@ -376,9 +375,7 @@ failed:
 }
 
 /* Connect and initiate BNEP session */
-int connection_connect(struct btd_device *device, uint16_t id,
-					const char *owner,
-					btd_connection_cb cb, void *data)
+int connection_connect(struct btd_device *device, uint16_t id)
 {
 	struct network_peer *peer;
 	struct network_conn *nc;
@@ -413,14 +410,11 @@ int connection_connect(struct btd_device *device, uint16_t id,
 		return -EIO;
 
 	nc->state = CONNECTING;
-	nc->cb = cb;
-	nc->cb_data = data;
 
 	return 0;
 }
 
-int connection_disconnect(struct btd_device *device, uint16_t id,
-							const char *caller)
+int connection_disconnect(struct btd_device *device, uint16_t id)
 {
 	struct network_peer *peer;
 	struct network_conn *nc;
diff --git a/profiles/network/connection.h b/profiles/network/connection.h
index e67b0ec..32356f9 100644
--- a/profiles/network/connection.h
+++ b/profiles/network/connection.h
@@ -21,13 +21,7 @@
  *
  */
 
-typedef void (*btd_connection_cb)(struct btd_device *device, int err,
-					const char *pdev, void *data);
-
 int connection_register(struct btd_device *device, uint16_t id);
 void connection_unregister(struct btd_device *device);
-int connection_connect(struct btd_device *device, uint16_t id,
-					const char *owner,
-					btd_connection_cb cb, void *data);
-int connection_disconnect(struct btd_device *device, uint16_t id,
-					const char *caller);
+int connection_connect(struct btd_device *device, uint16_t id);
+int connection_disconnect(struct btd_device *device, uint16_t id);
diff --git a/profiles/network/main.c b/profiles/network/main.c
deleted file mode 100644
index 99a1954..0000000
--- a/profiles/network/main.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- *
- *  BlueZ - Bluetooth protocol stack for Linux
- *
- *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
- *
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-
-#include <gdbus/gdbus.h>
-
-#include "plugin.h"
-#include "manager.h"
-
-static int network_init(void)
-{
-	return network_manager_init();
-}
-
-static void network_exit(void)
-{
-	network_manager_exit();
-}
-
-BLUETOOTH_PLUGIN_DEFINE(network, VERSION,
-			BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, network_init, network_exit)
diff --git a/profiles/network/manager.c b/profiles/network/manager.c
index 9958099..0a3683c 100644
--- a/profiles/network/manager.c
+++ b/profiles/network/manager.c
@@ -36,6 +36,7 @@
 #include <gdbus/gdbus.h>
 
 #include "log.h"
+#include "plugin.h"
 
 #include "adapter.h"
 #include "device.h"
@@ -73,39 +74,6 @@ done:
 				conf_security ? "true" : "false");
 }
 
-static void connect_profile_cb(struct btd_device *device, int err,
-						const char *pdev, void *data)
-{
-	struct btd_profile *profile = data;
-
-	device_profile_connected(device, profile, err);
-}
-
-static int connect_profile(struct btd_device *dev, struct btd_profile *profile,
-						uint16_t id)
-{
-	DBG("path %s id %u", device_get_path(dev), id);
-
-	return connection_connect(dev, id, NULL, connect_profile_cb, profile);
-}
-
-static int disconnect_profile(struct btd_device *dev,
-						struct btd_profile *profile,
-						uint16_t id)
-{
-	int err;
-
-	DBG("path %s id %u", device_get_path(dev), id);
-
-	err = connection_disconnect(dev, id, NULL);
-	if (err < 0)
-		return err;
-
-	device_profile_disconnected(dev, profile, 0);
-
-	return 0;
-}
-
 static int panu_probe(struct btd_profile *p, struct btd_device *device,
 								GSList *uuids)
 {
@@ -123,12 +91,12 @@ static void network_remove(struct btd_profile *p, struct btd_device *device)
 
 static int panu_connect(struct btd_device *dev, struct btd_profile *profile)
 {
-	return connect_profile(dev, profile, BNEP_SVC_PANU);
+	return connection_connect(dev, BNEP_SVC_PANU);
 }
 
 static int panu_disconnect(struct btd_device *dev, struct btd_profile *profile)
 {
-	return disconnect_profile(dev, profile, BNEP_SVC_PANU);
+	return connection_disconnect(dev, BNEP_SVC_PANU);
 }
 
 static int panu_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
@@ -160,12 +128,12 @@ static int gn_probe(struct btd_profile *p, struct btd_device *device,
 
 static int gn_connect(struct btd_device *dev, struct btd_profile *profile)
 {
-	return connect_profile(dev, profile, BNEP_SVC_GN);
+	return connection_connect(dev, BNEP_SVC_GN);
 }
 
 static int gn_disconnect(struct btd_device *dev, struct btd_profile *profile)
 {
-	return disconnect_profile(dev, profile, BNEP_SVC_GN);
+	return connection_disconnect(dev, BNEP_SVC_GN);
 }
 
 static int gn_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
@@ -197,12 +165,12 @@ static int nap_probe(struct btd_profile *p, struct btd_device *device,
 
 static int nap_connect(struct btd_device *dev, struct btd_profile *profile)
 {
-	return connect_profile(dev, profile, BNEP_SVC_NAP);
+	return connection_connect(dev, BNEP_SVC_NAP);
 }
 
 static int nap_disconnect(struct btd_device *dev, struct btd_profile *profile)
 {
-	return disconnect_profile(dev, profile, BNEP_SVC_NAP);
+	return connection_disconnect(dev, BNEP_SVC_NAP);
 }
 
 static int nap_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
@@ -260,7 +228,43 @@ static struct btd_profile nap_profile = {
 	.adapter_remove	= nap_server_remove,
 };
 
-int network_manager_init(void)
+void network_connected(struct btd_device *dev, int id, int err)
+{
+	switch (id) {
+	case BNEP_SVC_PANU:
+		device_profile_connected(dev, &panu_profile, err);
+		break;
+	case BNEP_SVC_GN:
+		device_profile_connected(dev, &gn_profile, err);
+		break;
+	case BNEP_SVC_NAP:
+		device_profile_connected(dev, &gn_profile, err);
+		break;
+	default:
+		error("Invalid id %d passed to network_connected", id);
+		break;
+	}
+}
+
+void network_disconnected(struct btd_device *dev, int id, int err)
+{
+	switch (id) {
+	case BNEP_SVC_PANU:
+		device_profile_disconnected(dev, &panu_profile, err);
+		break;
+	case BNEP_SVC_GN:
+		device_profile_disconnected(dev, &gn_profile, err);
+		break;
+	case BNEP_SVC_NAP:
+		device_profile_disconnected(dev, &gn_profile, err);
+		break;
+	default:
+		error("Invalid id %d passed to network_disconnected", id);
+		break;
+	}
+}
+
+static int network_init(void)
 {
 	read_config(CONFIGDIR "/network.conf");
 
@@ -286,7 +290,7 @@ int network_manager_init(void)
 	return 0;
 }
 
-void network_manager_exit(void)
+static void network_exit(void)
 {
 	server_exit();
 
@@ -296,3 +300,6 @@ void network_manager_exit(void)
 
 	bnep_cleanup();
 }
+
+BLUETOOTH_PLUGIN_DEFINE(network, VERSION,
+			BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, network_init, network_exit)
diff --git a/profiles/network/manager.h b/profiles/network/manager.h
index 5ba1f0e..8a8c065 100644
--- a/profiles/network/manager.h
+++ b/profiles/network/manager.h
@@ -21,5 +21,5 @@
  *
  */
 
-int network_manager_init(void);
-void network_manager_exit(void);
+void network_connected(struct btd_device *dev, int id, int err);
+void network_disconnected(struct btd_device *dev, int id, int err);