Add global method call to request scanning
authorMarcel Holtmann <marcel@holtmann.org>
Thu, 16 Jul 2009 09:49:38 +0000 (11:49 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 16 Jul 2009 09:49:38 +0000 (11:49 +0200)
doc/manager-api.txt
src/connman.h
src/device.c
src/element.c
src/manager.c

index e864a83a8cf39a9666ca02ada979c0f32ddb9cf5..bd42f9cc74a8a6feab228779052666f522d7ba8e 100644 (file)
@@ -45,6 +45,14 @@ Methods              dict GetProperties()
 
                        Possible Errors: [service].Error.InvalidArguments
 
+               void RequestScan(string type)
+
+                       Request to trigger a scan for the specified
+                       technology. The empty string "" triggers scanning
+                       on all technologies.
+
+                       Possible Errors: [service].Error.InvalidArguments
+
                void RegisterAgent(object path)
 
                        Register new agent for handling user requests.
index 9b200b5127006787539d91fc21623c3ef92aad38..a5614179580cdf06d5c7c8de6598eadbf5b56faf 100644 (file)
@@ -166,6 +166,7 @@ const char *__connman_element_get_device_path(struct connman_element *element);
 const char *__connman_element_get_network_path(struct connman_element *element);
 
 struct connman_device *__connman_element_find_device(enum connman_device_type type);
+int __connman_element_request_scan(enum connman_device_type type);
 
 const char *__connman_element_type2string(enum connman_element_type type);
 
@@ -206,6 +207,7 @@ void __connman_device_decrease_connections(struct connman_device *device);
 void __connman_device_set_network(struct connman_device *device,
                                        struct connman_network *network);
 
+int __connman_device_scan(struct connman_device *device);
 int __connman_device_connect(struct connman_device *device);
 int __connman_device_disconnect(struct connman_device *device);
 
index 981044414dc7f9d41bdbe8263a6ce75005217159..6dadaa3a2068c6c2944403bec989b9b89db081b4 100644 (file)
@@ -715,13 +715,7 @@ static DBusMessage *propose_scan(DBusConnection *conn,
                break;
        }
 
-       if (!device->driver || !device->driver->scan)
-               return __connman_error_not_supported(msg);
-
-       if (device->powered == FALSE)
-               return __connman_error_failed(msg, EINVAL);
-
-       err = device->driver->scan(device);
+       err = __connman_device_scan(device);
        if (err < 0)
                return __connman_error_failed(msg, -err);
 
@@ -1385,6 +1379,17 @@ int connman_device_set_carrier(struct connman_device *device,
        return set_carrier(device, device->carrier);
 }
 
+int __connman_device_scan(struct connman_device *device)
+{
+       if (!device->driver || !device->driver->scan)
+               return -EOPNOTSUPP;
+
+       if (device->powered == FALSE)
+               return -ENOLINK;
+
+       return device->driver->scan(device);
+}
+
 int __connman_device_connect(struct connman_device *device)
 {
        DBG("device %p", device);
index 0175019e12202b1ffeb5f116ee9b0891f927e7f3..3545e170cdd3f207b3df18b4d8c9eba16bb64d14 100644 (file)
@@ -364,6 +364,55 @@ struct connman_device *__connman_element_find_device(enum connman_device_type ty
        return data.device;
 }
 
+static gboolean request_scan(GNode *node, gpointer user_data)
+{
+       struct connman_element *element = node->data;
+       struct find_data *data = user_data;
+       enum connman_device_type type;
+
+       if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
+               return FALSE;
+
+       if (element->device == NULL)
+               return FALSE;
+
+       type = connman_device_get_type(element->device);
+
+       switch (type) {
+       case CONNMAN_DEVICE_TYPE_UNKNOWN:
+       case CONNMAN_DEVICE_TYPE_VENDOR:
+       case CONNMAN_DEVICE_TYPE_ETHERNET:
+       case CONNMAN_DEVICE_TYPE_BLUETOOTH:
+       case CONNMAN_DEVICE_TYPE_GPS:
+       case CONNMAN_DEVICE_TYPE_MBM:
+       case CONNMAN_DEVICE_TYPE_HSO:
+       case CONNMAN_DEVICE_TYPE_NOZOMI:
+       case CONNMAN_DEVICE_TYPE_HUAWEI:
+       case CONNMAN_DEVICE_TYPE_NOVATEL:
+               return FALSE;
+       case CONNMAN_DEVICE_TYPE_WIFI:
+       case CONNMAN_DEVICE_TYPE_WIMAX:
+               if (data->type != CONNMAN_DEVICE_TYPE_UNKNOWN &&
+                                                       data->type != type)
+                       return FALSE;
+               break;
+       }
+
+       __connman_device_scan(element->device);
+
+       return FALSE;
+}
+
+int __connman_element_request_scan(enum connman_device_type type)
+{
+       struct find_data data = { .type = type, .device = NULL };
+
+       g_node_traverse(element_root, G_PRE_ORDER,
+                               G_TRAVERSE_ALL, -1, request_scan, &data);
+
+       return 0;
+}
+
 static gint compare_priority(gconstpointer a, gconstpointer b)
 {
        const struct connman_driver *driver1 = a;
index 3a79bc52a56009cb18b29956aa3b764edc40f420..85025b3652c41e9ba0969b5a60c8e8587745558f 100644 (file)
@@ -244,6 +244,40 @@ static DBusMessage *remove_profile(DBusConnection *conn,
        return __connman_error_not_supported(msg);
 }
 
+static DBusMessage *request_scan(DBusConnection *conn,
+                                       DBusMessage *msg, void *data)
+{
+       enum connman_device_type type;
+       const char *str;
+       int err;
+
+       DBG("conn %p", conn);
+
+       dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str,
+                                                       DBUS_TYPE_INVALID);
+
+       if (g_strcmp0(str, "") == 0)
+               type = CONNMAN_DEVICE_TYPE_UNKNOWN;
+       else if (g_strcmp0(str, "wifi") == 0)
+               type = CONNMAN_DEVICE_TYPE_WIFI;
+       else if (g_strcmp0(str, "wimax") == 0)
+               type = CONNMAN_DEVICE_TYPE_WIMAX;
+       else
+               return __connman_error_invalid_arguments(msg);
+
+       err = __connman_element_request_scan(type);
+       if (err < 0) {
+               if (err == -EINPROGRESS) {
+                       connman_error("Invalid return code from scan");
+                       err = -EINVAL;
+               }
+
+               return __connman_error_failed(msg, -err);
+       }
+
+       return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+}
+
 static DBusMessage *connect_service(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
 {
@@ -258,7 +292,7 @@ static DBusMessage *connect_service(DBusConnection *conn,
        err = __connman_service_create_and_connect(msg);
        if (err < 0) {
                if (err == -EINPROGRESS) {
-                       connman_error("Invalid return code from callbacks");
+                       connman_error("Invalid return code from connect");
                        err = -EINVAL;
                }
 
@@ -321,6 +355,7 @@ static GDBusMethodTable manager_methods[] = {
        { "SetProperty",     "sv",    "",      set_property     },
        { "AddProfile",      "s",     "o",     add_profile      },
        { "RemoveProfile",   "o",     "",      remove_profile   },
+       { "RequestScan",     "s",     "",      request_scan     },
        { "ConnectService",  "a{sv}", "o",     connect_service,
                                                G_DBUS_METHOD_FLAG_ASYNC },
        { "RegisterAgent",   "o",     "",      register_agent   },