technology: Refactor enable/disable APIs
authorAlok Barsode <alok.barsode@linux.intel.com>
Wed, 24 Aug 2011 13:44:07 +0000 (16:44 +0300)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 25 Aug 2011 09:14:20 +0000 (11:14 +0200)
connman_technology_enable: Enable a technology. Enables all the
devices in the device_list of the technology.
connman_technology_enabled: Callback for connman_technology_enable.
Changes the state of the technology to ENABLED.
Ditto for connman_technology_disable/connman_technology_disabled.

src/connman.h
src/device.c
src/manager.c
src/technology.c

index 945d8e8..272b334 100644 (file)
@@ -314,8 +314,11 @@ void __connman_technology_list(DBusMessageIter *iter, void *user_data);
 
 int __connman_technology_add_device(struct connman_device *device);
 int __connman_technology_remove_device(struct connman_device *device);
+int __connman_technology_enabled(enum connman_service_type type);
 int __connman_technology_enable(enum connman_service_type type);
+int __connman_technology_disabled(enum connman_service_type type);
 int __connman_technology_disable(enum connman_service_type type);
+
 int __connman_technology_add_rfkill(unsigned int index,
                                        enum connman_service_type type,
                                                connman_bool_t softblock,
@@ -342,8 +345,6 @@ void __connman_device_list(DBusMessageIter *iter, void *user_data);
 enum connman_service_type __connman_device_get_service_type(struct connman_device *device);
 struct connman_device *__connman_device_find_device(enum connman_service_type type);
 int __connman_device_request_scan(enum connman_service_type type);
-int __connman_device_enable_technology(enum connman_service_type type);
-int __connman_device_disable_technology(enum connman_service_type type);
 
 connman_bool_t __connman_device_isfiltered(const char *devname);
 
index 12fa49a..be184e1 100644 (file)
@@ -246,7 +246,7 @@ int __connman_device_enable(struct connman_device *device)
                __connman_profile_set_offlinemode(FALSE, FALSE);
 
        type = __connman_device_get_service_type(device);
-       __connman_technology_enable(type);
+       __connman_technology_enabled(type);
 
        return 0;
 }
@@ -286,7 +286,7 @@ int __connman_device_disable(struct connman_device *device)
        device->powered = FALSE;
 
        type = __connman_device_get_service_type(device);
-       __connman_technology_disable(type);
+       __connman_technology_disabled(type);
 
        return 0;
 }
@@ -680,9 +680,9 @@ int connman_device_set_powered(struct connman_device *device,
        type = __connman_device_get_service_type(device);
 
        if (device->powered == TRUE)
-               __connman_technology_enable(type);
+               __connman_technology_enabled(type);
        else
-               __connman_technology_disable(type);
+               __connman_technology_disabled(type);
 
        if (device->offlinemode == TRUE && powered == TRUE)
                return connman_device_set_powered(device, FALSE);
@@ -1321,63 +1321,6 @@ int __connman_device_request_scan(enum connman_service_type type)
        return 0;
 }
 
