Enlightenment CVS committal

Author  : rephorm
Project : e17
Module  : proto

Dir     : e17/proto/e_dbus/src/lib/dbus


Modified Files:
        E_DBus.h e_dbus_interfaces.c e_dbus_message.c e_dbus_methods.c 
        e_dbus_signal.c 


Log Message:

playing around with the api a bit - use a single callback instead of separate 
reply / error callbacks

===================================================================
RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/E_DBus.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- E_DBus.h    20 Mar 2007 04:45:06 -0000      1.2
+++ E_DBus.h    20 Mar 2007 06:34:13 -0000      1.3
@@ -17,8 +17,7 @@
 typedef struct E_DBus_Signal_Handler E_DBus_Signal_Handler;
 
 typedef DBusMessage *(* E_DBus_Object_Method_Cb)(E_DBus_Object *obj, 
DBusMessage *message);
-typedef void (*E_DBus_Method_Return_Cb) (void *data, DBusMessage *msg);
-typedef void (*E_DBus_Error_Cb) (void *data, const char *error_name, const 
char *error_msg);
+typedef void (*E_DBus_Method_Return_Cb) (void *data, DBusMessage *msg, 
DBusError *error);
 typedef void (*E_DBus_Signal_Cb) (void *data, DBusMessage *msg);
 
 int e_dbus_init(void);
@@ -40,7 +39,7 @@
 /* sending method calls */
 
 
-DBusPendingCall *e_dbus_message_send(DBusConnection *conn, DBusMessage *msg, 
E_DBus_Method_Return_Cb cb_return, E_DBus_Error_Cb cb_error, int timeout, void 
*data);
+DBusPendingCall *e_dbus_message_send(DBusConnection *conn, DBusMessage *msg, 
E_DBus_Method_Return_Cb cb_return, int timeout, void *data);
 
 
 /* signal receiving */
@@ -54,45 +53,45 @@
 void e_dbus_request_name(DBusConnection *conn, const char *name, 
                          unsigned int flags,
                          E_DBus_Method_Return_Cb cb_return,
-                         E_DBus_Error_Cb cb_error, void *data);
+                         void *data);
 void e_dbus_release_name(DBusConnection *conn, const char *name,
                          E_DBus_Method_Return_Cb cb_return,
-                         E_DBus_Error_Cb cb_error, void *data);
+                         void *data);
 
 void e_dbus_get_name_owner(DBusConnection *conn, const char *name,
                            E_DBus_Method_Return_Cb cb_return,
-                           E_DBus_Error_Cb cb_error, void *data);
+                           void *data);
 void e_dbus_list_names(DBusConnection *conn,
                        E_DBus_Method_Return_Cb cb_return,
-                       E_DBus_Error_Cb cb_error, void *data);
+                       void *data);
 void e_dbus_list_activatable_names(DBusConnection *conn,
                                    E_DBus_Method_Return_Cb cb_return,
-                                   E_DBus_Error_Cb cb_error, void *data);
+                                   void *data);
 void e_dbus_name_has_owner(DBusConnection *conn, const char *name,
                            E_DBus_Method_Return_Cb cb_return,
-                           E_DBus_Error_Cb cb_error, void *data);
+                           void *data);
 void e_dbus_start_service_by_name(DBusConnection *conn, const char *name,
                                   E_DBus_Method_Return_Cb cb_return,
-                                  E_DBus_Error_Cb cb_error, void *data);
+                                  void *data);
 
 /* standard methods calls on objects */
 void e_dbus_peer_ping(DBusConnection *conn, const char *destination,
                       const char *path, E_DBus_Method_Return_Cb cb_return,
-                      E_DBus_Error_Cb cb_error, void *data);
+                      void *data);
 void e_dbus_peer_get_machine_id(DBusConnection *conn,
                                 const char *destination, const char *path,
                                 E_DBus_Method_Return_Cb cb_return,
-                                E_DBus_Error_Cb cb_error, void *data);
+                                void *data);
 void e_dbus_properties_get(DBusConnection *conn, const char *destination,
                            const char *path, const char *interface,
                            const char *property,
                            E_DBus_Method_Return_Cb cb_return,
-                           E_DBus_Error_Cb cb_error, void *data);
+                           void *data);
 void e_dbus_properties_set(DBusConnection *conn, const char *destination,
                            const char *path, const char *interface,
                            const char *property, int value_type,
                            void *value, E_DBus_Method_Return_Cb cb_return,
-                           E_DBus_Error_Cb cb_error, void *data);
+                           void *data);
 
 
 
