edbus: Add input message to get property function
authorJosé Roberto de Souza <zehortigoza@profusion.mobi>
Fri, 16 Nov 2012 13:06:53 +0000 (13:06 +0000)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 16 Nov 2012 13:06:53 +0000 (13:06 +0000)
Without this message, it's not possible for user create the error
message. Also update the docs to clarify usage of the Get/Set callbacks.

Patch by: José Roberto de Souza  <zehortigoza@profusion.mobi>

SVN revision: 79380

src/examples/complex_types_server.c
src/lib/edbus_service.c
src/lib/edbus_service.h

index 26633d9..5ba149f 100644 (file)
@@ -203,7 +203,7 @@ _double_container(const EDBus_Service_Interface *iface, const EDBus_Message *msg
 }
 
 static Eina_Bool
-_properties_get(const EDBus_Service_Interface *iface, const char *propname, EDBus_Message_Iter *iter, EDBus_Message **error)
+_properties_get(const EDBus_Service_Interface *iface, const char *propname, EDBus_Message_Iter *iter, const EDBus_Message *request_msg, EDBus_Message **error)
 {
    printf("Properties_get - %s\n", propname);
    if (!strcmp(propname, "Resp2"))
index 2df6e6e..54f21b2 100644 (file)
@@ -216,7 +216,7 @@ _cb_property_get(const EDBus_Service_Interface *piface, const EDBus_Message *msg
    variant = edbus_message_iter_container_new(main_iter, 'v',
                                               prop->property->type);
 
-   ret = getter(iface, propname, variant, &error_reply);
+   ret = getter(iface, propname, variant, msg, &error_reply);
 
    if (ret)
      {
@@ -282,7 +282,7 @@ _cb_property_getall(const EDBus_Service_Interface *piface, const EDBus_Message *
         var = edbus_message_iter_container_new(entry, 'v',
                                                prop->property->type);
 
-        ret = getter(iface, prop->property->name, var, &error_reply);
+        ret = getter(iface, prop->property->name, var, msg, &error_reply);
 
         if (!ret)
           {
@@ -1034,7 +1034,7 @@ _idler_propschanged(void *data)
    while ((prop = eina_array_pop(iface->props_changed)))
      {
         EDBus_Message_Iter *entry, *var;
-        EDBus_Message *error_reply;
+        EDBus_Message *error_reply = NULL;
         Eina_Bool ret;
         EDBus_Property_Get_Cb getter = NULL;
 
@@ -1057,17 +1057,16 @@ _idler_propschanged(void *data)
         var = edbus_message_iter_container_new(entry, 'v',
                                                prop->property->type);
 
-        ret = getter(iface, prop->property->name, var, &error_reply);
-
+        ret = getter(iface, prop->property->name, var, NULL, &error_reply);
         if (!ret)
           {
-             const char *errorname, *errormsg;
-             if (error_reply &&
-                 edbus_message_error_get(error_reply, &errorname, &errormsg))
-               ERR("%s %s", errorname, errormsg);
-
              edbus_message_unref(msg);
-             if (error_reply) edbus_message_unref(error_reply);
+             if (error_reply)
+               {
+                  ERR("Error reply was set without pass any input message.");
+                  edbus_message_unref(error_reply);
+               }
+             ERR("Getter of property %s returned error.", prop->property->name);
              goto error;
           }
 
index d207003..415c366 100644 (file)
@@ -31,7 +31,34 @@ typedef struct _EDBus_Arg_Info
 typedef struct _EDBus_Service_Interface EDBus_Service_Interface;
 typedef EDBus_Message * (*EDBus_Method_Cb)(const EDBus_Service_Interface *iface, const EDBus_Message *message);
 
-typedef Eina_Bool (*EDBus_Property_Get_Cb)(const EDBus_Service_Interface *iface, const char *propname, EDBus_Message_Iter *iter, EDBus_Message **error);
+/**
+ * Callback function to append property value to message.
+ *
+ * @param iface interface of property
+ * @param propname name of property
+ * @param iter variant iterator in which value must be appended
+ * @param request_msg message that request property
+ * @param error if a error happen you must set a message error to be send caller
+ *
+ * @return EINA_TRUE if success
+ *
+ * @note request_msg and error arguments are only different from NULL when a
+ * client request a property with Properties.Get or Properties.GetAll. Upon
+ * calls to edbus_service_property_changed(), this callback will also be called.
+ * It's a mistake to return an error in this case because if a property changed,
+ * it must have a new value set and it should be able to be read.
+ */
+typedef Eina_Bool (*EDBus_Property_Get_Cb)(const EDBus_Service_Interface *iface, const char *propname, EDBus_Message_Iter *iter, const EDBus_Message *request_msg, EDBus_Message **error);
+
+/**
+ * Callback function to set property value from message.
+ *
+ * @param iface interface of property
+ * @param propname name of property
+ * @param input_msg message call where you have to get value
+ *
+ * @return Message of response, could be a simple method_return, error or NULL to send response later.
+ */
 typedef EDBus_Message *(*EDBus_Property_Set_Cb)(const EDBus_Service_Interface *iface, const char *propname, const EDBus_Message *input_msg);
 
 typedef struct _EDBus_Method