more manager methods, not so useful, but they were easy.
authorbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 30 Dec 2009 20:33:40 +0000 (20:33 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 30 Dec 2009 20:33:40 +0000 (20:33 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/e_dbus@44812 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/bin/e_dbus_connman_test.c
src/bin/e_dbus_connman_test_api.c
src/lib/connman/E_Connman.h
src/lib/connman/e_connman.c
src/lib/connman/e_connman_element.c
src/lib/connman/e_connman_manager.c
src/lib/connman/e_connman_private.h

index de16f93..223a853 100644 (file)
@@ -427,6 +427,58 @@ _on_cmd_manager_technology_disable(char *cmd, char *args)
    return 1;
 }
 
+static int
+_on_cmd_manager_profile_remove(char *cmd, char *args)
+{
+   E_Connman_Element *e;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the profile path\n", stderr);
+       return 1;
+     }
+   _tok(args);
+
+   e = e_connman_profile_get(args);
+   if (e_connman_manager_profile_remove(e, NULL, NULL))
+     printf(":::Manager Remove Profile %s\n", args);
+   else
+     fputs("ERROR: can't remove profile from manager\n", stderr);
+   return 1;
+}
+
+static int
+_on_cmd_manager_profile_get_active(char *cmd, char *args)
+{
+   E_Connman_Element *e;
+
+   if (!e_connman_manager_profile_active_get(&e))
+     fputs("ERROR: can't active_get profile from manager\n", stderr);
+   else
+     e_connman_element_print(stderr, e);
+   return 1;
+}
+
+static int
+_on_cmd_manager_profile_set_active(char *cmd, char *args)
+{
+   E_Connman_Element *e;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the profile path\n", stderr);
+       return 1;
+     }
+   _tok(args);
+
+   e = e_connman_profile_get(args);
+   if (e_connman_manager_profile_active_set(e, NULL, NULL))
+     printf(":::Manager Active Profile set to %s\n", args);
+   else
+     fputs("ERROR: can't set active profile\n", stderr);
+   return 1;
+}
+
 /* Device Commands */
 static int
 _on_cmd_device_propose_scan(char *cmd, char *args)
@@ -744,7 +796,7 @@ _on_cmd_profile_set_name(char *cmd, char *args)
 
    e = e_connman_profile_get(path);
    if (e_connman_profile_name_set(e, next_args, NULL, NULL))
-     printf(":::Profile %s Name set to %hhu\n", path, next_args);
+     printf(":::Profile %s Name set to %s\n", path, next_args);
    else
      fputs("ERROR: can't set profile name\n", stderr);
    return 1;
@@ -1775,6 +1827,9 @@ _on_input(void *data, Ecore_Fd_Handler *fd_handler)
      {"manager_request_scan", _on_cmd_manager_request_scan},
      {"manager_technology_enable", _on_cmd_manager_technology_enable},
      {"manager_technology_disable", _on_cmd_manager_technology_disable},
+     {"manager_profile_remove", _on_cmd_manager_profile_remove},
+     {"manager_profile_get_active", _on_cmd_manager_profile_get_active},
+     {"manager_profile_set_active", _on_cmd_manager_profile_set_active},
      {"device_propose_scan", _on_cmd_device_propose_scan},
      {"device_get_address", _on_cmd_device_get_address},
      {"device_get_name", _on_cmd_device_get_name},
