From 72c28aa582fccf616092b3baed5a0964a98a09d7 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 20 Dec 2008 08:42:13 +0100 Subject: [PATCH] Add generic reference to the global D-Bus connection --- include/dbus.h | 2 ++ src/connman.h | 3 +++ src/dbus.c | 22 ++++++++++++++++++++++ src/main.c | 4 ++++ 4 files changed, 31 insertions(+) diff --git a/include/dbus.h b/include/dbus.h index 97a58ba..a0fe3fd 100644 --- a/include/dbus.h +++ b/include/dbus.h @@ -41,6 +41,8 @@ extern "C" { #define CONNMAN_NETWORK_INTERFACE CONNMAN_SERVICE ".Network" #define CONNMAN_CONNECTION_INTERFACE CONNMAN_SERVICE ".Connection" +extern DBusConnection *connman_dbus_get_connection(void); + extern void connman_dbus_property_append_variant(DBusMessageIter *property, const char *key, int type, void *val); diff --git a/src/connman.h b/src/connman.h index 4fca050..70fcac1 100644 --- a/src/connman.h +++ b/src/connman.h @@ -27,6 +27,9 @@ #define NM_PATH "/org/freedesktop/NetworkManager" #define NM_INTERFACE NM_SERVICE +int __connman_dbus_init(DBusConnection *conn); +void __connman_dbus_cleanup(void); + DBusMessage *__connman_error_failed(DBusMessage *msg); DBusMessage *__connman_error_invalid_arguments(DBusMessage *msg); DBusMessage *__connman_error_permission_denied(DBusMessage *msg); diff --git a/src/dbus.c b/src/dbus.c index 333b4cf..6960a40 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -114,3 +114,25 @@ void connman_dbus_dict_append_variant(DBusMessageIter *dict, dbus_message_iter_close_container(dict, &entry); } + +static DBusConnection *connection = NULL; + +DBusConnection *connman_dbus_get_connection(void) +{ + if (connection == NULL) + return NULL; + + return dbus_connection_ref(connection); +} + +int __connman_dbus_init(DBusConnection *conn) +{ + connection = conn; + + return 0; +} + +void __connman_dbus_cleanup(void) +{ + connection = NULL; +} diff --git a/src/main.c b/src/main.c index 929d31a..638ad0b 100644 --- a/src/main.c +++ b/src/main.c @@ -150,6 +150,8 @@ int main(int argc, char *argv[]) } } + __connman_dbus_init(conn); + __connman_storage_init(); __connman_element_init(conn, option_device); @@ -187,6 +189,8 @@ int main(int argc, char *argv[]) __connman_storage_cleanup(); + __connman_dbus_cleanup(); + selftest: __connman_log_cleanup(); -- 2.7.4