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);
33 dbind_send_and_allow_reentry (DBusConnection * bus, DBusMessage * message, DBusError *error)
35 DBusPendingCall *pending;
36 SpiReentrantCallClosure closure;
37 const char *unique_name = dbus_bus_get_unique_name (bus);
40 strcmp (dbus_message_get_destination (message), unique_name) != 0)
41 return dbus_connection_send_with_reply_and_block (bus, message, dbind_timeout, error);
44 dbus_connection_setup_with_g_main(bus, NULL);
45 if (!dbus_connection_send_with_reply (bus, message, &pending, dbind_timeout))
49 dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
52 while (!closure.reply)
54 if (!dbus_connection_read_write_dispatch (bus, dbind_timeout))
62 dbind_method_call_reentrant_va (DBusConnection *cnx,
65 const char *interface,
68 const char *arg_types,
71 dbus_bool_t success = FALSE;
72 DBusMessage *msg = NULL, *reply = NULL;
74 DBusError *err, real_err;
76 va_list args_demarshal;
78 va_copy (args_demarshal, args);
82 dbus_error_init (&real_err);
86 msg = dbus_message_new_method_call (bus_name, path, interface, method);
91 dbus_message_iter_init_append (msg, &iter);
92 dbind_any_marshal_va (&iter, &p, args);
94 reply = dbind_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;
108 dbus_message_iter_init (reply, &iter);
110 dbind_any_demarshal_va (&iter, &p, args_demarshal);
116 dbus_message_unref (msg);
119 dbus_message_unref (reply);
121 if (err == &real_err)
122 dbus_error_free (err);
124 va_end (args_demarshal);
129 * dbind_method_call_reentrant:
131 * @cnx: A D-Bus Connection used to make the method call.
132 * @bus_name: The D-Bus bus name of the program where the method call should
134 * @path: The D-Bus object path that should handle the method.
135 * @interface: The D-Bus interface used to scope the method name.
136 * @method: Method to be invoked.
137 * @opt_error: D-Bus error.
138 * @arg_types: Variable length arguments interleaving D-Bus argument types
139 * and pointers to argument data.
141 * Makes a D-Bus method call using the supplied location data, method name and
142 * argument data.This function is re-entrant. It continuously reads from the D-Bus
143 * bus and dispatches messages until a reply has been recieved.
146 dbind_method_call_reentrant (DBusConnection *cnx,
147 const char *bus_name,
149 const char *interface,
151 DBusError *opt_error,
152 const char *arg_types,
155 dbus_bool_t success = FALSE;
158 va_start (args, arg_types);
159 success = dbind_method_call_reentrant_va (cnx,
172 /*---------------------------------------------------------------------------*/
175 dbind_emit_signal_va (DBusConnection *cnx,
177 const char *interface,
179 DBusError *opt_error,
180 const char *arg_types,
183 dbus_bool_t success = FALSE;
184 DBusMessage *msg = NULL;
185 DBusMessageIter iter;
186 DBusError *err, real_err;
192 dbus_error_init (&real_err);
196 msg = dbus_message_new_signal (path, interface, signal);
201 dbus_message_iter_init_append (msg, &iter);
202 dbind_any_marshal_va (&iter, &p, args);
204 if (!dbus_connection_send (cnx, msg, NULL))
211 dbus_message_unref (msg);
213 if (err == &real_err)
214 dbus_error_free (err);
222 * @cnx: A D-Bus Connection used to make the method call.
223 * @path: The D-Bus object path that this signal is emitted from.
224 * @interface: The D-Bus interface used to scope the method name.
225 * @signal: Name of signal to emit.
226 * @opt_error: D-Bus error.
227 * @arg_types: Variable length arguments interleaving D-Bus argument types
228 * and pointers to argument data.
230 * Emits a D-Bus signal using the supplied signal name and argument data.
233 dbind_emit_signal (DBusConnection *cnx,
235 const char *interface,
237 DBusError *opt_error,
238 const char *arg_types,
241 dbus_bool_t success = FALSE;
244 va_start (args, arg_types);
245 success = dbind_emit_signal_va (cnx, path, interface, signal, opt_error, arg_types, args);
251 dbind_set_timeout (int timeout)
253 dbind_timeout = timeout;
257 /*END------------------------------------------------------------------------*/