8 #include "dbind/dbind.h"
10 static int dbind_timeout = -1;
13 * FIXME: compare types - to ensure they match &
14 * do dynamic padding of structures etc.
17 /*---------------------------------------------------------------------------*/
19 typedef struct _SpiReentrantCallClosure
22 } SpiReentrantCallClosure;
25 set_reply (DBusPendingCall * pending, void *user_data)
27 SpiReentrantCallClosure* closure = (SpiReentrantCallClosure *) user_data;
29 closure->reply = dbus_pending_call_steal_reply (pending);
30 dbus_pending_call_unref (pending);
34 dbind_send_and_allow_reentry (DBusConnection * bus, DBusMessage * message, DBusError *error)
36 DBusPendingCall *pending;
37 SpiReentrantCallClosure closure;
38 const char *unique_name = dbus_bus_get_unique_name (bus);
39 const char *destination = dbus_message_get_destination (message);
41 if (unique_name && destination &&
42 strcmp (destination, unique_name) != 0)
43 return dbus_connection_send_with_reply_and_block (bus, message, dbind_timeout, error);
46 dbus_connection_setup_with_g_main(bus, NULL);
47 if (!dbus_connection_send_with_reply (bus, message, &pending, dbind_timeout))
51 dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
54 while (!closure.reply)
56 if (!dbus_connection_read_write_dispatch (bus, dbind_timeout))
64 dbind_method_call_reentrant_va (DBusConnection *cnx,
67 const char *interface,
70 const char *arg_types,
73 dbus_bool_t success = FALSE;
74 DBusMessage *msg = NULL, *reply = NULL;
76 DBusError *err, real_err;
78 va_list args_demarshal;
80 va_copy (args_demarshal, args);
84 dbus_error_init (&real_err);
88 msg = dbus_message_new_method_call (bus_name, path, interface, method);
93 dbus_message_iter_init_append (msg, &iter);
94 dbind_any_marshal_va (&iter, &p, args);
96 reply = dbind_send_and_allow_reentry (cnx, msg, err);
100 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
102 const char *name = dbus_message_get_error_name (reply);
106 if (p[0] == '=' && p[1] == '>')
108 DBusMessageIter iter;
109 dbus_message_iter_init (reply, &iter);
111 dbind_any_demarshal_va (&iter, &p, args_demarshal);
117 dbus_message_unref (msg);
120 dbus_message_unref (reply);
122 if (err == &real_err)
123 dbus_error_free (err);
125 va_end (args_demarshal);
130 * dbind_method_call_reentrant:
132 * @cnx: A D-Bus Connection used to make the method call.
133 * @bus_name: The D-Bus bus name of the program where the method call should
135 * @path: The D-Bus object path that should handle the method.
136 * @interface: The D-Bus interface used to scope the method name.
137 * @method: Method to be invoked.
138 * @opt_error: D-Bus error.
139 * @arg_types: Variable length arguments interleaving D-Bus argument types
140 * and pointers to argument data.
142 * Makes a D-Bus method call using the supplied location data, method name and
143 * argument data.This function is re-entrant. It continuously reads from the D-Bus
144 * bus and dispatches messages until a reply has been recieved.
147 dbind_method_call_reentrant (DBusConnection *cnx,
148 const char *bus_name,
150 const char *interface,
152 DBusError *opt_error,
153 const char *arg_types,
156 dbus_bool_t success = FALSE;
159 va_start (args, arg_types);
160 success = dbind_method_call_reentrant_va (cnx,
173 /*---------------------------------------------------------------------------*/
176 dbind_emit_signal_va (DBusConnection *cnx,
178 const char *interface,
180 DBusError *opt_error,
181 const char *arg_types,
184 dbus_bool_t success = FALSE;
185 DBusMessage *msg = NULL;
186 DBusMessageIter iter;
187 DBusError *err, real_err;
193 dbus_error_init (&real_err);
197 msg = dbus_message_new_signal (path, interface, signal);
202 dbus_message_iter_init_append (msg, &iter);
203 dbind_any_marshal_va (&iter, &p, args);
205 if (!dbus_connection_send (cnx, msg, NULL))
212 dbus_message_unref (msg);
214 if (err == &real_err)
215 dbus_error_free (err);
223 * @cnx: A D-Bus Connection used to make the method call.
224 * @path: The D-Bus object path that this signal is emitted from.
225 * @interface: The D-Bus interface used to scope the method name.
226 * @signal: Name of signal to emit.
227 * @opt_error: D-Bus error.
228 * @arg_types: Variable length arguments interleaving D-Bus argument types
229 * and pointers to argument data.
231 * Emits a D-Bus signal using the supplied signal name and argument data.
234 dbind_emit_signal (DBusConnection *cnx,
236 const char *interface,
238 DBusError *opt_error,
239 const char *arg_types,
242 dbus_bool_t success = FALSE;
245 va_start (args, arg_types);
246 success = dbind_emit_signal_va (cnx, path, interface, signal, opt_error, arg_types, args);
252 dbind_set_timeout (int timeout)
254 dbind_timeout = timeout;
258 /*END------------------------------------------------------------------------*/