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;
38 if (strcmp (dbus_message_get_destination (message),
39 dbus_bus_get_unique_name (bus)) != 0)
40 return dbus_connection_send_with_reply_and_block (bus, message, dbind_timeout, error);
43 dbus_connection_setup_with_g_main(bus, NULL);
44 if (!dbus_connection_send_with_reply (bus, message, &pending, dbind_timeout))
46 dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
49 while (!closure.reply)
51 if (!dbus_connection_read_write_dispatch (bus, dbind_timeout))
59 dbind_method_call_reentrant_va (DBusConnection *cnx,
62 const char *interface,
65 const char *arg_types,
68 dbus_bool_t success = FALSE;
69 DBusMessage *msg = NULL, *reply = NULL;
71 DBusError *err, real_err;
73 va_list args_demarshal;
75 va_copy (args_demarshal, args);
79 dbus_error_init (&real_err);
83 msg = dbus_message_new_method_call (bus_name, path, interface, method);
88 dbus_message_iter_init_append (msg, &iter);
89 dbind_any_marshal_va (&iter, &p, args);
91 reply = dbind_send_and_allow_reentry (cnx, msg, err);
95 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
97 const char *name = dbus_message_get_error_name (reply);
98 dbus_set_error (err, name, g_strdup (""));
102 if (p[0] == '=' && p[1] == '>')
104 DBusMessageIter iter;
105 dbus_message_iter_init (reply, &iter);
107 dbind_any_demarshal_va (&iter, &p, args_demarshal);
113 dbus_message_unref (msg);
116 dbus_message_unref (reply);
118 if (err == &real_err)
119 dbus_error_free (err);
121 va_end (args_demarshal);
126 * dbind_method_call_reentrant:
128 * @cnx: A D-Bus Connection used to make the method call.
129 * @bus_name: The D-Bus bus name of the program where the method call should
131 * @path: The D-Bus object path that should handle the method.
132 * @interface: The D-Bus interface used to scope the method name.
133 * @method: Method to be invoked.
134 * @opt_error: D-Bus error.
135 * @arg_types: Variable length arguments interleaving D-Bus argument types
136 * and pointers to argument data.
138 * Makes a D-Bus method call using the supplied location data, method name and
139 * argument data.This function is re-entrant. It continuously reads from the D-Bus
140 * bus and dispatches messages until a reply has been recieved.
143 dbind_method_call_reentrant (DBusConnection *cnx,
144 const char *bus_name,
146 const char *interface,
148 DBusError *opt_error,
149 const char *arg_types,
152 dbus_bool_t success = FALSE;
155 va_start (args, arg_types);
156 success = dbind_method_call_reentrant_va (cnx,
169 /*---------------------------------------------------------------------------*/
172 dbind_emit_signal_va (DBusConnection *cnx,
174 const char *interface,
176 DBusError *opt_error,
177 const char *arg_types,
180 dbus_bool_t success = FALSE;
181 DBusMessage *msg = NULL;
182 DBusMessageIter iter;
183 DBusError *err, real_err;
189 dbus_error_init (&real_err);
193 msg = dbus_message_new_signal (path, interface, signal);
198 dbus_message_iter_init_append (msg, &iter);
199 dbind_any_marshal_va (&iter, &p, args);
201 if (!dbus_connection_send (cnx, msg, NULL))
208 dbus_message_unref (msg);
210 if (err == &real_err)
211 dbus_error_free (err);
219 * @cnx: A D-Bus Connection used to make the method call.
220 * @path: The D-Bus object path that this signal is emitted from.
221 * @interface: The D-Bus interface used to scope the method name.
222 * @signal: Name of signal to emit.
223 * @opt_error: D-Bus error.
224 * @arg_types: Variable length arguments interleaving D-Bus argument types
225 * and pointers to argument data.
227 * Emits a D-Bus signal using the supplied signal name and argument data.
230 dbind_emit_signal (DBusConnection *cnx,
232 const char *interface,
234 DBusError *opt_error,
235 const char *arg_types,
238 dbus_bool_t success = FALSE;
241 va_start (args, arg_types);
242 success = dbind_emit_signal_va (cnx, path, interface, signal, opt_error, arg_types, args);
248 dbind_set_timeout (int timeout)
250 dbind_timeout = timeout;
254 /*END------------------------------------------------------------------------*/