[PATCH 06/16] e_dbus/ofono: Add Modem interface.
authorbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 27 Feb 2010 05:27:09 +0000 (05:27 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 27 Feb 2010 05:27:09 +0000 (05:27 +0000)
By: João Paulo Rechi Vita <jprvita@profusion.mobi>

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/e_dbus@46558 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/bin/e_dbus_ofono_test.c
src/lib/ofono/E_Ofono.h
src/lib/ofono/Makefile.am
src/lib/ofono/e_ofono.c
src/lib/ofono/e_ofono_element.c
src/lib/ofono/e_ofono_modem.c [new file with mode: 0644]
src/lib/ofono/e_ofono_private.h

index bcecc8b..4df2795 100644 (file)
@@ -268,6 +268,34 @@ _on_cmd_manager_get(char *cmd, char *args)
    return 1;
 }
 
+/* Modem Commands */
+
+static int
+_on_cmd_modem_set_powered(char *cmd, char *args)
+{
+   char *next_args;
+   Eina_Bool powered;
+   E_Ofono_Element *element = _element_from_args("org.ofono.Modem", args, &next_args);
+
+   if (!element)
+          return 1;
+
+   if (!args)
+     {
+       fputs("ERROR: missing the powered value\n", stderr);
+       return 1;
+     }
+
+   powered = !!atol(next_args);
+
+   if (e_ofono_modem_powered_set
+       (element, powered, _method_success_check, "modem_set_powered"))
+     printf(":::Modem %s Powered set to %hhu\n", element->path, powered);
+   else
+     fputs("ERROR: can't set Modem Powered\n", stderr);
+   return 1;
+}
+
 static int
 _on_input(void *data, Ecore_Fd_Handler *fd_handler)
 {
@@ -284,6 +312,7 @@ _on_input(void *data, Ecore_Fd_Handler *fd_handler)
      {"get_properties", _on_cmd_get_properties},
      {"set_property", _on_cmd_property_set},
      {"manager_get", _on_cmd_manager_get},
+     {"modem_set_powered", _on_cmd_modem_set_powered},
      {NULL, NULL}
    };
 
