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
23 } SpiReentrantCallClosure;
26 set_reply (DBusPendingCall * pending, void *user_data)
28 SpiReentrantCallClosure* closure = (SpiReentrantCallClosure *) user_data;
30 closure->reply = dbus_pending_call_steal_reply (pending);
31 g_main_loop_quit (closure->loop);
35 dbind_send_and_allow_reentry (DBusConnection * bus, DBusMessage * message, DBusError *error)
37 DBusPendingCall *pending;
38 SpiReentrantCallClosure closure;
40 if (strcmp (dbus_message_get_destination (message),
41 dbus_bus_get_unique_name (bus)) != 0)
42 return dbus_connection_send_with_reply_and_block (bus, message, dbind_timeout, error);
44 if (!dbus_connection_send_with_reply (bus, message, &pending, dbind_timeout))
46 dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
47 closure.loop = g_main_loop_new (NULL, FALSE);
48 dbus_connection_setup_with_g_main(bus, NULL);
52 g_main_loop_run (closure.loop);
57 while (!closure.reply)
59 if (!dbus_connection_read_write_dispatch (bus, dbind_timeout))
64 g_main_loop_unref (closure.loop);
69 dbind_method_call_reentrant_va (DBusConnection *cnx,
72 const char *interface,
75 const char *arg_types,
78 dbus_bool_t success = FALSE;
79 DBusMessage *msg = NULL, *reply = NULL;
81 DBusError *err, real_err;
83 va_list args_demarshal;
85 va_copy (args_demarshal, args);
89 dbus_error_init (&real_err);
93 msg = dbus_message_new_method_call (bus_name, path, interface, method);
98 dbus_message_iter_init_append (msg, &iter);
99 dbind_any_marshal_va (&iter, &p, args);
101 reply = dbind_send_and_allow_reentry (cnx, msg, err);
105 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
107 const char *name = dbus_message_get_error_name (reply);
108 dbus_set_error (err, name, g_strdup (""));
112 if (p[0] == '=' && p[1] == '>')
114 DBusMessageIter iter;
115 dbus_message_iter_init (reply, &iter);
117 dbind_any_demarshal_va (&iter, &p, args_demarshal);
123 dbus_message_unref (msg);
126 dbus_message_unref (reply);
128 if (err == &real_err)
129 dbus_error_free (err);
131 va_end (args_demarshal);
136 * dbind_method_call_reentrant:
138 * @cnx: A D-Bus Connection used to make the method call.
139 * @bus_name: The D-Bus bus name of the program where the method call should
141 * @path: The D-Bus object path that should handle the method.
142 * @interface: The D-Bus interface used to scope the method name.
143 * @method: Method to be invoked.
144 * @opt_error: D-Bus error.
145 * @arg_types: Variable length arguments interleaving D-Bus argument types
146 * and pointers to argument data.
148 * Makes a D-Bus method call using the supplied location data, method name and
149 * argument data.This function is re-entrant. It continuously reads from the D-Bus
150 * bus and dispatches messages until a reply has been recieved.
153 dbind_method_call_reentrant (DBusConnection *cnx,
154 const char *bus_name,
156 const char *interface,
158 DBusError *opt_error,
159 const char *arg_types,
162 dbus_bool_t success = FALSE;
165 va_start (args, arg_types);
166 success = dbind_method_call_reentrant_va (cnx,
179 /*---------------------------------------------------------------------------*/
182 dbind_emit_signal_va (DBusConnection *cnx,
184 const char *interface,
186 DBusError *opt_error,
187 const char *arg_types,
190 dbus_bool_t success = FALSE;
191 DBusMessage *msg = NULL;
192 DBusMessageIter iter;
193 DBusError *err, real_err;
199 dbus_error_init (&real_err);
203 msg = dbus_message_new_signal (path, interface, signal);
208 dbus_message_iter_init_append (msg, &iter);
209 dbind_any_marshal_va (&iter, &p, args);
211 if (!dbus_connection_send (cnx, msg, NULL))
218 dbus_message_unref (msg);
220 if (err == &real_err)
221 dbus_error_free (err);
229 * @cnx: A D-Bus Connection used to make the method call.
230 * @path: The D-Bus object path that this signal is emitted from.
231 * @interface: The D-Bus interface used to scope the method name.
232 * @signal: Name of signal to emit.
233 * @opt_error: D-Bus error.
234 * @arg_types: Variable length arguments interleaving D-Bus argument types
235 * and pointers to argument data.
237 * Emits a D-Bus signal using the supplied signal name and argument data.
240 dbind_emit_signal (DBusConnection *cnx,
242 const char *interface,
244 DBusError *opt_error,
245 const char *arg_types,
248 dbus_bool_t success = FALSE;
251 va_start (args, arg_types);
252 success = dbind_emit_signal_va (cnx, path, interface, signal, opt_error, arg_types, args);
258 dbind_set_timeout (int timeout)
260 dbind_timeout = timeout;
264 /*END------------------------------------------------------------------------*/