index ac60e3c..64964fa 100644 (file)
@@ -146,6 +146,22 @@ _test_elements_get(E_Connman_Element *element, const char *name, bool (*func)(co
 }
 
 static bool
+_test_element_get_global(const char *name, bool (*func)(E_Connman_Element **value))
+{
+   E_Connman_Element *value;
+   bool ret;
+
+   INF("BEGIN: testing element get %s\n", name);
+   ret = func(&value);
+   if (ret)
+     INF("SUCCESS: testing element get %s: %p\n", name, value);
+   else
+     WRN("FAILURE: testing element get %s\n", name);
+
+   return ret;
+}
+
+static bool
 _test_elements_get_global(const char *name, bool (*func)(unsigned int *count, E_Connman_Element ***elements))
 {
    E_Connman_Element **value;
@@ -207,6 +223,7 @@ struct test_desc
      TEST_DESC_TYPE_UCHAR_ARRAY_GET,
      TEST_DESC_TYPE_ELEMENT_GET,
      TEST_DESC_TYPE_ELEMENTS_GET,
+     TEST_DESC_TYPE_ELEMENT_GET_GLOBAL,
      TEST_DESC_TYPE_ELEMENTS_GET_GLOBAL,
      TEST_DESC_TYPE_STRING_GET_GLOBAL,
      TEST_DESC_TYPE_BOOL_GET_GLOBAL,
@@ -220,6 +237,7 @@ struct test_desc
       bool (*uchar_array_get)(const E_Connman_Element *element, unsigned int *count, unsigned char **value);
       bool (*element_get)(const E_Connman_Element *element, E_Connman_Element **value);
       bool (*elements_get)(const E_Connman_Element *element, unsigned int *count, E_Connman_Element ***elements);
+      bool (*element_get_global)(E_Connman_Element **element);
       bool (*elements_get_global)(unsigned int *count, E_Connman_Element ***elements);
       bool (*string_get_global)(const char **value);
       bool (*bool_get_global)(bool *value);
@@ -242,6 +260,8 @@ struct test_desc
   {#_func, TEST_DESC_TYPE_ELEMENT_GET, .func.element_get=_func, may_fail}
 #define TEST_DESC_ELEMENTS_GET(_func, may_fail)                                \
   {#_func, TEST_DESC_TYPE_ELEMENTS_GET, .func.elements_get=_func, may_fail}
+#define TEST_DESC_ELEMENT_GET_GLOBAL(_func, may_fail)                  \
+  {#_func, TEST_DESC_TYPE_ELEMENT_GET_GLOBAL, .func.element_get_global=_func, may_fail}
 #define TEST_DESC_ELEMENTS_GET_GLOBAL(_func, may_fail)                 \
   {#_func, TEST_DESC_TYPE_ELEMENTS_GET_GLOBAL, .func.elements_get_global=_func, may_fail}
 #define TEST_DESC_STRING_GET_GLOBAL(_func, may_fail)                   \
@@ -287,6 +307,10 @@ _test_element(E_Connman_Element *element, const struct test_desc *test_descs)
              r = _test_elements_get
                (element, itr->name, itr->func.elements_get);
              break;
+          case TEST_DESC_TYPE_ELEMENT_GET_GLOBAL:
+             r = _test_element_get_global
+               (itr->name, itr->func.element_get_global);
+             break;
           case TEST_DESC_TYPE_ELEMENTS_GET_GLOBAL:
              r = _test_elements_get_global
                (itr->name, itr->func.elements_get_global);
@@ -340,6 +364,8 @@ static const struct test_desc test_desc_manager[] = {
   TEST_DESC_ELEMENTS_GET_GLOBAL(e_connman_manager_profiles_get, 0),
   TEST_DESC_ELEMENTS_GET_GLOBAL(e_connman_manager_devices_get, 0),
   TEST_DESC_ELEMENTS_GET_GLOBAL(e_connman_manager_services_get, 1),
+  TEST_DESC_STRING_GET_GLOBAL(e_connman_manager_technology_default_get, 0),
+  TEST_DESC_ELEMENT_GET_GLOBAL(e_connman_manager_profile_active_get, 0),
   TEST_DESC_SENTINEL
 };
 
index 84b578a..fe6d803 100644 (file)
@@ -59,6 +59,7 @@ extern "C" {
        Eina_Inlist *request_scan;
        Eina_Inlist *technology_enable;
        Eina_Inlist *technology_disable;
+       Eina_Inlist *profile_remove;
        Eina_Inlist *device_propose_scan;
        Eina_Inlist *service_connect;
        Eina_Inlist *service_disconnect;
@@ -100,10 +101,13 @@ extern "C" {
   EAPI bool e_connman_manager_technology_enable(const char *type, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
   EAPI bool e_connman_manager_technology_disable(const char *type, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
 
+  EAPI bool e_connman_manager_profile_remove(const E_Connman_Element *profile, E_DBus_Method_Return_Cb cb, const void *data) EINA_WARN_UNUSED_RESULT;
+
+  EAPI bool e_connman_manager_profile_active_get(E_Connman_Element **profile) EINA_ARG_NONNULL(1) EINA_PURE EINA_WARN_UNUSED_RESULT;
+  EAPI bool e_connman_manager_profile_active_set(const E_Connman_Element *profile, E_DBus_Method_Return_Cb cb, const void *data) EINA_WARN_UNUSED_RESULT;
+
+
   // TODO: profile_create()
-  // TODO: profile_remove()
-  // TODO: profile_active_get()
-  // TODO: profile_active_set()
   // TODO: technologies_available_get()
   // TODO: technologies_enabled_get()
   // TODO: technologies_connected_get()
index ef29ad6..5794909 100644 (file)
@@ -45,6 +45,7 @@ const char *e_connman_prop_policy = NULL;
 const char *e_connman_prop_powered = NULL;
 const char *e_connman_prop_priority = NULL;
 const char *e_connman_prop_profiles = NULL;
+const char *e_connman_prop_profile_active = NULL;
 const char *e_connman_prop_services = NULL;
 const char *e_connman_prop_remember = NULL;
 const char *e_connman_prop_scan_interval = NULL;
@@ -313,6 +314,8 @@ e_connman_system_init(E_DBus_Connection *edbus_conn)
      e_connman_prop_priority = eina_stringshare_add("Priority");
    if (e_connman_prop_profiles == NULL)
      e_connman_prop_profiles = eina_stringshare_add("Profiles");
+   if (e_connman_prop_profile_active == NULL)
+     e_connman_prop_profile_active = eina_stringshare_add("ActiveProfile");
    if (e_connman_prop_services == NULL)
      e_connman_prop_services = eina_stringshare_add("Services");
    if (e_connman_prop_remember == NULL)
@@ -438,6 +441,7 @@ e_connman_system_shutdown(void)
    _stringshare_del(&e_connman_prop_powered);
    _stringshare_del(&e_connman_prop_priority);
    _stringshare_del(&e_connman_prop_profiles);
+   _stringshare_del(&e_connman_prop_profile_active);
    _stringshare_del(&e_connman_prop_services);
    _stringshare_del(&e_connman_prop_remember);
    _stringshare_del(&e_connman_prop_scan_interval);
index dc03e4e..9870413 100644 (file)
@@ -705,6 +705,7 @@ e_connman_element_free(E_Connman_Element *element)
    e_connman_element_pending_cancel_and_free(&element->_pending.request_scan);
    e_connman_element_pending_cancel_and_free(&element->_pending.technology_enable);
    e_connman_element_pending_cancel_and_free(&element->_pending.technology_disable);
+   e_connman_element_pending_cancel_and_free(&element->_pending.profile_remove);
    e_connman_element_pending_cancel_and_free(&element->_pending.device_propose_scan);
    e_connman_element_pending_cancel_and_free(&element->_pending.service_connect);
    e_connman_element_pending_cancel_and_free(&element->_pending.service_disconnect);
index d10ffc8..c6c0bb6 100644 (file)
@@ -384,7 +384,7 @@ e_connman_manager_technology_disable(const char *type, E_DBus_Method_Return_Cb c
  * If zero is returned, then this call failed and parameter-returned
  * values shall be considered invalid.
  *
- *The current connected technology which holds the default route.
+ * The current connected technology which holds the default route.
  *
  * @param type where to store the property value, must be a pointer
  *        to string (const char **), it will not be allocated or
@@ -406,3 +406,106 @@ e_connman_manager_technology_default_get(const char **type)
    return e_connman_element_property_get_stringshared
      (element, e_connman_prop_technology_default, NULL, type);
 }
+
+/**
+ * Remove specified profile.
+ *
+ * Call method RemoveProfile(profile) on server.
+ *
+ * It is not possible to remove the current active profile. To remove
+ * the active profile a different one must be selected via
+ * ActiveProfile property first.
+ *
+ * At minimum one profile must be available all the time.
+ *
+ * @param profile element to remove, must be of type profile.
+ * @param cb function to call when server replies or some error happens.
+ * @param data data to give to cb when it is called.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_connman_manager_profile_remove(const E_Connman_Element *profile, E_DBus_Method_Return_Cb cb, const void *data)
+{
+   E_Connman_Element *element;
+   const char name[] = "RemoveProfile";
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(profile, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(profile->path, 0);
+
+   if (!e_connman_element_is_profile(profile))
+     return 0;
+
+   element = e_connman_manager_get();
+   if (!element)
+     return 0;
+
+   return e_connman_element_call_with_path
+     (element, name, profile->path, NULL,
+      &element->_pending.profile_remove, cb, data);
+}
+
+/**
+ * Get property "ActiveProfile" value.
+ *
+ * If this property isn't found then 0 is returned.
+ * If zero is returned, then this call failed and parameter-returned
+ * values shall be considered invalid.
+ *
+ * @param element where to store the element, just changed if return is 1
+ *
+ * @return 1 on success, 0 otherwise.
+ *
+ * @see e_connman_manager_profile_active_set()
+ */
+bool
+e_connman_manager_profile_active_get(E_Connman_Element **profile)
+{
+   E_Connman_Element *element;
+   char *profile_path;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(profile, 0);
+
+   element = e_connman_manager_get();
+   if (!element)
+     return 0;
+   if (!e_connman_element_property_get_stringshared
+       (element, e_connman_prop_profile_active, NULL, &profile_path))
+     return 0;
+   *profile = e_connman_element_get(profile_path);
+   return 1;
+}
+
+/**
+ * Call method SetProperty("ActiveProfile", profile) at the given
+ * element on server.
+ *
+ * This is a server call, not local, so it may fail and in that case
+ * no property is updated locally. If the value was set the event
+ * E_CONNMAN_EVENT_ELEMENT_UPDATED will be added to main loop.
+ *
+ * @param profile object to set.
+ * @param cb function to call when server replies or some error happens.
+ * @param data data to give to cb when it is called.
+ *
+ * @return 1 on success, 0 otherwise.
+ * @see e_connman_manager_profile_active_get()
+ */
+bool
+e_connman_manager_profile_active_set(const E_Connman_Element *profile, E_DBus_Method_Return_Cb cb, const void *data)
+{
+   E_Connman_Element *element;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(profile, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(profile->path, 0);
+
+   if (!e_connman_element_is_profile(profile))
+     return 0;
+
+   element = e_connman_manager_get();
+   if (!element)
+     return 0;
+   return e_connman_element_property_set_full
+     (element, e_connman_prop_profile_active, DBUS_TYPE_OBJECT_PATH,
+      profile->path, cb, data);
+}
index 2ea8f23..f98e5be 100644 (file)
@@ -36,6 +36,7 @@ extern const char *e_connman_prop_policy;
 extern const char *e_connman_prop_powered;
 extern const char *e_connman_prop_priority;
 extern const char *e_connman_prop_profiles;
+extern const char *e_connman_prop_profile_active;
 extern const char *e_connman_prop_services;
 extern const char *e_connman_prop_remember;
 extern const char *e_connman_prop_scan_interval;