From: Alok Barsode <[email protected]>

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 |   29 ++++++++++++++++++++++++++++-
 5 files changed, 32 insertions(+), 55 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index c7d9b95..2d9d957 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -311,6 +311,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,
@@ -372,8 +373,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 <connman/network.h>
 
 int __connman_network_init(void);
@@ -409,7 +408,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 1596a93..0817561 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1001,49 +1001,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 82cccb6..afa0ae3 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -118,9 +118,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 ef38b56..8865483 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -717,7 +717,7 @@ int __connman_technology_enabled(enum connman_service_type 
type)
        }
 
        if (__connman_profile_get_offlinemode() == TRUE) {
-               __connman_profile_set_offlinemode(FALSE, FALSE);
+               __connman_profile_set_offlinemode(FALSE);
                __connman_profile_save_default();
        }
 
@@ -879,6 +879,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);
+               else
+                       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)
 {
-- 
1.7.1

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to