From fa0e75c2255edd7cecd8a1d63390e7e000cc7d83 Mon Sep 17 00:00:00 2001 From: Alok Barsode Date: Wed, 24 Aug 2011 16:44:14 +0300 Subject: [PATCH] technology: Redo offlinemode logic Traverse the list of technologies and enable/disable each instead of traversing the device list. --- src/connman.h | 5 ++--- src/device.c | 43 ------------------------------------------- src/manager.c | 4 +--- src/profile.c | 6 +----- src/technology.c | 32 +++++++++++++++++++++++++++----- 5 files changed, 31 insertions(+), 59 deletions(-) diff --git a/src/connman.h b/src/connman.h index de863e6..e11dcda 100644 --- a/src/connman.h +++ b/src/connman.h @@ -320,6 +320,7 @@ int __connman_technology_enabled(enum connman_service_type type); int __connman_technology_enable(enum connman_service_type type, DBusMessage *msg); int __connman_technology_disabled(enum connman_service_type type); int __connman_technology_disable(enum connman_service_type type, DBusMessage *msg); +int __connman_technology_set_offlinemode(connman_bool_t offlinemode); int __connman_technology_add_rfkill(unsigned int index, enum connman_service_type type, @@ -382,8 +383,6 @@ connman_bool_t __connman_device_get_reconnect(struct connman_device *device); const char *__connman_device_get_type(struct connman_device *device); -int __connman_device_set_offlinemode(connman_bool_t offlinemode); - #include int __connman_network_init(void); @@ -421,7 +420,7 @@ int __connman_profile_init(); void __connman_profile_cleanup(void); connman_bool_t __connman_profile_get_offlinemode(void); -int __connman_profile_set_offlinemode(connman_bool_t offlinemode, connman_bool_t all_devices); +int __connman_profile_set_offlinemode(connman_bool_t offlinemode); int __connman_profile_save_default(void); void __connman_profile_list(DBusMessageIter *iter, void *user_data); diff --git a/src/device.c b/src/device.c index 669c6a8..60c50fd 100644 --- a/src/device.c +++ b/src/device.c @@ -1015,49 +1015,6 @@ const char *connman_device_get_string(struct connman_device *device, return NULL; } -static void set_offlinemode(struct connman_device *device, - connman_bool_t offlinemode) -{ - connman_bool_t powered; - - DBG("device %p name %s", device, device->name); - - if (device == NULL) - return; - - device->offlinemode = offlinemode; - - if (device->blocked == TRUE) - return; - - powered = (offlinemode == TRUE) ? FALSE : TRUE; - - if (device->powered == powered) - return; - - if (device->powered_persistent == FALSE) - powered = FALSE; - - set_powered(device, powered); -} - -int __connman_device_set_offlinemode(connman_bool_t offlinemode) -{ - GSList *list; - - DBG("offlinmode %d", offlinemode); - - for (list = device_list; list != NULL; list = list->next) { - struct connman_device *device = list->data; - - set_offlinemode(device, offlinemode); - } - - __connman_notifier_offlinemode(offlinemode); - - return 0; -} - void __connman_device_increase_connections(struct connman_device *device) { if (device == NULL) diff --git a/src/manager.c b/src/manager.c index 54de643..f39c2be 100644 --- a/src/manager.c +++ b/src/manager.c @@ -121,9 +121,7 @@ static DBusMessage *set_property(DBusConnection *conn, dbus_message_iter_get_basic(&value, &offlinemode); - __connman_profile_set_offlinemode(offlinemode, TRUE); - - __connman_profile_save_default(); + __connman_technology_set_offlinemode(offlinemode); } else if (g_str_equal(name, "ActiveProfile") == TRUE) { const char *str; diff --git a/src/profile.c b/src/profile.c index 0df255a..11e2adc 100644 --- a/src/profile.c +++ b/src/profile.c @@ -61,8 +61,7 @@ connman_bool_t __connman_profile_get_offlinemode(void) return default_profile->offlinemode; } -int __connman_profile_set_offlinemode(connman_bool_t offlinemode, - connman_bool_t all_devices) +int __connman_profile_set_offlinemode(connman_bool_t offlinemode) { DBG("offlinemode %d", offlinemode); @@ -75,9 +74,6 @@ int __connman_profile_set_offlinemode(connman_bool_t offlinemode, default_profile->offlinemode = offlinemode; offlinemode_changed(default_profile); - if (all_devices) - __connman_device_set_offlinemode(offlinemode); - return 0; } diff --git a/src/technology.c b/src/technology.c index fb7f058..19a096d 100644 --- a/src/technology.c +++ b/src/technology.c @@ -707,11 +707,6 @@ int __connman_technology_enabled(enum connman_service_type type) state_changed(technology); } - if (__connman_profile_get_offlinemode() == TRUE) { - __connman_profile_set_offlinemode(FALSE, FALSE); - __connman_profile_save_default(); - } - if (technology->pending_reply != NULL) { g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID); dbus_message_unref(technology->pending_reply); @@ -873,6 +868,33 @@ done: return err; } +int __connman_technology_set_offlinemode(connman_bool_t offlinemode) +{ + GSList *list; + int err = -EINVAL; + + DBG("offlinemode %s", offlinemode ? "On" : "Off"); + + /* Traverse technology list, enable/disable each technology. */ + for (list = technology_list; list; list = list->next) { + struct connman_technology *technology = list->data; + + if (offlinemode) + err = __connman_technology_disable(technology->type, NULL); + if (!offlinemode && technology->enable_persistent) + err = __connman_technology_enable(technology->type, NULL); + } + + if (err == 0 || err == -EINPROGRESS) { + __connman_profile_set_offlinemode(offlinemode); + __connman_profile_save_default(); + + __connman_notifier_offlinemode(offlinemode); + } + + return err; +} + static void technology_blocked(struct connman_technology *technology, connman_bool_t blocked) { -- 2.7.4