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_va (DBusConnection *cnx,
47 const char *interface,
50 const char *arg_types,
53 dbus_bool_t success = FALSE;
54 DBusMessage *msg = NULL, *reply = NULL;
56 DBusError *err, real_err;
62 dbus_error_init (&real_err);
66 msg = dbus_message_new_method_call (bus_name, path, interface, method);
71 dbus_message_iter_init_append (msg, &iter);
72 dbind_any_marshal_va (&iter, &p, args);
74 reply = send_and_allow_reentry (cnx, msg, err);
78 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
80 const char *name = dbus_message_get_error_name (reply);
81 dbus_set_error (err, name, g_strdup (""));
85 if (p[0] == '=' && p[1] == '>')
89 dbus_message_iter_init (reply, &iter);
90 dbind_any_demarshal_va (&iter, &p, args);
96 dbus_message_unref (msg);
99 dbus_message_unref (reply);
101 if (err == &real_err)
102 dbus_error_free (err);
108 * dbind_method_call_reentrant:
110 * @cnx: A D-Bus Connection used to make the method call.
111 * @bus_name: The D-Bus bus name of the program where the method call should
113 * @path: The D-Bus object path that should handle the method.
114 * @interface: The D-Bus interface used to scope the method name.
115 * @method: Method to be invoked.
116 * @opt_error: D-Bus error.
117 * @arg_types: Variable length arguments interleaving D-Bus argument types
118 * and pointers to argument data.
120 * Makes a D-Bus method call using the supplied location data, method name and
121 * argument data.This function is re-entrant. It continuously reads from the D-Bus
122 * bus and dispatches messages until a reply has been recieved.
125 dbind_method_call_reentrant (DBusConnection *cnx,
126 const char *bus_name,
128 const char *interface,
130 DBusError *opt_error,
131 const char *arg_types,
134 dbus_bool_t success = FALSE;
137 va_start (args, arg_types);
138 success = dbind_method_call_reentrant_va (cnx,
151 /*---------------------------------------------------------------------------*/
154 dbind_emit_signal_va (DBusConnection *cnx,
156 const char *interface,
158 DBusError *opt_error,
159 const char *arg_types,
162 dbus_bool_t success = FALSE;
163 DBusMessage *msg = NULL;
164 DBusMessageIter iter;
165 DBusError *err, real_err;
171 dbus_error_init (&real_err);
175 msg = dbus_message_new_signal (path, interface, signal);
179 dbus_message_iter_init (msg, &iter);
180 dbind_any_marshal_va (&iter, &p, args);
182 if (!dbus_connection_send (cnx, msg, NULL))
189 dbus_message_unref (msg);
191 if (err == &real_err)
192 dbus_error_free (err);
200 * @cnx: A D-Bus Connection used to make the method call.
201 * @path: The D-Bus object path that this signal is emitted from.
202 * @interface: The D-Bus interface used to scope the method name.
203 * @signal: Name of signal to emit.
204 * @opt_error: D-Bus error.
205 * @arg_types: Variable length arguments interleaving D-Bus argument types
206 * and pointers to argument data.
208 * Emits a D-Bus signal using the supplied signal name and argument data.
211 dbind_emit_signal (DBusConnection *cnx,
213 const char *interface,
215 DBusError *opt_error,
216 const char *arg_types,
219 dbus_bool_t success = FALSE;
222 va_start (args, arg_types);
223 success = dbind_emit_signal_va (cnx, path, interface, signal, opt_error, arg_types, args);
229 /*END------------------------------------------------------------------------*/