From 47eab9ed1e78e901e83507bafe946cf1fab3ab50 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 21 Jul 2009 12:08:12 +0200 Subject: [PATCH] Handle the async notification of scan requests --- plugins/supplicant.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/plugins/supplicant.c b/plugins/supplicant.c index 5b23d92..50d08bd 100644 --- a/plugins/supplicant.c +++ b/plugins/supplicant.c @@ -901,6 +901,30 @@ static int set_network(struct supplicant_task *task, return 0; } +static void scan_reply(DBusPendingCall *call, void *user_data) +{ + struct supplicant_task *task = user_data; + DBusMessage *reply; + + DBG("task %p", task); + + reply = dbus_pending_call_steal_reply(call); + if (reply == NULL) + return; + + if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { + connman_device_set_scanning(task->device, FALSE); + goto done; + } + + if (task->scanning == TRUE) + connman_device_set_scanning(task->device, TRUE); + +done: + dbus_message_unref(reply); +} + + static int initiate_scan(struct supplicant_task *task) { DBusMessage *message; @@ -922,9 +946,17 @@ static int initiate_scan(struct supplicant_task *task) return -EIO; } + if (call == NULL) { + connman_error("D-Bus connection not available"); + dbus_message_unref(message); + return -EIO; + } + + dbus_pending_call_set_notify(call, scan_reply, task, NULL); + dbus_message_unref(message); - return 0; + return -EINPROGRESS; } static struct { @@ -1753,6 +1785,9 @@ int supplicant_scan(struct connman_device *device) err = initiate_scan(task); if (err < 0) { + if (err == -EINPROGRESS) + return 0; + task->scanning = FALSE; return err; } -- 2.7.4