summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2007-05-01 11:23:55 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2007-05-01 11:23:55 +0000
commitcdb1b7c3435688bc6f30a3953f1152247ec51b95 (patch)
treef71ac5ac29c404515b724d7626b36656d4a15715
parent6ecc27526933015c672c305669e6f09c68a0b573 (diff)
serial: added main loop integration
-rw-r--r--serial/main.c32
-rw-r--r--serial/manager.c19
-rw-r--r--serial/manager.h3
3 files changed, 54 insertions, 0 deletions
diff --git a/serial/main.c b/serial/main.c
index d249e672..5bacd121 100644
--- a/serial/main.c
+++ b/serial/main.c
@@ -25,19 +25,26 @@
#include <config.h>
#endif
+#include <stdlib.h>
#include <string.h>
#include <signal.h>
+#include <glib.h>
#include "logging.h"
+#include "dbus.h"
#include "manager.h"
+static GMainLoop *main_loop;
+
static void sig_term(int sig)
{
+ g_main_loop_quit(main_loop);
}
int main(int argc, char *argv[])
{
+ DBusConnection *conn;
struct sigaction sa;
start_logging("serial", "Bluetooth Serial Port daemon");
@@ -54,6 +61,31 @@ int main(int argc, char *argv[])
enable_debug();
+ 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(EXIT_FAILURE);
+ }
+
+ if (serial_init(conn) < 0) {
+ dbus_connection_unref(conn);
+ g_main_loop_unref(main_loop);
+ exit(EXIT_FAILURE);
+ }
+
+ if (argc > 1 && !strcmp(argv[1], "-s"))
+ register_external_service(conn, "serial", "Serial service", "");
+
+ g_main_loop_run(main_loop);
+
+ serial_exit();
+
+ dbus_connection_unref(conn);
+
+ g_main_loop_unref(main_loop);
+
info("Exit");
stop_logging();
diff --git a/serial/manager.c b/serial/manager.c
index 2f4ab59e..79601624 100644
--- a/serial/manager.c
+++ b/serial/manager.c
@@ -24,3 +24,22 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+
+#include "dbus.h"
+
+#include "manager.h"
+
+static DBusConnection *connection = NULL;
+
+int serial_init(DBusConnection *conn)
+{
+ connection = dbus_connection_ref(conn);
+
+ return 0;
+}
+
+void serial_exit(void)
+{
+ dbus_connection_unref(connection);
+ connection = NULL;
+}
diff --git a/serial/manager.h b/serial/manager.h
index e87dd676..f09aa294 100644
--- a/serial/manager.h
+++ b/serial/manager.h
@@ -20,3 +20,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+
+int serial_init(DBusConnection *conn);
+void serial_exit(void);