Add ready and killed callbacks to supplicant test program
authorMarcel Holtmann <marcel@holtmann.org>
Thu, 31 Dec 2009 04:29:50 +0000 (20:29 -0800)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 31 Dec 2009 04:29:50 +0000 (20:29 -0800)
tools/supplicant-test.c
tools/supplicant.c
tools/supplicant.h

index 988d4920ac5c38a2e06e390afe0676a300ceb84c..e7fa4d676f9f8331cb43b588e18462a15bc426c3 100644 (file)
        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,
index b9b11fcf0a64cd75c9aadfdb6a7e826768f6216a..8f23dc3f6f7cd7cdc396597961dbb1bc95b3901f 100644 (file)
@@ -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;
index 0a783e1ee1d14b357d96f5408f40ebb35dbac766..f4d01c6dc7c59dd080cc0e88619de7464b51ebec 100644 (file)
@@ -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);