e_dbus/connman: set array property
authorlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 14 Nov 2011 15:20:10 +0000 (15:20 +0000)
committerlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 14 Nov 2011 15:20:10 +0000 (15:20 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/e_dbus@65187 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/connman/E_Connman.h
src/lib/connman/e_connman_element.c

index 2e92d0d..2d76be7 100644 (file)
@@ -217,6 +217,8 @@ EAPI void                   e_connman_element_properties_list(const E_Connman_El
 
 EAPI Eina_Bool              e_connman_element_property_set(E_Connman_Element *element, const char *prop, int type, const void *value) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
 EAPI Eina_Bool              e_connman_element_property_set_full(E_Connman_Element *element, const char *prop, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
+EAPI Eina_Bool              e_connman_element_property_array_set_full(E_Connman_Element *element, const char *prop, int type, const Eina_List *values, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT;
+
 EAPI Eina_Bool              e_connman_element_property_dict_set_full(E_Connman_Element *element, const char *prop, const char *key, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT;
 
 EAPI Eina_Bool              e_connman_element_property_type_get_stringshared(const E_Connman_Element *element, const char *name, int *type) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT;
index 3a2f6f6..8d1524d 100644 (file)
@@ -1575,6 +1575,71 @@ e_connman_element_property_set_full(E_Connman_Element *element, const char *prop
 }
 
 /**
+ * Call method SetProperty(prop, value) at the given element on server, when
+ * value is an array.
+ *
+ * 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 element to call method on server.
+ * @param prop property name.
+ * @param type DBus type to use for value.
+ * @param value pointer to value, just like regular DBus, see
+ *        dbus_message_iter_append_basic().
+ * @param cb function to call when server replies or some error happens.
+ * @param data data to give to cb when it is called.
+ *
+ * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
+ */
+Eina_Bool
+e_connman_element_property_array_set_full(E_Connman_Element *element, const char *prop, int type, const Eina_List *values, E_DBus_Method_Return_Cb cb, const void *data)
+{
+   const char name[] = "SetProperty";
+   char type_sig[2] = { type, '\0'};
+   char array_sig[3] = { DBUS_TYPE_ARRAY, type, '\0' };
+   DBusMessage *msg;
+   DBusMessageIter itr, variant, array;
+   const Eina_List *l;
+   void *entry;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(element, EINA_FALSE);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(prop, EINA_FALSE);
+
+   msg = dbus_message_new_method_call
+         (e_connman_system_bus_name_get(), element->path, element->interface, name);
+
+   if (!msg)
+      return EINA_FALSE;
+
+   dbus_message_iter_init_append(msg, &itr);
+   dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &prop);
+
+   dbus_message_iter_open_container(&itr, DBUS_TYPE_VARIANT, array_sig,
+                                    &variant);
+   dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY, type_sig,
+                                    &array);
+
+   if (type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH)
+     {
+        EINA_LIST_FOREACH(values, l, entry)
+           dbus_message_iter_append_basic(&array, type, &entry);
+     }
+   else
+     {
+        EINA_LIST_FOREACH(values, l, entry)
+           dbus_message_iter_append_basic(&array, type, entry);
+     }
+
+   dbus_message_iter_close_container(&variant, &array);
+   dbus_message_iter_close_container(&itr, &variant);
+
+   return e_connman_element_message_send(element, name, NULL, msg,
+                                         &element->_pending.property_set,
+                                         cb, data);
+}
+
+/**
  * Call method SetProperty(prop, value) at the given element on server.
  *
  * This is the simple version and there is no check of server reply