Instead of parse 2 vectors of Enabled and Disabled technologies, use the
technology interface with its 'state' field. It's much easier to extend
this design than the other, also allowing the UI to be easily updated
upon devices (dis)appearing.

This breaks compatibility with connman version < 0.49.
---
 src/modules/connman/e_mod_config.c |   45 ++++-----
 src/modules/connman/e_mod_main.c   |  187 +++++++++++++++++++-----------------
 src/modules/connman/e_mod_main.h   |   20 ++++-
 3 files changed, 136 insertions(+), 116 deletions(-)

diff --git a/src/modules/connman/e_mod_config.c 
b/src/modules/connman/e_mod_config.c
index 62efd24..1db00ed 100644
--- a/src/modules/connman/e_mod_config.c
+++ b/src/modules/connman/e_mod_config.c
@@ -2,12 +2,17 @@
 
 extern const char _e_connman_Name[];
 
+extern const char *e_str_enabled;
+extern const char *e_str_available;
+extern const char *e_str_connected;
+extern const char *e_str_offline;
+
 struct connman_config_technologies
 {
    EINA_INLIST;
    Evas_Object *obj;
    E_Connman_Technology *technology;
-   int val;
+   int enabled;
 };
 
 struct _E_Config_Dialog_Data
@@ -125,7 +130,7 @@ _connman_service_move(E_Connman_Service *service, const 
E_Connman_Service *servi
 
 struct _connman_technology_onoff_data
 {
-   const char *name;
+   const char *type;
    E_Connman_Module_Context *ctxt;
    bool on;
 };
@@ -140,25 +145,14 @@ _connman_technology_onoff_cb(void *data, DBusMessage *msg 
__UNUSED__, DBusError
        dbus_error_free(error);
      }
    else
-     {
-       /* TODO: update config dialog */
-       E_Connman_Technology *t;
-       t = _connman_technology_find(d->ctxt, d->name);
-       if (t)
-         {
-            t->enabled = d->on;
-            DBG("Technology %s has been %s.", d->name, 
d->on?"enabled":"disabled");
-         }
-       else
-         WRN("Technology does not exist anymore: %s.", d->name);
-     }
+     DBG("Technology %s has been %s.", d->type, d->on?"enabled":"disabled");
 
-   eina_stringshare_del(d->name);
+   eina_stringshare_del(d->type);
    E_FREE(d);
 }
 
 static void
-_connman_technology_onoff(E_Connman_Module_Context *ctxt, const char 
*technology, bool on)
+_connman_technology_onoff(E_Connman_Module_Context *ctxt, const char *type, 
bool on)
 {
    int ret;
    struct _connman_technology_onoff_data *d;
@@ -170,23 +164,23 @@ _connman_technology_onoff(E_Connman_Module_Context *ctxt, 
const char *technology
        return;
      }
 
-   d->name = eina_stringshare_add(technology);
+   d->type = eina_stringshare_add(type);
    d->ctxt = ctxt;
    d->on = on;
 
    if(on)
-      ret = e_connman_manager_technology_enable(technology, 
_connman_technology_onoff_cb, d);
+      ret = e_connman_manager_technology_enable(type, 
_connman_technology_onoff_cb, d);
    else
-      ret = e_connman_manager_technology_disable(technology, 
_connman_technology_onoff_cb, d);
+      ret = e_connman_manager_technology_disable(type, 
_connman_technology_onoff_cb, d);
 
    if(!ret)
      {
-       eina_stringshare_del(d->name);
+       eina_stringshare_del(type);
        E_FREE(d);
      }
 
    return;
-  }
+}
 
 E_Config_Dialog *
 e_connman_config_dialog_new(E_Container *con, E_Connman_Module_Context *ctxt)
