8 #include "dbind/dbind.h"
11 * FIXME: compare types - to ensure they match &
12 * do dynamic padding of structures etc.
15 /*---------------------------------------------------------------------------*/
18 set_reply (DBusPendingCall *pending, void *user_data)
20 void **replyptr = (void **)user_data;
22 *replyptr = dbus_pending_call_steal_reply (pending);
26 send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, DBusError *error)
28 DBusPendingCall *pending;
29 DBusMessage *reply = NULL;
31 if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
35 dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL);
38 if (!dbus_connection_read_write_dispatch (bus, -1)) return NULL;
44 * dbind_method_call_reentrant:
46 * @cnx: A D-Bus Connection used to make the method call.
47 * @bus_name: The D-Bus bus name of the program where the method call should
49 * @path: The D-Bus object path that should handle the method.
50 * @interface: The D-Bus interface used to scope the method name.
51 * @method: Method to be invoked.
52 * @opt_error: D-Bus error.
53 * @arg_types: Variable length arguments interleaving D-Bus argument types
54 * and pointers to argument data.
56 * Makes a D-Bus method call using the supplied location data, method name and
57 * argument data.This function is re-entrant. It continuously reads from the D-Bus
58 * bus and dispatches messages until a reply has been recieved.
61 dbind_method_call_reentrant (DBusConnection *cnx,
64 const char *interface,
67 const char *arg_types,
70 dbus_bool_t success = FALSE;
71 DBusMessage *msg = NULL, *reply = NULL;
73 DBusError *err, real_err;
77 va_start (args, arg_types);
82 dbus_error_init (&real_err);
86 msg = dbus_message_new_method_call (bus_name, path, interface, method);
91 dbus_message_iter_init (msg, &iter);
92 dbind_any_marshal_va (&iter, &p, args);
94 reply = send_and_allow_reentry (cnx, msg, err);
98 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
100 const char *name = dbus_message_get_error_name (reply);
101 dbus_set_error (err, name, g_strdup (""));
105 if (p[0] == '=' && p[1] == '>')
107 DBusMessageIter iter;
109 dbus_message_iter_init (reply, &iter);
110 dbind_any_demarshal_va (&iter, &p, args);
118 dbus_message_unref (msg);
121 dbus_message_unref (reply);
123 if (err == &real_err)
124 dbus_error_free (err);
129 /*---------------------------------------------------------------------------*/
134 * @cnx: A D-Bus Connection used to make the method call.
135 * @path: The D-Bus object path that this signal is emitted from.
136 * @interface: The D-Bus interface used to scope the method name.
137 * @signal: Name of signal to emit.
138 * @opt_error: D-Bus error.
139 * @arg_types: Variable length arguments interleaving D-Bus argument types
140 * and pointers to argument data.
142 * Emits a D-Bus signal using the supplied signal name and argument data.
145 dbind_emit_signal (DBusConnection *cnx,
147 const char *interface,
149 DBusError *opt_error,
150 const char *arg_types,
153 dbus_bool_t success = FALSE;
154 DBusMessage *msg = NULL;
155 DBusMessageIter iter;
156 DBusError *err, real_err;
160 va_start (args, arg_types);
165 dbus_error_init (&real_err);
169 msg = dbus_message_new_signal (path, interface, signal);
173 dbus_message_iter_init (msg, &iter);
174 dbind_any_marshal_va (&iter, &p, args);
176 if (!dbus_connection_send (cnx, msg, NULL))
184 dbus_message_unref (msg);
186 if (err == &real_err)
187 dbus_error_free (err);
192 /*END------------------------------------------------------------------------*/