From: Patrik Flykt <[email protected]>

---
 src/connman.h    |    2 +
 src/technology.c |  101 ++++++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 92 insertions(+), 11 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index d60e601..a8b861b 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -393,6 +393,8 @@ int __connman_technology_update_rfkill(unsigned int index,
 int __connman_technology_remove_rfkill(unsigned int index,
                                        enum connman_service_type type);
 
+void __connman_technology_scan_start(enum connman_service_type type);
+void __connman_technology_scan_stop(enum connman_service_type type);
 void __connman_technology_add_interface(enum connman_service_type type,
                                int index, const char *name, const char *ident);
 void __connman_technology_remove_interface(enum connman_service_type type,
diff --git a/src/technology.c b/src/technology.c
index 9ff80dc..2e01058 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -64,6 +64,8 @@ struct connman_technology {
 
        DBusMessage *pending_reply;
        guint pending_timeout;
+
+       GSList *scan;
 };
 
 static GSList *driver_list = NULL;
@@ -698,17 +700,6 @@ static DBusMessage *set_property(DBusConnection *conn,
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
-static GDBusMethodTable technology_methods[] = {
-       { "GetProperties", "",   "a{sv}", get_properties },
-       { "SetProperty",   "sv", "",      set_property   },
-       { },
-};
-
-static GDBusSignalTable technology_signals[] = {
-       { "PropertyChanged", "sv" },
-       { },
-};
-
 static struct connman_technology *technology_find(enum connman_service_type 
type)
 {
        GSList *list;
@@ -725,6 +716,92 @@ static struct connman_technology *technology_find(enum 
connman_service_type type
        return NULL;
 }
 
+static void scan_failed(struct connman_technology *technology, int err)
+{
+       GSList *list = technology->scan;
+       DBusMessage *reply;
+
+       DBG("technology type %d err %d", technology->type, err);
+
+       technology->scan = NULL;
+       while (list) {
+               DBusMessage *msg = list->data;
+               reply = __connman_error_failed(msg, -err);
+               g_dbus_send_message(connection, reply);
+               list = g_slist_delete_link(list, list);
+       }
+}
+
+void __connman_technology_scan_start(enum connman_service_type type)
+{
+       DBG("technology type %d", type);
+}
+
+void __connman_technology_scan_stop(enum connman_service_type type)
+{
+       struct connman_technology *technology;
+       GSList *list;
+       DBusMessage *reply;
+       
+       DBG("technology type %d", type);
+
+       technology = technology_find(type);
+
+       if (technology == NULL)
+               return;
+
+       list = technology->scan;
+       technology->scan = NULL;
+
+       while (list) {
+               DBusMessage *msg = list->data;
+
+               DBG("reply to %s", dbus_message_get_sender(msg));
+
+               reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+               g_dbus_send_message(connection, reply);
+               dbus_message_unref(msg);
+               list = g_slist_delete_link(list, list);
+       }
+}
+
+static DBusMessage *scan(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+       struct connman_technology *technology = data;
+       connman_bool_t scan_start = FALSE;
+       int err;
+
+       DBG ("request from %s technology %d", dbus_message_get_sender(msg),
+                       technology->type);
+
+       if (technology->scan == NULL)
+               scan_start = TRUE;
+
+       dbus_message_ref(msg);
+       technology->scan = g_slist_prepend(technology->scan, msg);
+
+       if (scan_start == TRUE) {
+               err = __connman_device_request_scan(technology->type);
+               if (err < 0 && err != -EALREADY)
+                       scan_failed(technology, err);
+       }
+
+       return NULL;
+}
+
+static GDBusMethodTable technology_methods[] = {
+       { "GetProperties", "",   "a{sv}", get_properties },
+       { "SetProperty",   "sv", "",      set_property   },
+       { "Scan",          "",    "",     scan,
+                                               G_DBUS_METHOD_FLAG_ASYNC },
+       { },
+};
+
+static GDBusSignalTable technology_signals[] = {
+       { "PropertyChanged", "sv" },
+       { },
+};
+
 static struct connman_technology *technology_get(enum connman_service_type 
type)
 {
        struct connman_technology *technology;
@@ -807,6 +884,8 @@ static void technology_put(struct connman_technology 
*technology)
        if (__sync_fetch_and_sub(&technology->refcount, 1) != 1)
                return;
 
+       scan_failed(technology, -EINTR);
+
        if (technology->driver) {
                technology->driver->remove(technology);
                technology->driver = NULL;
-- 
1.7.2.5

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to