From: Marcel Holtmann Date: Thu, 31 Dec 2009 04:29:50 +0000 (-0800) Subject: Add ready and killed callbacks to supplicant test program X-Git-Tag: 0.49~108 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7eb2d1dbb241b1fc258402f57a6fac4dd2229feb;p=platform%2Fupstream%2Fconnman.git Add ready and killed callbacks to supplicant test program --- diff --git a/tools/supplicant-test.c b/tools/supplicant-test.c index 988d4920..e7fa4d67 100644 --- a/tools/supplicant-test.c +++ b/tools/supplicant-test.c @@ -37,6 +37,18 @@ syslog(LOG_DEBUG, "%s() " fmt, __FUNCTION__ , ## arg); \ } while (0) +static void system_ready(void) +{ + DBG(""); + + //supplicant_set_debug_level(1); +} + +static void system_killed(void) +{ + DBG(""); +} + static void interface_added(struct supplicant_interface *interface) { const char *ifname = supplicant_interface_get_ifname(interface); @@ -68,6 +80,8 @@ static void network_removed(struct supplicant_network *network) } static const struct supplicant_callbacks callbacks = { + .system_ready = system_ready, + .system_killed = system_killed, .interface_added = interface_added, .interface_removed = interface_removed, .network_added = network_added, diff --git a/tools/supplicant.c b/tools/supplicant.c index b9b11fcf..8f23dc3f 100644 --- a/tools/supplicant.c +++ b/tools/supplicant.c @@ -48,6 +48,8 @@ static DBusConnection *connection; static const struct supplicant_callbacks *callbacks_pointer; +static dbus_bool_t system_available = FALSE; + static dbus_int32_t debug_level = 0; static dbus_bool_t debug_show_timestamps = FALSE; static dbus_bool_t debug_show_keys = FALSE; @@ -192,6 +194,28 @@ static enum supplicant_state string2state(const char *state) return SUPPLICANT_STATE_UNKNOWN; } +static void callback_system_ready(void) +{ + if (callbacks_pointer == NULL) + return; + + if (callbacks_pointer->system_ready == NULL) + return; + + callbacks_pointer->system_ready(); +} + +static void callback_system_killed(void) +{ + if (callbacks_pointer == NULL) + return; + + if (callbacks_pointer->system_killed == NULL) + return; + + callbacks_pointer->system_killed(); +} + static void callback_interface_added(struct supplicant_interface *interface) { if (callbacks_pointer == NULL) @@ -880,8 +904,10 @@ static void eap_method(DBusMessageIter *iter, void *user_data) static void service_property(const char *key, DBusMessageIter *iter, void *user_data) { - if (key == NULL) + if (key == NULL) { + callback_system_ready(); return; + } if (g_strcmp0(key, "DebugParams") == 0) { DBusMessageIter list; @@ -934,11 +960,16 @@ static void signal_name_owner_changed(const char *path, DBusMessageIter *iter) if (old == NULL || new == NULL) return; - if (strlen(old) > 0 && strlen(new) == 0) + if (strlen(old) > 0 && strlen(new) == 0) { + system_available = FALSE; g_hash_table_remove_all(interface_table); + callback_system_killed(); + } - if (strlen(new) > 0 && strlen(old) == 0) + if (strlen(new) > 0 && strlen(old) == 0) { + system_available = TRUE; supplicant_bootstrap(); + } } static void signal_properties_changed(const char *path, DBusMessageIter *iter) @@ -1105,8 +1136,10 @@ int supplicant_register(const struct supplicant_callbacks *callbacks) dbus_connection_flush(connection); if (dbus_bus_name_has_owner(connection, - SUPPLICANT_SERVICE, NULL) == TRUE) + SUPPLICANT_SERVICE, NULL) == TRUE) { + system_available = TRUE; supplicant_bootstrap(); + } return 0; } @@ -1132,6 +1165,9 @@ void supplicant_unregister(const struct supplicant_callbacks *callbacks) interface_table = NULL; } + if (system_available == TRUE) + callback_system_killed(); + if (connection != NULL) { dbus_connection_unref(connection); connection = NULL; diff --git a/tools/supplicant.h b/tools/supplicant.h index 0a783e1e..f4d01c6d 100644 --- a/tools/supplicant.h +++ b/tools/supplicant.h @@ -79,6 +79,8 @@ const char *supplicant_network_get_identifier(struct supplicant_network *network enum supplicant_mode supplicant_network_get_mode(struct supplicant_network *network); struct supplicant_callbacks { + void (*system_ready) (void); + void (*system_killed) (void); void (*interface_added) (struct supplicant_interface *interface); void (*interface_removed) (struct supplicant_interface *interface); void (*network_added) (struct supplicant_network *network);