Add callbacks to supplicant driver
authorMarcel Holtmann <marcel@holtmann.org>
Sun, 4 Jan 2009 17:18:24 +0000 (18:18 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Sun, 4 Jan 2009 17:18:24 +0000 (18:18 +0100)
plugins/supplicant.c
plugins/supplicant.h
plugins/wifi.c

index a51a517..7edbb91 100644 (file)
 
 static GSList *driver_list = NULL;
 
+static void process_state_change(struct connman_device *device,
+                                               enum supplicant_state state)
+{
+       GSList *list;
+
+       for (list = driver_list; list; list = list->next) {
+               struct supplicant_driver *driver = list->data;
+
+               if (driver->state_change)
+                       driver->state_change(device, state);
+       }
+}
+
+static void process_clear_results(struct connman_device *device)
+{
+       GSList *list;
+
+       for (list = driver_list; list; list = list->next) {
+               struct supplicant_driver *driver = list->data;
+
+               if (driver->clear_results)
+                       driver->clear_results(device);
+       }
+}
+
+static void process_scan_result(struct connman_device *device,
+                                       struct supplicant_network *network)
+{
+       GSList *list;
+
+       for (list = driver_list; list; list = list->next) {
+               struct supplicant_driver *driver = list->data;
+
+               if (driver->scan_result)
+                       driver->scan_result(device, network);
+       }
+}
+
 struct supplicant_task {
        int ifindex;
        gchar *ifname;
        struct connman_device *device;
-       struct supplicant_callback *callback;
        gchar *path;
        gboolean created;
        gchar *network;
@@ -735,8 +772,7 @@ static void properties_reply(DBusPendingCall *call, void *user_data)
                dbus_message_iter_next(&dict);
        }
 
-       if (task->callback && task->callback->scan_result)
-               task->callback->scan_result(task->device, network);
+       process_scan_result(task->device, network);
 
        g_free(network->identifier);
        g_free(network->ssid);
@@ -798,8 +834,7 @@ static void scan_results_reply(DBusPendingCall *call, void *user_data)
                goto done;
        }
 
-       if (task->callback && task->callback->clear_results)
-                       task->callback->clear_results(task->device);
+       process_clear_results(task->device);
 
        for (i = 0; i < num_results; i++)
                get_network_properties(task, results[i]);
@@ -874,8 +909,7 @@ static void state_change(struct supplicant_task *task, DBusMessage *msg)
        else if (g_str_equal(state, "DISCONNECTED") == TRUE)
                task->state = STATE_DISCONNECTED;
 
-       if (task->callback && task->callback->state_change)
-               task->callback->state_change(task->device, task->state);
+       process_state_change(task->device, task->state);
 
        switch (task->state) {
        case STATE_COMPLETED:
@@ -921,8 +955,7 @@ static DBusHandlerResult supplicant_filter(DBusConnection *conn,
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
-int __supplicant_start(struct connman_device *device,
-                                       struct supplicant_callback *callback)
+int supplicant_start(struct connman_device *device)
 {
        struct supplicant_task *task;
        int err;
@@ -936,7 +969,6 @@ int __supplicant_start(struct connman_device *device,
        task->ifindex = connman_device_get_index(device);
        task->ifname = inet_index2name(task->ifindex);
        task->device = device;
-       task->callback = callback;
 
        if (task->ifname == NULL) {
                g_free(task);
@@ -962,7 +994,7 @@ int __supplicant_start(struct connman_device *device,
        return 0;
 }
 
-int __supplicant_stop(struct connman_device *device)
+int supplicant_stop(struct connman_device *device)
 {
        int index = connman_device_get_index(device);
        struct supplicant_task *task;
@@ -988,7 +1020,7 @@ int __supplicant_stop(struct connman_device *device)
        return 0;
 }
 
-int __supplicant_scan(struct connman_device *device)
+int supplicant_scan(struct connman_device *device)
 {
        int index = connman_device_get_index(device);
        struct supplicant_task *task;
index 691b961..4dc6d7f 100644 (file)
@@ -52,7 +52,11 @@ struct supplicant_network {
        gint32 maxrate;
 };
 
-struct supplicant_callback {
+struct supplicant_driver {
+       const char *name;
+       void (*probe) (void);
+       void (*remove) (void);
+
        void (*state_change) (struct connman_device *device,
                                                enum supplicant_state state);
        void (*clear_results) (struct connman_device *device);
@@ -60,19 +64,12 @@ struct supplicant_callback {
                                        struct supplicant_network *network);
 };
 
-struct supplicant_driver {
-       const char *name;
-       void (*probe) (void);
-       void (*remove) (void);
-};
-
 int supplicant_register(struct supplicant_driver *driver);
 void supplicant_unregister(struct supplicant_driver *driver);
 
-int __supplicant_start(struct connman_device *device,
-                                       struct supplicant_callback *callback);
-int __supplicant_stop(struct connman_device *device);
-int __supplicant_scan(struct connman_device *device);
+int supplicant_start(struct connman_device *device);
+int supplicant_stop(struct connman_device *device);
+int supplicant_scan(struct connman_device *device);
 
 int __supplicant_connect(struct connman_element *element,
                                const unsigned char *ssid, int ssid_len,
index 454c6a0..6c3efde 100644 (file)
@@ -171,7 +171,7 @@ static gboolean inactive_scan(gpointer user_data)
 
        DBG("device %p", device);
 
-       __supplicant_scan(device);
+       supplicant_scan(device);
 
        data->inactive_timer = 0;
 
@@ -397,12 +397,6 @@ done:
        g_free(temp);
 }
 
-static struct supplicant_callback wifi_callback = {
-       .state_change   = state_change,
-       .clear_results  = clear_results,
-       .scan_result    = scan_result,
-};
-
 static int wifi_probe(struct connman_device *device)
 {
        struct wifi_data *data;
@@ -438,13 +432,13 @@ static int wifi_enable(struct connman_device *device)
 
        DBG("device %p", device);
 
-       err = __supplicant_start(device, &wifi_callback);
+       err = supplicant_start(device);
        if (err < 0)
                return err;
 
        connman_device_set_powered(device, TRUE);
 
-       __supplicant_scan(device);
+       supplicant_scan(device);
 
        return 0;
 }
@@ -480,7 +474,7 @@ static int wifi_disable(struct connman_device *device)
 
        connman_element_unregister_children((struct connman_element *) device);
 
-       __supplicant_stop(device);
+       supplicant_stop(device);
 
        connman_device_set_powered(device, FALSE);
 
@@ -491,7 +485,7 @@ static int wifi_scan(struct connman_device *device)
 {
        DBG("device %p", device);
 
-       __supplicant_scan(device);
+       supplicant_scan(device);
 
        return 0;
 }
@@ -525,6 +519,10 @@ static struct supplicant_driver supplicant = {
        .name           = "wifi",
        .probe          = wifi_register,
        .remove         = wifi_unregister,
+
+       .state_change   = state_change,
+       .clear_results  = clear_results,
+       .scan_result    = scan_result,
 };
 
 static int wifi_init(void)