@@ -542,8 +536,8 @@ _switches_page_create_technologies(Evas *evas, 
E_Connman_Module_Context *ctxt, s
      {
        struct connman_config_technologies *t_list = E_NEW(struct 
connman_config_technologies, 1);
        t_list->technology = t;
-       t_list->val = t->enabled;
-       t_list->obj = e_widget_check_add(evas, _(t->name), &t_list->val);
+       t_list->enabled = ((t->state == e_str_enabled) || (t->state == 
e_str_connected));
+       t_list->obj = e_widget_check_add(evas, _(t->name), &t_list->enabled);
 
        ui->technologies = eina_inlist_append(ui->technologies, 
EINA_INLIST_GET(t_list));
        e_widget_framelist_object_append(ui->type_frame, t_list->obj);
@@ -599,8 +593,9 @@ _basic_apply(E_Config_Dialog *dialog __UNUSED__, 
E_Config_Dialog_Data *cfdata)
 
    EINA_INLIST_FOREACH(sw->technologies, t)
      {
-       if (t->val != t->technology->enabled)
-         _connman_technology_onoff(ctxt, t->technology->name, t->val);
+       int was_enabled = ((t->technology->state == e_str_enabled) || 
(t->technology->state == e_str_connected));
+       if (t->enabled != was_enabled)
+         _connman_technology_onoff(ctxt, t->technology->type, t->enabled);
      }
    if (ctxt->offline_mode != sw->offline_mode)
      _connman_toggle_offline_mode(ctxt);
diff --git a/src/modules/connman/e_mod_main.c b/src/modules/connman/e_mod_main.c
index dad25d8..bbbd0ce 100644
--- a/src/modules/connman/e_mod_main.c
+++ b/src/modules/connman/e_mod_main.c
@@ -45,14 +45,10 @@ static const char *e_str_online = NULL;
 static const char *e_str_disconnect = NULL;
 static const char *e_str_failure = NULL;
 
-static struct _Connman_Technologies_Names
-{
-   const char **names;
-   unsigned int count;
-} _connman_enabled_technologies = {
-     NULL,
-     0
-};
+const char *e_str_enabled = NULL;
+const char *e_str_available = NULL;
+const char *e_str_connected = NULL;
+const char *e_str_offline = NULL;
 
 static void _connman_service_ask_pass_and_connect(E_Connman_Service *service);
 static void _connman_default_service_changed_delayed(E_Connman_Module_Context 
*ctxt);
@@ -449,6 +445,76 @@ _connman_service_new(E_Connman_Module_Context *ctxt, 
E_Connman_Element *element)
    return service;
 }
 
+
+#define GSTR(name_, getter)                    \
+   str = NULL;                                 \
+   if (!getter(element, &str))                 \
+     str = NULL;                               \
+   eina_stringshare_replace(&t->name_, str)
+
+static void
+_connman_technology_free(E_Connman_Technology *t)
+{
+   eina_stringshare_del(t->path);
+   eina_stringshare_del(t->name);
+   eina_stringshare_del(t->type);
+   eina_stringshare_del(t->state);
+
+   E_FREE(t);
+}
+
+static void
+_connman_technology_changed(void *data, const E_Connman_Element *element)
+{
+   E_Connman_Technology *t = data;
+   const char *str;
+
+   GSTR(name, e_connman_technology_name_get);
+   GSTR(type, e_connman_technology_type_get);
+   GSTR(state, e_connman_technology_state_get);
+}
+
+static void
+_connman_technology_freed(void *data)
+{
+   E_Connman_Technology *t = data;
+   E_Connman_Module_Context *ctxt = t->ctxt;
+
+   ctxt->technologies = eina_inlist_remove
+     (ctxt->technologies, EINA_INLIST_GET(t));
+
+   _connman_technology_free(t);
+}
+
+static E_Connman_Technology *
+_connman_technology_new(E_Connman_Module_Context *ctxt, E_Connman_Element 
*element)
+{
+   E_Connman_Technology *t;
+   const char *str;
+
+   if (!element)
+     return NULL;
+
+   t = E_NEW(E_Connman_Technology, 1);
+   if (!t)
+     return NULL;
+
+   t->ctxt = ctxt;
+   t->element = element;
+   t->path = eina_stringshare_add(element->path);
+
+   GSTR(name, e_connman_technology_name_get);
+   GSTR(type, e_connman_technology_type_get);
+   GSTR(state, e_connman_technology_state_get);
+
+   e_connman_element_listener_add
+     (element, _connman_technology_changed, t,
+      _connman_technology_freed);
+
+   return t;
+}
+#undef GSTR
+
 static void
 _connman_service_disconnect_cb(void *data, DBusMessage *msg __UNUSED__, 
DBusError *error)
 {
@@ -634,20 +700,6 @@ _connman_services_free(E_Connman_Module_Context *ctxt)
      }
 }
 
