From: Marcel Holtmann Date: Fri, 17 Oct 2008 20:10:02 +0000 (+0200) Subject: Add watch for monitoring wpa_supplicant X-Git-Tag: 0.1~117 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=176fe9f20467f7c4bd493c437d6e9d5acd2ebb48;p=platform%2Fupstream%2Fconnman.git Add watch for monitoring wpa_supplicant --- diff --git a/plugins/supplicant.c b/plugins/supplicant.c index de56f8d..260d24f 100644 --- a/plugins/supplicant.c +++ b/plugins/supplicant.c @@ -1049,11 +1049,9 @@ int __supplicant_disconnect(struct connman_element *element) return 0; } -int __supplicant_init(void) +int __supplicant_init(DBusConnection *conn) { - connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); - if (connection == NULL) - return -EIO; + connection = conn; if (dbus_connection_add_filter(connection, supplicant_filter, NULL, NULL) == FALSE) { @@ -1066,11 +1064,5 @@ int __supplicant_init(void) void __supplicant_exit(void) { - if (connection == NULL) - return; - dbus_connection_remove_filter(connection, supplicant_filter, NULL); - - dbus_connection_unref(connection); - connection = NULL; } diff --git a/plugins/supplicant.h b/plugins/supplicant.h index 538c84f..d62e07d 100644 --- a/plugins/supplicant.h +++ b/plugins/supplicant.h @@ -53,7 +53,7 @@ struct supplicant_callback { struct supplicant_network *network); }; -int __supplicant_init(void); +int __supplicant_init(DBusConnection *conn); void __supplicant_exit(void); int __supplicant_start(struct connman_element *element, diff --git a/plugins/wifi.c b/plugins/wifi.c index f7280b1..304ebba 100644 --- a/plugins/wifi.c +++ b/plugins/wifi.c @@ -24,7 +24,7 @@ #endif #include -#include +#include #include #include @@ -299,17 +299,40 @@ static struct connman_driver wifi_driver = { .disable = wifi_disable, }; +static void supplicant_connect(DBusConnection *connection, void *user_data) +{ + DBG("connection %p", connection); +} + +static void supplicant_disconnect(DBusConnection *connection, void *user_data) +{ + DBG("connection %p", connection); +} + +static DBusConnection *connection; +static guint watch; + static int wifi_init(void) { int err; - err = __supplicant_init(); - if (err < 0) + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) + return -EIO; + + err = __supplicant_init(connection); + if (err < 0) { + dbus_connection_unref(connection); return err; + } + + watch = g_dbus_add_service_watch(connection, SUPPLICANT_NAME, + supplicant_connect, supplicant_disconnect, NULL, NULL); err = connman_driver_register(&network_driver); if (err < 0) { __supplicant_exit(); + dbus_connection_unref(connection); return err; } @@ -317,6 +340,7 @@ static int wifi_init(void) if (err < 0) { connman_driver_unregister(&network_driver); __supplicant_exit(); + dbus_connection_unref(connection); return err; } @@ -328,7 +352,12 @@ static void wifi_exit(void) connman_driver_unregister(&network_driver); connman_driver_unregister(&wifi_driver); + if (watch > 0) + g_dbus_remove_watch(connection, watch); + __supplicant_exit(); + + dbus_connection_unref(connection); } CONNMAN_PLUGIN_DEFINE("wifi", "WiFi interface plugin", VERSION,