===================================================================
RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/e_dbus_interfaces.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- e_dbus_interfaces.c 20 Mar 2007 04:45:06 -0000      1.1
+++ e_dbus_interfaces.c 20 Mar 2007 06:34:13 -0000      1.2
@@ -6,21 +6,21 @@
  */
 
 void
-e_dbus_peer_ping(DBusConnection*conn, const char *destination, const char 
*path, E_DBus_Method_Return_Cb cb_return, E_DBus_Error_Cb cb_error, void *data)
+e_dbus_peer_ping(DBusConnection*conn, const char *destination, const char 
*path, E_DBus_Method_Return_Cb cb_return, void *data)
 {
   DBusMessage *msg;
 
   msg = dbus_message_new_method_call(destination, path, 
"org.freedesktop.DBus.Peer", "Ping");
-  e_dbus_message_send(conn, msg, cb_return, cb_error, -1, data);
+  e_dbus_message_send(conn, msg, cb_return, -1, data);
 }
 
 void
-e_dbus_peer_get_machine_id(DBusConnection*conn, const char *destination, const 
char *path, E_DBus_Method_Return_Cb cb_return, E_DBus_Error_Cb cb_error, void 
*data)
+e_dbus_peer_get_machine_id(DBusConnection*conn, const char *destination, const 
char *path, E_DBus_Method_Return_Cb cb_return, void *data)
 {
   DBusMessage *msg;
 
   msg = dbus_message_new_method_call(destination, path, 
"org.freedesktop.DBus.Peer", "GetMachineId");
-  e_dbus_message_send(conn, msg, cb_return, cb_error, -1, data);
+  e_dbus_message_send(conn, msg, cb_return, -1, data);
 }
 
 
@@ -33,17 +33,16 @@
  * @param interface the interface name of the property
  * @param property the name of the property
  * @param cb_return a callback for a successful return
- * @param cb_error a callback for errors
  * @param data data to pass to the callbacks
  */
 void
-e_dbus_properties_get(DBusConnection*conn, const char *destination, const char 
*path, const char *interface, const char *property, E_DBus_Method_Return_Cb 
cb_return, E_DBus_Error_Cb cb_error, void *data)
+e_dbus_properties_get(DBusConnection*conn, const char *destination, const char 
*path, const char *interface, const char *property, E_DBus_Method_Return_Cb 
cb_return, void *data)
 {
   DBusMessage *msg;
 
   msg = dbus_message_new_method_call(destination, path, 
"org.freedesktop.DBus.Properties", "Get");
   dbus_message_append_args(msg, DBUS_TYPE_STRING, &interface, 
DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID);
-  e_dbus_message_send(conn, msg, cb_return, cb_error, -1, data);
+  e_dbus_message_send(conn, msg, cb_return, -1, data);
 }
 
 /**
@@ -57,18 +56,24 @@
  * @param value_type the type of the property's value
  * @param value a pointer to the value
  * @param cb_return a callback for a successful return
- * @param cb_error a callback for errors
  * @param data data to pass to the callbacks
  */
 void