-static int set_technology(enum connman_service_type type, connman_bool_t enable)
-{
-       GSList *list;
-       int err;
-
-       DBG("type %d enable %d", type, enable);
-
-       switch (type) {
-       case CONNMAN_SERVICE_TYPE_UNKNOWN:
-       case CONNMAN_SERVICE_TYPE_SYSTEM:
-       case CONNMAN_SERVICE_TYPE_GPS:
-       case CONNMAN_SERVICE_TYPE_VPN:
-       case CONNMAN_SERVICE_TYPE_GADGET:
-               return 0;
-       case CONNMAN_SERVICE_TYPE_ETHERNET:
-       case CONNMAN_SERVICE_TYPE_WIFI:
-       case CONNMAN_SERVICE_TYPE_WIMAX:
-       case CONNMAN_SERVICE_TYPE_BLUETOOTH:
-       case CONNMAN_SERVICE_TYPE_CELLULAR:
-               break;
-       }
-
-       for (list = device_list; list != NULL; list = list->next) {
-               struct connman_device *device = list->data;
-               enum connman_service_type service_type =
-                       __connman_device_get_service_type(device);
-
-               if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
-                               service_type != type) {
-                       continue;
-               }
-
-               if (enable == TRUE)
-                       err = __connman_device_enable_persistent(device);
-               else
-                       err = __connman_device_disable_persistent(device);
-
-               if (err < 0 && err != -EINPROGRESS) {
-                       DBG("err %d", err);
-                       /* XXX maybe only a continue? */
-                       return err;
-               }
-       }
-
-       return 0;
-}
-
-int __connman_device_enable_technology(enum connman_service_type type)
-{
-       return set_technology(type, TRUE);
-}
-
-int __connman_device_disable_technology(enum connman_service_type type)
-{
-       return set_technology(type, FALSE);
-}
-
 connman_bool_t __connman_device_isfiltered(const char *devname)
 {
        char **pattern;
index d5542fd..a276e0b 100644 (file)
@@ -343,8 +343,8 @@ static DBusMessage *enable_technology(DBusConnection *conn,
        technology_enabled = TRUE;
        technology_pending = dbus_message_ref(msg);
 
-       err = __connman_device_enable_technology(type);
-       if (err < 0 && err != -EINPROGRESS)
+       err = __connman_technology_enable(type);
+       if (err < 0)
                technology_reply(-err);
        else
                technology_timeout = g_timeout_add_seconds(15,
@@ -391,8 +391,8 @@ static DBusMessage *disable_technology(DBusConnection *conn,
        technology_enabled = FALSE;
        technology_pending = dbus_message_ref(msg);
 
-       err = __connman_device_disable_technology(type);
-       if (err < 0 && err != -EINPROGRESS)
+       err = __connman_technology_disable(type);
+       if (err < 0)
                technology_reply(-err);
        else
                technology_timeout = g_timeout_add_seconds(10,
index c68a649..cb065e2 100644 (file)
@@ -675,7 +675,7 @@ int __connman_technology_remove_device(struct connman_device *device)
        return 0;
 }
 
-int __connman_technology_enable(enum connman_service_type type)
+int __connman_technology_enabled(enum connman_service_type type)
 {
        struct connman_technology *technology;
 
@@ -696,7 +696,37 @@ int __connman_technology_enable(enum connman_service_type type)
        return 0;
 }
 
-int __connman_technology_disable(enum connman_service_type type)
+int __connman_technology_enable(enum connman_service_type type)
+{
+       struct connman_technology *technology;
+       GSList *list;
+       int err;
+       int ret = -ENODEV;
+
+       DBG("type %d enable", type);
+
+       technology = technology_find(type);
+       if (technology == NULL)
+               return -ENXIO;
+
+       for (list = technology->device_list; list; list = list->next) {
+               struct connman_device *device = list->data;
+
+               err = __connman_device_enable_persistent(device);
+               /*
+                * err = 0 : Device was enabled right away.
+                * err = -EINPROGRESS : DBus call was successful.
+                * If atleast one device gets enabled, we consider
+                * the technology to be enabled.
+                */
+               if (err == 0 || err == -EINPROGRESS)
+                       ret = 0;
+       }
+
+       return ret;
+}
+
+int __connman_technology_disabled(enum connman_service_type type)
 {
        struct connman_technology *technology;
        GSList *list;
@@ -725,6 +755,30 @@ int __connman_technology_disable(enum connman_service_type type)
        return 0;
 }
 
+int __connman_technology_disable(enum connman_service_type type)
+{
+       struct connman_technology *technology;
+       GSList *list;
+       int err;
+       int ret = -ENODEV;
+
+       DBG("type %d disable", type);
+
+       technology = technology_find(type);
+       if (technology == NULL)
+               return -ENXIO;
+
+       for (list = technology->device_list; list; list = list->next) {
+               struct connman_device *device = list->data;
+
+               err = __connman_device_disable_persistent(device);
+               if (err == 0 || err == -EINPROGRESS)
+                       ret = 0;
+       }
+
+       return ret;
+}
+
 static void technology_blocked(struct connman_technology *technology,
                                connman_bool_t blocked)
 {