8 #include "dbind/dbind.h"
11 * FIXME: compare types - to ensure they match &
12 * do dynamic padding of structures etc.
15 /*---------------------------------------------------------------------------*/
18 set_reply (DBusPendingCall *pending, void *user_data)
20 void **replyptr = (void **)user_data;
22 *replyptr = dbus_pending_call_steal_reply (pending);
26 send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, DBusError *error)
28 DBusPendingCall *pending;
29 DBusMessage *reply = NULL;
31 if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
35 dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL);
38 if (!dbus_connection_read_write_dispatch (bus, -1)) return NULL;
44 * dbind_method_call_reentrant:
46 * @cnx: A D-Bus Connection used to make the method call.
47 * @bus_name: The D-Bus bus name of the program where the method call should
49 * @path: The D-Bus object path that should handle the method.
50 * @interface: The D-Bus interface used to scope the method name.
51 * @method: Method to be invoked.
52 * @opt_error: D-Bus error.
53 * @arg_types: Variable length arguments interleaving D-Bus argument types
54 * and pointers to argument data.
56 * Makes a D-Bus method call using the supplied location data, method name and
57 * argument data.This function is re-entrant. It continuously reads from the D-Bus
58 * bus and dispatches messages until a reply has been recieved.
61 dbind_method_call_reentrant (DBusConnection *cnx,
64 const char *interface,
67 const char *arg_types,
70 dbus_bool_t success = FALSE;
71 DBusMessage *msg = NULL, *reply = NULL;
73 DBusError *err, real_err;
77 va_start (args, arg_types);
82 dbus_error_init (&real_err);
86 msg = dbus_message_new_method_call (bus_name, path, interface, method);
90 dbus_message_iter_init (msg, &iter);
91 dbind_any_marshal_va (&iter, &p, args);
93 reply = send_and_allow_reentry (cnx, msg, err);
97 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
99 const char *name = dbus_message_get_error_name (reply);
100 dbus_set_error (err, name, g_strdup (""));
104 if (p[0] == '=' && p[1] == '>')
106 DBusMessageIter iter;
108 dbus_message_iter_init (reply, &iter);
109 dbind_any_demarshal_va (&iter, &p, args);
117 dbus_message_unref (msg);
120 dbus_message_unref (reply);
122 if (err == &real_err)
123 dbus_error_free (err);
128 /*---------------------------------------------------------------------------*/
133 * @cnx: A D-Bus Connection used to make the method call.
134 * @path: The D-Bus object path that this signal is emitted from.
135 * @interface: The D-Bus interface used to scope the method name.
136 * @signal: Name of signal to emit.
137 * @opt_error: D-Bus error.
138 * @arg_types: Variable length arguments interleaving D-Bus argument types
139 * and pointers to argument data.
141 * Emits a D-Bus signal using the supplied signal name and argument data.
144 dbind_emit_signal (DBusConnection *cnx,
146 const char *interface,
148 DBusError *opt_error,
149 const char *arg_types,
152 dbus_bool_t success = FALSE;
153 DBusMessage *msg = NULL;
154 DBusMessageIter iter;
155 DBusError *err, real_err;
159 va_start (args, arg_types);
164 dbus_error_init (&real_err);
168 msg = dbus_message_new_signal (path, interface, signal);
172 dbus_message_iter_init (msg, &iter);
173 dbind_any_marshal_va (&iter, &p, args);
175 if (!dbus_connection_send (cnx, msg, NULL))
183 dbus_message_unref (msg);
185 if (err == &real_err)
186 dbus_error_free (err);
191 /*END------------------------------------------------------------------------*/