summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-03-22 15:49:07 +0000
committerMarcel Holtmann <marcel@holtmann.org>2008-03-22 15:49:07 +0000
commit88e798a8b8126d997ded2adcebafbc3fb1fcb509 (patch)
tree863976dc7e43d9a5f35d7661b84b0eab12bef4e6 /network
parent29efa57d5a27b0cf5997381053be9cc48b2c2e80 (diff)
Convert network service into a plugin
Diffstat (limited to 'network')
-rw-r--r--network/Makefile.am22
-rw-r--r--network/main.c85
-rw-r--r--network/manager.c4
-rw-r--r--network/manager.h4
-rw-r--r--network/network.service5
5 files changed, 34 insertions, 86 deletions
diff --git a/network/Makefile.am b/network/Makefile.am
index 2f8a7c3d..da92a8c2 100644
--- a/network/Makefile.am
+++ b/network/Makefile.am
@@ -1,28 +1,24 @@
if NETWORKSERVICE
-if CONFIGFILES
-confdir = $(sysconfdir)/bluetooth
+plugindir = $(libdir)/bluetooth/plugins
-conf_DATA = network.service
-endif
-
-servicedir = $(libdir)/bluetooth
+plugin_LTLIBRARIES = libnetwork.la
-service_PROGRAMS = bluetoothd-service-network
-
-bluetoothd_service_network_SOURCES = main.c \
+libnetwork_la_SOURCES = main.c \
manager.h manager.c \
server.h server.c bridge.h bridge.c \
connection.h connection.c common.h common.c
LDADD = $(top_builddir)/common/libhelper.a \
- @GLIB_LIBS@ @HAL_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@
+ @GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@
endif
-AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @HAL_CFLAGS@ @GLIB_CFLAGS@
+AM_LDFLAGS = -module -avoid-version -export-symbols-regex bluetooth_plugin_desc
+
+AM_CFLAGS = @BLUEZ_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@
-INCLUDES = -I$(top_srcdir)/common
+INCLUDES = -I$(top_srcdir)/common -I$(top_srcdir)/hcid
-EXTRA_DIST = network.service network.conf network-api.txt test-network
+EXTRA_DIST = network.conf network-api.txt test-network
MAINTAINERCLEANFILES = Makefile.in
diff --git a/network/main.c b/network/main.c
index 914cb9c1..e749762e 100644
--- a/network/main.c
+++ b/network/main.c
@@ -25,28 +25,22 @@
#include <config.h>
#endif
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
#include <errno.h>
-#include <signal.h>
-#include <glib.h>
-
+#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
+#include <glib.h>
+#include <dbus/dbus.h>
+
+#include "plugin.h"
#include "dbus.h"
#include "logging.h"
-
#include "manager.h"
-#include "hal.h"
#define IFACE_PREFIX "bnep%d"
#define GN_IFACE "pan0"
#define NAP_IFACE "pan1"
-static GMainLoop *main_loop;
-
static struct network_conf conf = {
.connection_enabled = TRUE,
.server_enabled = TRUE,
@@ -59,11 +53,6 @@ static struct network_conf conf = {
.security = TRUE
};
-static void sig_term(int sig)
-{
- g_main_loop_quit(main_loop);
-}
-
static void read_config(const char *file)
{
GKeyFile *keyfile;
@@ -165,63 +154,31 @@ done:
conf.security ? "true" : "false");
}
-int main(int argc, char *argv[])
-{
- DBusConnection *conn;
- struct sigaction sa;
-
- start_logging("network", "Bluetooth Network daemon");
-
- memset(&sa, 0, sizeof(sa));
- sa.sa_flags = SA_NOCLDSTOP;
- sa.sa_handler = sig_term;
- sigaction(SIGTERM, &sa, NULL);
- sigaction(SIGINT, &sa, NULL);
+static DBusConnection *conn;
- sa.sa_handler = SIG_IGN;
- sigaction(SIGCHLD, &sa, NULL);
- sigaction(SIGPIPE, &sa, NULL);
-
- enable_debug();
+static int network_init(void)
+{
+ conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (conn == NULL)
+ return -EIO;
read_config(CONFIGDIR "/network.conf");
- main_loop = g_main_loop_new(NULL, FALSE);
-
- 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(conn, &conf) < 0) {
+ if (network_manager_init(conn, &conf) < 0) {
dbus_connection_unref(conn);
- g_main_loop_unref(main_loop);
- exit(1);
+ return -EIO;
}
- if (argc > 1 && !strcmp(argv[1], "-s"))
- register_external_service(conn, "network", "Network service", "");
+ register_external_service(conn, "network", "Network service", "");
- g_main_loop_run(main_loop);
-
- network_exit();
-
- hal_remove_device(NULL);
+ return 0;
+}
- hal_cleanup();
+static void network_exit(void)
+{
+ network_manager_exit();
dbus_connection_unref(conn);
-
- g_main_loop_unref(main_loop);
-
- info("Exit");
-
- stop_logging();
-
- return 0;
}
+
+BLUETOOTH_PLUGIN_DEFINE("network", network_init, network_exit)
diff --git a/network/manager.c b/network/manager.c
index 1647e34e..0808706e 100644
--- a/network/manager.c
+++ b/network/manager.c
@@ -1003,7 +1003,7 @@ static DBusMethodVTable manager_methods[] = {
{ NULL, NULL, NULL, NULL }
};
-int network_init(DBusConnection *conn, struct network_conf *service_conf)
+int network_manager_init(DBusConnection *conn, struct network_conf *service_conf)
{
DBusMethodVTable *methods = NULL;
DBusSignalVTable *signals = NULL;
@@ -1078,7 +1078,7 @@ int network_init(DBusConnection *conn, struct network_conf *service_conf)
return 0;
}
-void network_exit(void)
+void network_manager_exit(void)
{
if (conf->server_enabled)
server_exit();
diff --git a/network/manager.h b/network/manager.h
index 6d440a55..9b16c2a3 100644
--- a/network/manager.h
+++ b/network/manager.h
@@ -39,5 +39,5 @@ struct network_conf {
char *nap_iface;
};
-int network_init(DBusConnection *conn, struct network_conf *service_conf);
-void network_exit(void);
+int network_manager_init(DBusConnection *conn, struct network_conf *service_conf);
+void network_manager_exit(void);
diff --git a/network/network.service b/network/network.service
deleted file mode 100644
index 444bdff3..00000000
--- a/network/network.service
+++ /dev/null
@@ -1,5 +0,0 @@
-[Bluetooth Service]
-Identifier=network
-Name=Network service
-Description=Bluetooth Personal Area Network service
-Autostart=false