summaryrefslogtreecommitdiffstats
path: root/serial/main.c
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 /serial/main.c
parent24eaef5b7c1bdbaa1d956d7714184ab0a8059185 (diff)
Convert serial service to a plugin
Diffstat (limited to 'serial/main.c')
-rw-r--r--serial/main.c73
1 files changed, 21 insertions, 52 deletions
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)