-e_dbus_properties_set(DBusConnection*conn, const char *destination, const char 
*path, const char *interface, const char *property, int value_type, void 
*value, E_DBus_Method_Return_Cb cb_return, E_DBus_Error_Cb cb_error, void *data)
+e_dbus_properties_set(DBusConnection*conn, const char *destination, const char 
*path, const char *interface, const char *property, int value_type, void 
*value, E_DBus_Method_Return_Cb cb_return, void *data)
 {
   DBusMessage *msg;
   DBusMessageIter iter, sub;
+  DBusError err;
 
   if (!dbus_type_is_basic(value_type)) 
   {
-    cb_error(data, "org.enlightenment.DBus.InvalidType", "Only basic types may 
be set using e_dbus_properties_set()");
+    if (cb_return)
+    {
+      dbus_error_init(&err);
+      dbus_set_error(&err, "org.enlightenment.DBus.InvalidType", "Only basic 
types may be set using e_dbus_properties_set()");
+      cb_return(data, NULL, &err);
+
+    }
     return;
   }
 
@@ -80,5 +85,5 @@
   dbus_message_iter_append_basic(&sub, value_type, &value);
   dbus_message_iter_close_container(&iter, &sub);
 
-  e_dbus_message_send(conn, msg, cb_return, cb_error, -1, data);
+  e_dbus_message_send(conn, msg, cb_return, -1, data);
 }
===================================================================
RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/e_dbus_message.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- e_dbus_message.c    15 Mar 2007 08:59:19 -0000      1.1
+++ e_dbus_message.c    20 Mar 2007 06:34:13 -0000      1.2
@@ -7,8 +7,6 @@
   int                     serial;
 
   E_DBus_Method_Return_Cb cb_return;
-  E_DBus_Error_Cb         cb_error;
-
   void                   *data;
 };
 
@@ -25,24 +23,29 @@
     return;
   }
 