-E_Connman_Technology *
-_connman_technology_find(E_Connman_Module_Context *ctxt, const char* name)
-{
-   E_Connman_Technology *t;
-
-   EINA_INLIST_FOREACH(ctxt->technologies, t)
-     {
-       if (!strcmp(t->name, name))
-         return t;
-     }
-
-   return NULL;
-}
-
 static inline Eina_Bool
 _connman_services_element_exists(const E_Connman_Module_Context *ctxt, const 
E_Connman_Element *element)
 {
@@ -661,70 +713,19 @@ _connman_services_element_exists(const 
E_Connman_Module_Context *ctxt, const E_C
 }
 
 static inline Eina_Bool
-_connman_technology_exists(const E_Connman_Module_Context *ctxt, const char* 
name)
+_connman_technologies_element_exists(const E_Connman_Module_Context *ctxt, 
const E_Connman_Element *element)
 {
    const E_Connman_Technology *t;
 
    EINA_INLIST_FOREACH(ctxt->technologies, t)
      {
-       if (t->name == name)
+       if (t->path == element->path)
          return EINA_TRUE;
      }
 
    return EINA_FALSE;
 }
 
-static inline int
-_connman_technologies_enabled_update()
-{
-   int ret;
-   if (_connman_enabled_technologies.names)
-     free(_connman_enabled_technologies.names);
-
-   ret = e_connman_manager_technologies_enabled_get
-      (&_connman_enabled_technologies.count, 
&_connman_enabled_technologies.names);
-   if (!ret)
-     {
-       WRN("Failed to query enabled technologies.");
-        return 0;
-     }
-   return 1;
-}
-
-static inline int
-_connman_technology_enabled(const char *type)
-{
-   unsigned int i;
-   if (!_connman_enabled_technologies.names && 
!_connman_technologies_enabled_update())
-     return 0;
-   DBG("%d technologies enabled.", _connman_enabled_technologies.count);
-
-   for (i = 0; i < _connman_enabled_technologies.count; i++)
-     {
-        if(!strcmp(type, _connman_enabled_technologies.names[i]))
-          {
-            DBG("Technology %s is enabled.", type);
-             return 1;
-          }
-
-     }
-   DBG("Technology %s is disabled.", type);
-   return 0;
-}
-
-static void
-_connman_technologies_free(E_Connman_Module_Context *ctxt)
-{
-   while (ctxt->technologies)
-     {
-       E_Connman_Technology *t = (E_Connman_Technology *) ctxt->technologies;
-       eina_stringshare_del(t->name);
-       ctxt->technologies = eina_inlist_remove(ctxt->technologies, 
EINA_INLIST_GET(t));
-       E_FREE(t);
-     }
-   if (_connman_enabled_technologies.names)
-      free(_connman_enabled_technologies.names);
-}
 void
 _connman_request_scan_cb(void *data __UNUSED__, DBusMessage *msg __UNUSED__, 
DBusError *error)
 {
@@ -740,34 +741,34 @@ _connman_request_scan_cb(void *data __UNUSED__, 
DBusMessage *msg __UNUSED__, DBu
 static void
 _connman_technologies_load(E_Connman_Module_Context *ctxt)
 {
-   const char **names;
    unsigned int count, i;
+   E_Connman_Element **elements;
 
-   if (!e_connman_manager_technologies_available_get(&count, &names))
+   if (!e_connman_manager_technologies_get(&count, &elements))
      return;
 
-   DBG("Available Technologies = %d.", count);
+   DBG("Technologies = %d.", count);
    for (i = 0; i < count; i++)
      {
-       const char *name = eina_stringshare_add(names[i]);
+       E_Connman_Element *e = elements[i];
        E_Connman_Technology *t;
 
-       if ((name == NULL) || _connman_technology_exists(ctxt, name))
-         {
-            eina_stringshare_del(name);
-            continue;
-         }
-       t = E_NEW(E_Connman_Technology, 1);
-       t->name = name;
-       t->enabled = _connman_technology_enabled(name);
-       ctxt->technologies = eina_inlist_append(ctxt->technologies, 
EINA_INLIST_GET(t));
+       if ((!e) || _connman_technologies_element_exists(ctxt, e))
+         continue;
+
+       t = _connman_technology_new(ctxt, e);
+       if (!t)
+         continue;
 
        DBG("Added technology: %s.", t->name);
+       ctxt->technologies = eina_inlist_append
+         (ctxt->technologies, EINA_INLIST_GET(t));
      }
 
    if (!e_connman_manager_request_scan("", _connman_request_scan_cb, NULL))
      ERR("Request scan on all technologies failed.");
-   free(names);
+
+   free(elements);
 }
 
 static void
@@ -1777,6 +1778,10 @@ _connman_status_stringshare_init(void)
    e_str_online = eina_stringshare_add(N_("online"));
    e_str_disconnect = eina_stringshare_add(N_("disconnect"));
    e_str_failure = eina_stringshare_add(N_("failure"));
+   e_str_enabled = eina_stringshare_add(N_("enabled"));
+   e_str_available = eina_stringshare_add(N_("available"));
+   e_str_connected = eina_stringshare_add(N_("connected"));
+   e_str_offline = eina_stringshare_add(N_("offline"));
 }
 
 static inline void
@@ -1790,6 +1795,10 @@ _connman_status_stringshare_del(void)
    eina_stringshare_replace(&e_str_online, NULL);
    eina_stringshare_replace(&e_str_disconnect, NULL);
    eina_stringshare_replace(&e_str_failure, NULL);
+   eina_stringshare_replace(&e_str_enabled, NULL);
+   eina_stringshare_replace(&e_str_available, NULL);
+   eina_stringshare_replace(&e_str_connected, NULL);
+   eina_stringshare_replace(&e_str_offline, NULL);
 }
 
 EAPI void *
diff --git a/src/modules/connman/e_mod_main.h b/src/modules/connman/e_mod_main.h
index d3e8ee2..8143fb3 100644
--- a/src/modules/connman/e_mod_main.h
+++ b/src/modules/connman/e_mod_main.h
@@ -76,8 +76,12 @@ struct E_Connman_Service
 struct E_Connman_Technology
 {
    EINA_INLIST;
+   E_Connman_Module_Context *ctxt;
+   E_Connman_Element *element;
+   const char *path;
    const char *name;
-   bool enabled;
+   const char *type;
+   const char *state;
 };
 
 struct E_Connman_Module_Context
@@ -120,7 +124,6 @@ EAPI int   e_modapi_save     (E_Module *m);
 const char *e_connman_theme_path(void);
 E_Config_Dialog *e_connman_config_dialog_new(E_Container *con, 
E_Connman_Module_Context *ctxt);
 void _connman_toggle_offline_mode(E_Connman_Module_Context *ctxt);
-E_Connman_Technology *_connman_technology_find(E_Connman_Module_Context *ctxt, 
const char* name);
 Evas_Object *_connman_service_new_list_item(Evas *evas, E_Connman_Service 
*service);
 
 static inline void
@@ -162,4 +165,17 @@ _connman_ctxt_find_service_stringshare(const 
E_Connman_Module_Context *ctxt, con
 
    return NULL;
 }
+
+static inline E_Connman_Technology *
+_connman_ctxt_technology_find_stringshare(const E_Connman_Module_Context 
*ctxt, const char *path)
+{
+   E_Connman_Technology *t;
+
+   EINA_INLIST_FOREACH(ctxt->technologies, t)
+      if (t->path == path)
+       return t;
+
+   return NULL;
+}
+
 #endif
-- 
1.7.0.1


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to