From 16a3c81f6e336ebc5aed1e1462002833aaebc4fa Mon Sep 17 00:00:00 2001 From: Alok Barsode Date: Wed, 24 Aug 2011 16:44:07 +0300 Subject: [PATCH] technology: Refactor enable/disable APIs 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 | 5 +++-- src/device.c | 65 ++++---------------------------------------------------- src/manager.c | 8 +++---- src/technology.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 67 insertions(+), 69 deletions(-) diff --git a/src/connman.h b/src/connman.h index 945d8e8..272b334 100644 --- a/src/connman.h +++ b/src/connman.h @@ -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); diff --git a/src/device.c b/src/device.c index 12fa49a..be184e1 100644 --- a/src/device.c +++ b/src/device.c @@ -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; diff --git a/src/manager.c b/src/manager.c index d5542fd..a276e0b 100644 --- a/src/manager.c +++ b/src/manager.c @@ -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, diff --git a/src/technology.c b/src/technology.c index c68a649..cb065e2 100644 --- a/src/technology.c +++ b/src/technology.c @@ -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) { -- 2.7.4