summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>2012-10-15 15:35:13 +0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-10-16 15:02:45 +0300
commit911b920a34803672825a5e085c602dd0ff037e34 (patch)
tree612b2f568e4e9e0b2dd16d9c5bc17bcd171c4cdf
parent1b0448697474a2d0f78a083e606083478c0f1d69 (diff)
downloadconnman-911b920a34803672825a5e085c602dd0ff037e34.tar.gz
connman-911b920a34803672825a5e085c602dd0ff037e34.tar.bz2
connman-911b920a34803672825a5e085c602dd0ff037e34.zip
technology: Refactor how a technology is enabled or disabled
Refactor how a device list is enabled/disabled: this will be useful for coming patches. Simplify also the code, and remove useless gotos.
-rw-r--r--src/technology.c66
1 files changed, 28 insertions, 38 deletions
diff --git a/src/technology.c b/src/technology.c
index c84fff9d..3f7141ad 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -579,58 +579,55 @@ static gboolean technology_pending_reply(gpointer user_data)
return FALSE;
}
-static int technology_enable(struct connman_technology *technology,
- connman_bool_t hardblock)
+static int technology_affect_devices(struct connman_technology *technology,
+ connman_bool_t enable_device)
{
GSList *list;
int err = 0;
+ for (list = technology->device_list; list; list = list->next) {
+ struct connman_device *device = list->data;
+
+ if (enable_device == TRUE)
+ err = __connman_device_enable(device);
+ else
+ err = __connman_device_disable(device);
+ }
+
+ return err;
+}
+
+static int technology_enable(struct connman_technology *technology,
+ connman_bool_t hardblock)
+{
DBG("technology %p enable", technology);
__sync_synchronize();
- if (technology->enabled > 0) {
- err = -EALREADY;
- goto done;
- }
+ if (technology->enabled > 0)
+ return -EALREADY;
- if (technology->pending_reply != NULL) {
- err = -EBUSY;
- goto done;
- }
+ if (technology->pending_reply != NULL)
+ return -EBUSY;
if (hardblock == TRUE && technology->enable_persistent == FALSE)
- goto done;
+ return 0;
__connman_rfkill_block(technology->type, FALSE);
- for (list = technology->device_list; list; list = list->next) {
- struct connman_device *device = list->data;
-
- err = __connman_device_enable(device);
- }
-
-done:
- return err;
+ return technology_affect_devices(technology, TRUE);
}
static int technology_disable(struct connman_technology *technology,
connman_bool_t hardblock)
{
- GSList *list;
- int err = 0;
-
DBG("technology %p disable", technology);
__sync_synchronize();
- if (technology->enabled == 0) {
- err = -EALREADY;
- goto done;
- }
+ if (technology->enabled == 0)
+ return -EALREADY;
- if (technology->pending_reply != NULL) {
- err = -EBUSY;
- goto done;
- }
+ if (technology->pending_reply != NULL)
+ return -EBUSY;
if (technology->tethering == TRUE)
set_tethering(technology, FALSE);
@@ -638,14 +635,7 @@ static int technology_disable(struct connman_technology *technology,
if (hardblock == FALSE)
__connman_rfkill_block(technology->type, TRUE);
- for (list = technology->device_list; list; list = list->next) {
- struct connman_device *device = list->data;
-
- err = __connman_device_disable(device);
- }
-
-done:
- return err;
+ return technology_affect_devices(technology, FALSE);
}
static DBusMessage *set_powered(struct connman_technology *technology,