summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-03-22 16:07:37 +0000
committerMarcel Holtmann <marcel@holtmann.org>2008-03-22 16:07:37 +0000
commitd78b22fe007467b1e5129e6e7f0f5752fac85efe (patch)
treef6cf81e1fd1262bfc55c3e6611948eefe59e5898
parent24eaef5b7c1bdbaa1d956d7714184ab0a8059185 (diff)
Convert serial service to a plugin
-rw-r--r--serial/Makefile.am20
-rw-r--r--serial/main.c73
-rw-r--r--serial/manager.c4
-rw-r--r--serial/manager.h4
-rw-r--r--serial/serial.service5
5 files changed, 33 insertions, 73 deletions
diff --git a/serial/Makefile.am b/serial/Makefile.am
index 46039bea..705ccef4 100644
--- a/serial/Makefile.am
+++ b/serial/Makefile.am
@@ -1,27 +1,23 @@
if SERIALSERVICE
-if CONFIGFILES
-confdir = $(sysconfdir)/bluetooth
+plugindir = $(libdir)/bluetooth/plugins
-conf_DATA = serial.service
-endif
-
-servicedir = $(libdir)/bluetooth
+plugin_LTLIBRARIES = libserial.la
-service_PROGRAMS = bluetoothd-service-serial
-
-bluetoothd_service_serial_SOURCES = main.c \
+libserial_la_SOURCES = main.c \
manager.h manager.c port.h port.c \
storage.h storage.c
LDADD = $(top_builddir)/common/libhelper.a \
- @GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@
+ @GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@
endif
+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 = serial.service serial-api.txt test-serial
+EXTRA_DIST = serial-api.txt test-serial
MAINTAINERCLEANFILES = Makefile.in
diff --git a/serial/main.c b/serial/main.c
index 3554eeeb..466ee883 100644
--- a/serial/main.c
+++ b/serial/main.c
@@ -25,70 +25,39 @@
#include <config.h>
#endif
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <glib.h>
-#include "logging.h"
-#include "dbus.h"
+#include <errno.h>
+#include <sys/types.h>
-#include "manager.h"
+#include <dbus/dbus.h>
-static GMainLoop *main_loop;
+#include "plugin.h"
+#include "dbus.h"
+#include "manager.h"
-static void sig_term(int sig)
-{
- g_main_loop_quit(main_loop);
-}
+static DBusConnection *conn;
-int main(int argc, char *argv[])
+static int serial_init(void)
{
- DBusConnection *conn;
- struct sigaction sa;
-
- start_logging("serial", "Bluetooth Serial Port daemon");
-
- memset(&sa, 0, sizeof(sa));
- sa.sa_flags = SA_NOCLDSTOP;
- sa.sa_handler = sig_term;
- sigaction(SIGTERM, &sa, NULL);
- sigaction(SIGINT, &sa, NULL);
-
- sa.sa_handler = SIG_IGN;
- sigaction(SIGCHLD, &sa, NULL);
- sigaction(SIGPIPE, &sa, NULL);
-
- enable_debug();
-
- main_loop = g_main_loop_new(NULL, FALSE);
+ conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (conn == NULL)
+ return -EIO;
- conn = dbus_bus_system_setup_with_main_loop(NULL, NULL, NULL);
- if (!conn) {
- g_main_loop_unref(main_loop);
- exit(EXIT_FAILURE);
- }
-
- if (serial_init(conn) < 0) {
+ if (serial_manager_init(conn) < 0) {
dbus_connection_unref(conn);
- g_main_loop_unref(main_loop);
- exit(EXIT_FAILURE);
+ return -EIO;
}
- if (argc > 1 && !strcmp(argv[1], "-s"))
- register_external_service(conn, "serial", "Serial service", "");
+ register_external_service(conn, "serial", "Serial service", "");
- g_main_loop_run(main_loop);
+ return 0;
+}
- serial_exit();
+static void serial_exit(void)
+{
+ serial_manager_exit();
dbus_connection_unref(conn);
-
- g_main_loop_unref(main_loop);
-
- info("Exit");
-
- stop_logging();
-
- return 0;
}
+
+BLUETOOTH_PLUGIN_DEFINE("serial", serial_init, serial_exit)
diff --git a/serial/manager.c b/serial/manager.c
index bf9b0d24..349e5cdc 100644
--- a/serial/manager.c
+++ b/serial/manager.c
@@ -2392,7 +2392,7 @@ static void register_stored(void)
closedir(dir);
}
-int serial_init(DBusConnection *conn)
+int serial_manager_init(DBusConnection *conn)
{
if (rfcomm_ctl < 0) {
@@ -2427,7 +2427,7 @@ int serial_init(DBusConnection *conn)
return 0;
}
-void serial_exit(void)
+void serial_manager_exit(void)
{
dbus_connection_destroy_object_path(connection, SERIAL_MANAGER_PATH);
diff --git a/serial/manager.h b/serial/manager.h
index cf55adab..8a870101 100644
--- a/serial/manager.h
+++ b/serial/manager.h
@@ -26,6 +26,6 @@
#define MAX_PATH_LENGTH 32
-int serial_init(DBusConnection *conn);
-void serial_exit(void);
+int serial_manager_init(DBusConnection *conn);
+void serial_manager_exit(void);
int rfcomm_release(int16_t id);
diff --git a/serial/serial.service b/serial/serial.service
deleted file mode 100644
index 926e5064..00000000
--- a/serial/serial.service
+++ /dev/null
@@ -1,5 +0,0 @@
-[Bluetooth Service]
-Identifier=serial
-Name=Serial service
-Description=Bluetooth Serial Port service
-Autostart=false