diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2007-03-27 10:27:01 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2007-03-27 10:27:01 +0000 |
commit | 40ebcf393b790a4e6553e1314b29f0f34b3377a3 (patch) | |
tree | 87f78cab6014bfb7b5f2c6606a75390f99fd8f7e /input | |
parent | 3ee5b90642bb7c8d2e88904600edac9d0d33efb4 (diff) |
Improve integration with D-Bus system bus
Diffstat (limited to 'input')
-rw-r--r-- | input/main.c | 17 | ||||
-rw-r--r-- | input/manager.c | 36 | ||||
-rw-r--r-- | input/manager.h | 3 |
3 files changed, 17 insertions, 39 deletions
diff --git a/input/main.c b/input/main.c index 2a6b3b59..057ee0db 100644 --- a/input/main.c +++ b/input/main.c @@ -51,6 +51,7 @@ static void sig_term(int sig) int main(int argc, char *argv[]) { + DBusConnection *conn; struct sigaction sa; start_logging("input", "Bluetooth Input daemon"); @@ -67,16 +68,22 @@ int main(int argc, char *argv[]) enable_debug(); - /* Create event loop */ main_loop = g_main_loop_new(NULL, FALSE); - if (input_init() < 0) { - error("Unable to get on D-Bus"); + conn = dbus_bus_system_setup_with_main_loop(NULL, NULL, NULL); + if (!conn) { + g_main_loop_unref(main_loop); + exit(1); + } + + if (input_init(conn) < 0) { + dbus_connection_unref(conn); + g_main_loop_unref(main_loop); exit(1); } if (argc > 1 && !strcmp(argv[1], "-s")) - internal_service("input"); + register_external_service(conn, "input", "Input service", ""); server_start(); @@ -86,6 +93,8 @@ int main(int argc, char *argv[]) input_exit(); + dbus_connection_unref(conn); + g_main_loop_unref(main_loop); info("Exit"); diff --git a/input/manager.c b/input/manager.c index 2faef35d..a4269df3 100644 --- a/input/manager.c +++ b/input/manager.c @@ -830,15 +830,13 @@ static int register_stored_inputs(struct manager *mgr) return 0; } -int input_init(void) +int input_init(DBusConnection *conn) { struct manager *mgr; bdaddr_t src; int dev_id; - connection = init_dbus(NULL, NULL, NULL); - if (!connection) - return -1; + connection = dbus_connection_ref(conn); dbus_connection_set_exit_on_disconnect(connection, TRUE); @@ -883,34 +881,6 @@ void input_exit(void) dbus_connection_unregister_object_path(connection, INPUT_PATH); dbus_connection_unref(connection); -} - -void internal_service(const char *identifier) -{ - DBusMessage *msg, *reply; - const char *name = "Input Service Debug", *desc = ""; - - info("Registering service"); - - 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); + connection = NULL; } diff --git a/input/manager.h b/input/manager.h index 9eee22aa..7fc6f162 100644 --- a/input/manager.h +++ b/input/manager.h @@ -24,6 +24,5 @@ #define INPUT_PATH "/org/bluez/input" #define INPUT_MANAGER_INTERFACE "org.bluez.input.Manager" -int input_init(void); +int input_init(DBusConnection *conn); void input_exit(void); -void internal_service(const char *identifier); |