index 4b28bd3..8ba83fb 100644 (file)
@@ -71,6 +71,11 @@ extern "C" {
   /* Manager Methods */
   EAPI E_Ofono_Element *e_ofono_manager_get(void) EINA_WARN_UNUSED_RESULT;
 
+  /* Modem Methods */
+  EAPI bool e_ofono_modem_powered_get(E_Ofono_Element *element, Eina_Bool *powered);
+  EAPI bool e_ofono_modem_powered_set(E_Ofono_Element *element, Eina_Bool powered, E_DBus_Method_Return_Cb cb, const void *data);
+  EAPI bool e_ofono_modem_name_get(E_Ofono_Element *element, const char **name);
+
   /* Low-Level API:
    *
    * Should just be used to work around problems until proper solution
index fca78b3..28ec51c 100644 (file)
@@ -14,7 +14,8 @@ E_Ofono.h \
 e_ofono_private.h \
 e_ofono.c \
 e_ofono_element.c \
-e_ofono_manager.c
+e_ofono_manager.c \
+e_ofono_modem.c
 
 libeofono_la_LIBADD = \
 @EDBUS_LIBS@ @EVAS_LIBS@ \
index a6b11d4..3db7d8c 100644 (file)
@@ -22,6 +22,10 @@ EAPI int E_OFONO_EVENT_ELEMENT_UPDATED = 0;
 
 const char *e_ofono_iface_manager = NULL;
 const char *e_ofono_prop_modems = NULL;
+const char *e_ofono_iface_modem = NULL;
+const char *e_ofono_prop_name = NULL;
+const char *e_ofono_prop_powered = NULL;
+const char *e_ofono_prop_interfaces = NULL;
 
 int _e_dbus_ofono_log_dom = -1;
 
@@ -219,6 +223,14 @@ e_ofono_system_init(E_DBus_Connection *edbus_conn)
                e_ofono_iface_manager = eina_stringshare_add("org.ofono.Manager");
        if (e_ofono_prop_modems == NULL)
                e_ofono_prop_modems = eina_stringshare_add("Modems");
+       if (e_ofono_iface_modem == NULL)
+               e_ofono_iface_modem = eina_stringshare_add("org.ofono.Modem");
+       if (e_ofono_prop_name == NULL)
+               e_ofono_prop_name = eina_stringshare_add("Name");
+       if (e_ofono_prop_powered == NULL)
+               e_ofono_prop_powered = eina_stringshare_add("Powered");
+       if (e_ofono_prop_interfaces == NULL)
+               e_ofono_prop_interfaces = eina_stringshare_add("Interfaces");
 
        e_ofono_conn = edbus_conn;
        cb_name_owner_changed = e_dbus_signal_handler_add
@@ -266,5 +278,9 @@ e_ofono_system_shutdown(void)
 
        _stringshare_del(&e_ofono_iface_manager);
        _stringshare_del(&e_ofono_prop_modems);
+       _stringshare_del(&e_ofono_iface_modem);
+       _stringshare_del(&e_ofono_prop_name);
+       _stringshare_del(&e_ofono_prop_powered);
+       _stringshare_del(&e_ofono_prop_interfaces);
        return 0;
 }
index c4a1afa..92573a4 100644 (file)
@@ -444,6 +444,10 @@ _e_ofono_element_get_interface(const char *key)
 
    switch (head)
      {
+      case 'M':
+        if (strcmp(tail, "odems") == 0)
+          interface = e_ofono_iface_modem;
+        break;
       default:
         break;
      }
@@ -1342,6 +1346,22 @@ _e_ofono_element_get_properties_callback(void *user_data, DBusMessage *msg, DBus
          {
             INF("property value changed %s (%c)", key, t);
             changed = 1;
+            if ((strcmp(key, "Interfaces") == 0) && value)
+              {
+                 char *interface;
+                 Eina_Array_Iterator iterator;
+                 unsigned int i;
+                 E_Ofono_Element *e;
+
+                 EINA_ARRAY_ITER_NEXT(((E_Ofono_Array*)value)->array, i,
+                                      interface, iterator)
+                   {
+                      DBG("Found interface %s on %s", interface, element->path);
+                      e = e_ofono_element_register(element->path, interface);
+                      if ((e) && (!e_ofono_element_properties_sync(e)))
+                        WRN("could not get properties of %s", e->path);
+                   }
+              }
          }
      }
    while (dbus_message_iter_next(&s_itr));
@@ -2132,6 +2152,23 @@ _e_ofono_element_property_changed_callback(void *data, DBusMessage *msg)
      {
        INF("property value changed %s (%c)", name, t);
        changed = 1;
+       if ((strcmp(name, "Interfaces") == 0) && value)
+         {
+            char *interface;
+            Eina_Array_Iterator iterator;
+            unsigned int i;
+            E_Ofono_Element *e;
+
+            EINA_ARRAY_ITER_NEXT(((E_Ofono_Array*)value)->array, i,
+                                 interface, iterator)
+              {
+                 DBG("Found interface %s on %s", interface, element->path);
+                 e_ofono_element_register(element->path, interface);
+                 e = e_ofono_element_register(element->path, interface);
+                 if ((e) && (!e_ofono_element_properties_sync(e)))
+                   WRN("could not get properties of %s", e->path);
+              }
+         }
      }
    if (changed)
      _e_ofono_element_listeners_call(element);
diff --git a/src/lib/ofono/e_ofono_modem.c b/src/lib/ofono/e_ofono_modem.c
new file mode 100644 (file)
index 0000000..6a0bbf0
--- /dev/null
@@ -0,0 +1,67 @@
+#include "e_ofono_private.h"
+
+/* TODO: add a getter for Interfaces property */
+
+/**
+ * Get property "Powered" value.
+ *
+ * @param powered where to store the property value, must be a pointer
+ *        to bool (bool *), it will not be allocated or
+ *        copied and references will be valid until element changes,
+ *        so copy it if you want to use it later.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_ofono_modem_powered_get(E_Ofono_Element *element, Eina_Bool *powered)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(powered, 0);
+
+   return e_ofono_element_property_get_stringshared
+     (element, e_ofono_prop_powered, NULL, powered);
+}
+
+/**
+ * Call method SetProperty("Powered", powered) at the given element on server.
+ *
+ *
+ * @param powered value 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.
+ */
+bool
+e_ofono_modem_powered_set(E_Ofono_Element *element, Eina_Bool powered, E_DBus_Method_Return_Cb cb, const void *data)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
+
+   return e_ofono_element_property_set_full
+     (element, e_ofono_prop_powered, DBUS_TYPE_BOOLEAN,
+      &powered, cb, data);
+}
+
+/**
+ * Get property "Name" 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 address where to store the property value, must be a pointer
+ *        to string (const char **), it will not be allocated or
+ *        copied and references will be valid until element changes,
+ *        so copy it if you want to use it later.
+ *
+ * @return 1 on success, 0 otherwise.
+ */
+bool
+e_ofono_modem_name_get(E_Ofono_Element *element, const char **name)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0);
+
+   return e_ofono_element_property_get_stringshared
+     (element, e_ofono_prop_name, NULL, name);
+}
index e63dcb2..e96a762 100644 (file)
 
     extern const char *e_ofono_iface_manager;
     extern const char *e_ofono_prop_modems;
+    extern const char *e_ofono_iface_modem;
+    extern const char *e_ofono_prop_name;
+    extern const char *e_ofono_prop_powered;
+    extern const char *e_ofono_prop_interfaces;
 
     extern int _e_dbus_ofono_log_dom;