From 911b920a34803672825a5e085c602dd0ff037e34 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Mon, 15 Oct 2012 15:35:13 +0300 Subject: [PATCH] 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. --- src/technology.c | 66 ++++++++++++++++++++++++-------------------------------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/src/technology.c b/src/technology.c index c84fff9..3f7141a 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, -- 2.7.4