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;
87 dbus_error_init (&real_err);
91 msg = dbus_message_new_method_call (bus_name, path, interface, method);
96 dbus_message_iter_init_append (msg, &iter);
97 dbind_any_marshal_va (&iter, &p, &args);
99 reply = dbind_send_and_allow_reentry (cnx, msg, err);
103 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
105 const char *name = dbus_message_get_error_name (reply);
106 dbus_set_error (err, name, g_strdup (""));
110 if (p[0] == '=' && p[1] == '>')
112 DBusMessageIter iter;
114 dbus_message_iter_init (reply, &iter);
115 dbind_any_demarshal_va (&iter, &p, &args);
121 dbus_message_unref (msg);
124 dbus_message_unref (reply);
126 if (err == &real_err)
127 dbus_error_free (err);
133 * dbind_method_call_reentrant:
135 * @cnx: A D-Bus Connection used to make the method call.
136 * @bus_name: The D-Bus bus name of the program where the method call should
138 * @path: The D-Bus object path that should handle the method.
139 * @interface: The D-Bus interface used to scope the method name.
140 * @method: Method to be invoked.
141 * @opt_error: D-Bus error.
142 * @arg_types: Variable length arguments interleaving D-Bus argument types
143 * and pointers to argument data.
145 * Makes a D-Bus method call using the supplied location data, method name and
146 * argument data.This function is re-entrant. It continuously reads from the D-Bus
147 * bus and dispatches messages until a reply has been recieved.
150 dbind_method_call_reentrant (DBusConnection *cnx,
151 const char *bus_name,
153 const char *interface,
155 DBusError *opt_error,
156 const char *arg_types,
159 dbus_bool_t success = FALSE;
162 va_start (args, arg_types);
163 success = dbind_method_call_reentrant_va (cnx,
176 /*---------------------------------------------------------------------------*/
179 dbind_emit_signal_va (DBusConnection *cnx,
181 const char *interface,
183 DBusError *opt_error,
184 const char *arg_types,
187 dbus_bool_t success = FALSE;
188 DBusMessage *msg = NULL;
189 DBusMessageIter iter;
190 DBusError *err, real_err;
196 dbus_error_init (&real_err);
200 msg = dbus_message_new_signal (path, interface, signal);
205 dbus_message_iter_init_append (msg, &iter);
206 dbind_any_marshal_va (&iter, &p, &args);
208 if (!dbus_connection_send (cnx, msg, NULL))
215 dbus_message_unref (msg);
217 if (err == &real_err)
218 dbus_error_free (err);
226 * @cnx: A D-Bus Connection used to make the method call.
227 * @path: The D-Bus object path that this signal is emitted from.
228 * @interface: The D-Bus interface used to scope the method name.
229 * @signal: Name of signal to emit.
230 * @opt_error: D-Bus error.
231 * @arg_types: Variable length arguments interleaving D-Bus argument types
232 * and pointers to argument data.
234 * Emits a D-Bus signal using the supplied signal name and argument data.
237 dbind_emit_signal (DBusConnection *cnx,
239 const char *interface,
241 DBusError *opt_error,
242 const char *arg_types,
245 dbus_bool_t success = FALSE;
248 va_start (args, arg_types);
249 success = dbind_emit_signal_va (cnx, path, interface, signal, opt_error, arg_types, args);
255 dbind_set_timeout (int timeout)
257 dbind_timeout = timeout;
261 /*END------------------------------------------------------------------------*/