summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-03-27 10:21:45 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-03-27 10:21:45 +0000
commit3ee5b90642bb7c8d2e88904600edac9d0d33efb4 (patch)
treea15bcf9975cd0b052a2f785b62df4546d5dd9255 /network
parent3e3f6b041fd5a9f876c9a2fd87be366cc5621c17 (diff)
Improve D-Bus system bus integration
Diffstat (limited to 'network')
-rw-r--r--network/common.h2
-rw-r--r--network/connection.h3
-rw-r--r--network/main.c22
-rw-r--r--network/manager.c55
-rw-r--r--network/manager.h3
-rw-r--r--network/server.h1
6 files changed, 36 insertions, 50 deletions
diff --git a/network/common.h b/network/common.h
index 36bb66b2..820a2b3a 100644
--- a/network/common.h
+++ b/network/common.h
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
-/* BNEP functions */
+
int bnep_init(void);
int bnep_cleanup(void);
diff --git a/network/connection.h b/network/connection.h
index 70966b2c..08861a72 100644
--- a/network/connection.h
+++ b/network/connection.h
@@ -20,5 +20,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+
int connection_register(DBusConnection *conn, const char *path,
- const char *addr, uint16_t id);
+ const char *addr, uint16_t id);
diff --git a/network/main.c b/network/main.c
index 16a173c5..74675184 100644
--- a/network/main.c
+++ b/network/main.c
@@ -48,6 +48,7 @@ static void sig_term(int sig)
int main(int argc, char *argv[])
{
+ DBusConnection *conn;
struct sigaction sa;
start_logging("network", "Bluetooth Network daemon");
@@ -64,18 +65,26 @@ int main(int argc, char *argv[])
enable_debug();
- /* Create event loop */
main_loop = g_main_loop_new(NULL, FALSE);
- hal_init(NULL);
+ conn = dbus_bus_system_setup_with_main_loop(NULL, NULL, NULL);
+ if (!conn) {
+ g_main_loop_unref(main_loop);
+ exit(1);
+ }
+
+ hal_init(conn);
hal_create_device(NULL);
- if (network_init() == -1)
- goto fail;
+ if (network_init(conn) < 0) {
+ dbus_connection_unref(conn);
+ g_main_loop_unref(main_loop);
+ exit(1);
+ }
if (argc > 1 && !strcmp(argv[1], "-s"))
- internal_service("network");
+ register_external_service(conn, "network", "Network service", "");
g_main_loop_run(main_loop);
@@ -85,7 +94,8 @@ int main(int argc, char *argv[])
hal_cleanup();
-fail:
+ dbus_connection_unref(conn);
+
g_main_loop_unref(main_loop);
info("Exit");
diff --git a/network/manager.c b/network/manager.c
index 915f1a4b..60471429 100644
--- a/network/manager.c
+++ b/network/manager.c
@@ -341,17 +341,13 @@ int network_dbus_init(void)
bdaddr_t src;
int dev_id;
- connection = init_dbus(NULL, NULL, NULL);
- if (!connection)
- return -1;
-
dbus_connection_set_exit_on_disconnect(connection, TRUE);
mgr = g_new0(struct manager, 1);
/* Fallback to catch invalid network path */
- if (!dbus_connection_register_fallback(connection, NETWORK_PATH,
- &manager_table, mgr)) {
+ if (dbus_connection_register_fallback(connection, NETWORK_PATH,
+ &manager_table, mgr) == FALSE) {
error("D-Bus failed to register %s path", NETWORK_PATH);
goto fail;
}
@@ -384,43 +380,12 @@ fail:
void network_dbus_exit(void)
{
dbus_connection_unregister_object_path(connection, NETWORK_PATH);
-
- dbus_connection_unref(connection);
}
-void internal_service(const char *identifier)
+int network_init(DBusConnection *conn)
{
- DBusMessage *msg, *reply;
- const char *name = "Network service", *desc = "";
-
- info("Registering service");
+ int err;
- msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
- "org.bluez.Database", "RegisterService");
- if (!msg) {
- error("Can't create service register method");
- return;
- }
-
- dbus_message_append_args(msg, DBUS_TYPE_STRING, &identifier,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_STRING, &desc, DBUS_TYPE_INVALID);
-
- reply = dbus_connection_send_with_reply_and_block(connection, msg, -1,
- NULL);
- if (!reply) {
- error("Can't register service");
- return;
- }
-
- dbus_message_unref(msg);
- dbus_message_unref(reply);
-
- dbus_connection_flush(connection);
-}
-
-int network_init(void)
-{
if (bridge_init() < 0) {
error("Can't init bridge module");
return -1;
@@ -436,13 +401,23 @@ int network_init(void)
return -1;
}
- return network_dbus_init();
+ connection = dbus_connection_ref(conn);
+
+ err = network_dbus_init();
+ if (err < 0)
+ dbus_connection_unref(connection);
+
+ return err;
}
void network_exit(void)
{
network_dbus_exit();
+ dbus_connection_unref(connection);
+
+ connection = NULL;
+
if (bridge_remove("pan0") < 0)
error("Can't remove bridge");
diff --git a/network/manager.h b/network/manager.h
index 81467c1a..d37ca3cd 100644
--- a/network/manager.h
+++ b/network/manager.h
@@ -21,6 +21,5 @@
*
*/
-int network_init(void);
+int network_init(DBusConnection *conn);
void network_exit(void);
-void internal_service(const char *identifier);
diff --git a/network/server.h b/network/server.h
index bb15e4d7..27b38ba6 100644
--- a/network/server.h
+++ b/network/server.h
@@ -20,4 +20,5 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+
int server_register(DBusConnection *conn, const char *path, uint16_t id);