+  dbus_error_init(&err);
   msg = dbus_pending_call_steal_reply(pending);
   if (!msg)
   {
-    if (data->cb_error)
-      data->cb_error(data->data, "E.DBus.NoReply", "There was no reply to this 
method call.");
+    if (data->cb_return)
+    {
+      dbus_set_error(&err, "org.enlightenment.DBus.NoReply", "There was no 
reply to this method call.");
+      data->cb_return(data->data, NULL, &err);
+      dbus_error_free(&err);
+    }
     return;
   }
 
-  dbus_error_init(&err);
   if (dbus_set_error_from_message(&err, msg))
   {
-    if (data->cb_error)
-      data->cb_error(data->data, err.name, err.message);
+    if (data->cb_return)
+      data->cb_return(data->data, NULL, &err);
+    dbus_error_free(&err);
   }
   else
   {
     if (data->cb_return)
-      data->cb_return(data->data, msg);
+      data->cb_return(data->data, msg, &err);
   }
 
   dbus_message_unref(msg);
@@ -55,25 +58,23 @@
  * @param conn The DBus connection
  * @param msg  The message to send
  * @param cb_return A callback function for returns (only used if @a msg is a 
method-call)
- * @param cb_error  A callback function for errors
  * @param timeout   A timeout in milliseconds, after which a synthetic error 
will be generated
  * @return a DBusPendingCall that can be used to cancel the current call
  */
 DBusPendingCall *
-e_dbus_message_send(DBusConnection *conn, DBusMessage *msg, 
E_DBus_Method_Return_Cb cb_return, E_DBus_Error_Cb cb_error, int timeout, void 
*data)
+e_dbus_message_send(DBusConnection *conn, DBusMessage *msg, 
E_DBus_Method_Return_Cb cb_return, int timeout, void *data)
 {
   DBusPendingCall *pending;
 
   if (!dbus_connection_send_with_reply(conn, msg, &pending, timeout))
     return NULL;
 
-  if (cb_return || cb_error)
+  if (cb_return)
   {
     E_DBus_Pending_Call_Data *pdata;
 
     pdata = calloc(1, sizeof(E_DBus_Pending_Call_Data));
     pdata->cb_return = cb_return;
-    pdata->cb_error = cb_error;
     pdata->data = data;
 
     dbus_pending_call_set_notify(pending, cb_pending, pdata, free);
===================================================================
RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/e_dbus_methods.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- e_dbus_methods.c    20 Mar 2007 04:45:06 -0000      1.2
+++ e_dbus_methods.c    20 Mar 2007 06:34:13 -0000      1.3
@@ -1,7 +1,7 @@
 #include "E_DBus.h"
 
 void
-e_dbus_request_name(DBusConnection *conn, const char *name, unsigned int 
flags, E_DBus_Method_Return_Cb cb_return, E_DBus_Error_Cb cb_error, void *data)
+e_dbus_request_name(DBusConnection *conn, const char *name, unsigned int 
flags, E_DBus_Method_Return_Cb cb_return, void *data)
 {
   DBusMessage *msg;
   dbus_uint32_t u_flags;
@@ -10,66 +10,66 @@
 
   msg = dbus_message_new_method_call("org.freedesktop.DBus", 
"/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName");
   dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_UINT32, 
&u_flags, DBUS_TYPE_INVALID);
-  e_dbus_message_send(conn, msg, cb_return, cb_error, -1, data);
+  e_dbus_message_send(conn, msg, cb_return, -1, data);
 }
 
 void
-e_dbus_release_name(DBusConnection *conn, const char *name, 
E_DBus_Method_Return_Cb cb_return, E_DBus_Error_Cb cb_error, void *data)
+e_dbus_release_name(DBusConnection *conn, const char *name, 
E_DBus_Method_Return_Cb cb_return, void *data)
 {
   DBusMessage *msg;
 
   msg = dbus_message_new_method_call("org.freedesktop.DBus", 
"/org/freedesktop/DBus", "org.freedesktop.DBus", "ReleaseName");
   dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
-  e_dbus_message_send(conn, msg, cb_return, cb_error, -1, data);
+  e_dbus_message_send(conn, msg, cb_return, -1, data);
 }
 
 
 void
-e_dbus_get_name_owner(DBusConnection *conn, const char *name, 
E_DBus_Method_Return_Cb cb_return, E_DBus_Error_Cb cb_error, void *data)
+e_dbus_get_name_owner(DBusConnection *conn, const char *name, 
E_DBus_Method_Return_Cb cb_return, void *data)
 {
   DBusMessage *msg;
 
   msg = dbus_message_new_method_call("org.freedesktop.DBus", 
"/org/freedesktop/DBus", "org.freedesktop.DBus", "GetNameOwner");
   dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
-  e_dbus_message_send(conn, msg, cb_return, cb_error, -1, data);
+  e_dbus_message_send(conn, msg, cb_return, -1, data);
 }
 
 void
-e_dbus_list_names(DBusConnection *conn, E_DBus_Method_Return_Cb cb_return, 
E_DBus_Error_Cb cb_error, void *data)
+e_dbus_list_names(DBusConnection *conn, E_DBus_Method_Return_Cb cb_return, 
void *data)
 {
   DBusMessage *msg;
 
   msg = dbus_message_new_method_call("org.freedesktop.DBus", 
"/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames");
-  e_dbus_message_send(conn, msg, cb_return, cb_error, -1, data);
+  e_dbus_message_send(conn, msg, cb_return, -1, data);
 }
 
 
 void
-e_dbus_list_activatable_names(DBusConnection *conn, E_DBus_Method_Return_Cb 
cb_return, E_DBus_Error_Cb cb_error, void *data)
+e_dbus_list_activatable_names(DBusConnection *conn, E_DBus_Method_Return_Cb 
cb_return, void *data)
 {
   DBusMessage *msg;
 
   msg = dbus_message_new_method_call("org.freedesktop.DBus", 
"/org/freedesktop/DBus", "org.freedesktop.DBus", "ListActivatableNames");
-  e_dbus_message_send(conn, msg, cb_return, cb_error, -1, data);
+  e_dbus_message_send(conn, msg, cb_return, -1, data);
 }
 
 void
-e_dbus_name_has_owner(DBusConnection *conn, const char *name, 
E_DBus_Method_Return_Cb cb_return, E_DBus_Error_Cb cb_error, void *data)
+e_dbus_name_has_owner(DBusConnection *conn, const char *name, 
E_DBus_Method_Return_Cb cb_return, void *data)
 {
   DBusMessage *msg;
 
   msg = dbus_message_new_method_call("org.freedesktop.DBus", 
"/org/freedesktop/DBus", "org.freedesktop.DBus", "NameHasOwner");
   dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
-  e_dbus_message_send(conn, msg, cb_return, cb_error, -1, data);
+  e_dbus_message_send(conn, msg, cb_return, -1, data);
 }
 
 
 void
-e_dbus_start_service_by_name(DBusConnection *conn, const char *name, 
E_DBus_Method_Return_Cb cb_return, E_DBus_Error_Cb cb_error, void *data)
+e_dbus_start_service_by_name(DBusConnection *conn, const char *name, 
E_DBus_Method_Return_Cb cb_return, void *data)
 {
   DBusMessage *msg;
 
   msg = dbus_message_new_method_call("org.freedesktop.DBus", 
"/org/freedesktop/DBus", "org.freedesktop.DBus", "StartServiceByName");
   dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
-  e_dbus_message_send(conn, msg, cb_return, cb_error, -1, data);
+  e_dbus_message_send(conn, msg, cb_return, -1, data);
 }
===================================================================
RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/e_dbus_signal.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- e_dbus_signal.c     15 Mar 2007 09:18:54 -0000      1.2
+++ e_dbus_signal.c     20 Mar 2007 06:34:13 -0000      1.3
@@ -76,21 +76,28 @@
 }
 
 static void
-cb_name_owner(void *data, DBusMessage *msg)
+cb_name_owner(void *data, DBusMessage *msg, DBusError *err)
 {
-  DBusError err;
   const char *unique_name = NULL;
   E_DBus_Signal_Handler *sh;
 
   sh = data;
 
-  dbus_error_init(&err);
-  dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &unique_name, 
DBUS_TYPE_INVALID);
+  if (dbus_error_is_set(err))
+  {
+    if (ecore_list_goto(signal_handlers, sh))
+      ecore_list_remove(signal_handlers);
+    e_dbus_signal_handler_free(sh);
+    dbus_error_free(err);
+    return;
+  }
+
+  dbus_message_get_args(msg, err, DBUS_TYPE_STRING, &unique_name, 
DBUS_TYPE_INVALID);
 
-  if (dbus_error_is_set(&err))
+  if (dbus_error_is_set(err))
   {
     DEBUG(1, "Invalid signature in reply to name owner call\n");
-    dbus_error_free(&err);
+    dbus_error_free(err);
     return;
   }
 
@@ -103,18 +110,6 @@
 
 }
 
-static void
-cb_name_owner_error(void *data, const char *error_name, const char *error_msg)
-{
-  E_DBus_Signal_Handler *sh;
-  sh = ecore_list_goto(signal_handlers, data);
-  if (sh)
-  {
-    ecore_list_remove(signal_handlers);
-    e_dbus_signal_handler_free(sh);
-  }
-}
-
 /**
  * Add a signal handler
  *
@@ -169,7 +164,7 @@
 
   /* if we have a sender, and it is not a unique name, we need to know the 
unique name to match since signals will have the name owner as ther sender. */
   if (sender && sender[0] != ':')
-    e_dbus_get_name_owner(conn, sender, cb_name_owner, cb_name_owner_error, 
sh);
+    e_dbus_get_name_owner(conn, sender, cb_name_owner, sh);
 
   return sh;
 }



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to