/*
* TODO for GDBus:
*
- * - Validate all data (e.g. UTF-8) and check all the required D-Bus headers
- * are present and forbidden ones aren't
- * - When writing: g_dbus_message_to_blob()
- * - When reading: g_dbus_message_new_from_blob()
- *
* - would be nice to expose GDBusAuthMechanism and an extension point
*
* - Need to rewrite GDBusAuth and rework GDBusAuthMechanism. In particular
* kind of pitfalls it avoids
* - Export objects before claiming names
* - Talk about auto-starting services (cf. GBusNameWatcherFlags)
+ *
+ * - use abstract sockets in test code
+ * - right now it doesn't work, dbus-daemon(1) fails with
+ *
+ * /gdbus/connection/filter: Failed to start message bus: Failed to bind
+ * socket "/tmp/g-dbus-tests-pid-28531": Address already in use
+ * ** WARNING **: Error reading address from dbus daemon, 0 bytes read
+ *
+ * or similar.
*/
#include "config.h"
/* ---------------------------------------------------------------------------------------------------- */
+typedef struct
+{
+ GDestroyNotify callback;
+ gpointer user_data;
+ GMainContext *context;
+} CallDestroyNotifyData;
+
+static gboolean
+call_destroy_notify_data_in_idle (gpointer user_data)
+{
+ CallDestroyNotifyData *data = user_data;
+ data->callback (data->user_data);
+ return FALSE;
+}
+
+static void
+call_destroy_notify_data_free (CallDestroyNotifyData *data)
+{
+ if (data->context != NULL)
+ g_main_context_unref (data->context);
+ g_free (data);
+}
+
+/*
+ * call_destroy_notify: <internal>
+ * @context: A #GMainContext or %NULL.
+ * @callback: A #GDestroyNotify or %NULL.
+ * @user_data: Data to pass to @callback.
+ *
+ * Schedules @callback to run in @context.
+ */
+static void
+call_destroy_notify (GMainContext *context,
+ GDestroyNotify callback,
+ gpointer user_data)
+{
+ if (callback == NULL)
+ goto out;
+
+ if (context == g_main_context_get_thread_default ())
+ {
+ callback (user_data);
+ }
+ else
+ {
+ GSource *idle_source;
+ CallDestroyNotifyData *data;
+
+ data = g_new0 (CallDestroyNotifyData, 1);
+ data->callback = callback;
+ data->user_data = user_data;
+ data->context = context;
+ if (data->context != NULL)
+ g_main_context_ref (data->context);
+
+ idle_source = g_idle_source_new ();
+ g_source_set_priority (idle_source, G_PRIORITY_DEFAULT);
+ g_source_set_callback (idle_source,
+ call_destroy_notify_data_in_idle,
+ data,
+ (GDestroyNotify) call_destroy_notify_data_free);
+ g_source_attach (idle_source, data->context);
+ g_source_unref (idle_source);
+ }
+
+ out:
+ ;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
static gboolean
_g_strv_has_string (const gchar* const *haystack,
const gchar *needle)
GDBusCapabilityFlags capabilities;
GDBusAuthObserver *authentication_observer;
- GCredentials *crendentials;
+ GCredentials *credentials;
+
+ /* set to TRUE when finalizing */
+ gboolean finalizing;
};
typedef struct ExportedObject ExportedObject;
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init)
);
+static GHashTable *alive_connections = NULL;
+
static void
g_dbus_connection_dispose (GObject *object)
{
GDBusConnection *connection = G_DBUS_CONNECTION (object);
G_LOCK (message_bus_lock);
- //g_debug ("disposing %p", connection);
if (connection == the_session_bus)
{
the_session_bus = NULL;
{
the_system_bus = NULL;
}
+ CONNECTION_LOCK (connection);
if (connection->worker != NULL)
{
_g_dbus_worker_stop (connection->worker);
connection->worker = NULL;
+ if (alive_connections != NULL)
+ g_warn_if_fail (g_hash_table_remove (alive_connections, connection));
}
+ else
+ {
+ if (alive_connections != NULL)
+ g_warn_if_fail (g_hash_table_lookup (alive_connections, connection) == NULL);
+ }
+ CONNECTION_UNLOCK (connection);
G_UNLOCK (message_bus_lock);
if (G_OBJECT_CLASS (g_dbus_connection_parent_class)->dispose != NULL)
{
GDBusConnection *connection = G_DBUS_CONNECTION (object);
+ connection->finalizing = TRUE;
+
+ purge_all_signal_subscriptions (connection);
+
+ purge_all_filters (connection);
+ g_ptr_array_unref (connection->filters);
+
if (connection->authentication_observer != NULL)
g_object_unref (connection->authentication_observer);
if (connection->auth != NULL)
g_object_unref (connection->auth);
- //g_debug ("finalizing %p", connection);
+ if (connection->credentials)
+ g_object_unref (connection->credentials);
+
if (connection->stream != NULL)
{
/* We don't really care if closing the stream succeeds or not */
g_hash_table_unref (connection->map_method_serial_to_send_message_data);
- purge_all_signal_subscriptions (connection);
g_hash_table_unref (connection->map_rule_to_signal_data);
g_hash_table_unref (connection->map_id_to_signal_data);
g_hash_table_unref (connection->map_sender_unique_name_to_signal_data_array);
g_hash_table_unref (connection->map_id_to_es);
g_hash_table_unref (connection->map_object_path_to_es);
- purge_all_filters (connection);
- g_ptr_array_unref (connection->filters);
-
if (connection->main_context_at_construction != NULL)
g_main_context_unref (connection->main_context_at_construction);
{
if (remote_peer_vanished && connection->exit_on_close)
{
- g_print ("%s: Remote peer vanished. Exiting.\n", G_STRFUNC);
+ if (error != NULL)
+ {
+ g_print ("%s: Remote peer vanished with error: %s (%s, %d). Exiting.\n",
+ G_STRFUNC,
+ error->message,
+ g_quark_to_string (error->domain), error->code);
+ }
+ else
+ {
+ g_print ("%s: Remote peer vanished. Exiting.\n", G_STRFUNC);
+ }
raise (SIGTERM);
}
}
connection->map_sender_unique_name_to_signal_data_array = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
- NULL);
+ (GDestroyNotify) g_ptr_array_unref);
connection->map_object_path_to_eo = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
- simple = g_simple_async_result_new (NULL,
+ simple = g_simple_async_result_new (G_OBJECT (connection),
callback,
user_data,
g_dbus_connection_flush);
gboolean ret;
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
ret = FALSE;
/* ---------------------------------------------------------------------------------------------------- */
+static void
+close_in_thread_func (GSimpleAsyncResult *res,
+ GObject *object,
+ GCancellable *cancellable)
+{
+ GError *error;
+
+ error = NULL;
+ if (!g_dbus_connection_close_sync (G_DBUS_CONNECTION (object),
+ cancellable,
+ &error))
+ {
+ g_simple_async_result_set_from_error (res, error);
+ g_error_free (error);
+ }
+}
+
/**
* g_dbus_connection_close:
* @connection: A #GDBusConnection.
+ * @cancellable: A #GCancellable or %NULL.
+ * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL if you don't
+ * care about the result.
+ * @user_data: The data to pass to @callback.
*
* Closes @connection. Note that this never causes the process to
* exit (this might only happen if the other end of a shared message
* bus connection disconnects, see #GDBusConnection:exit-on-close).
*
- * Once the stream is closed, all operations will return
+ * Once the connection is closed, operations such as sending a message
+ * will return with the error %G_IO_ERROR_CLOSED. Closing a connection
+ * will not automatically flush the connection so queued messages may
+ * be lost. Use g_dbus_connection_flush() if you need such guarantees.
+ *
+ * If @connection is already closed, this method fails with
* %G_IO_ERROR_CLOSED.
*
- * Note that closing a connection will not automatically flush the
- * connection so queued messages may be lost. Use
- * g_dbus_connection_flush() if you need such guarantees.
+ * When @connection has been closed, the #GDBusConnection::closed
+ * signal is emitted in the <link
+ * linkend="g-main-context-push-thread-default">thread-default main
+ * loop</link> of the thread that @connection was constructed in.
*
- * If @connection is already closed, this method does nothing.
+ * This is an asynchronous method. When the operation is finished,
+ * @callback will be invoked in the <link
+ * linkend="g-main-context-push-thread-default">thread-default main
+ * loop</link> of the thread you are calling this method from. You can
+ * then call g_dbus_connection_close_finish() to get the result of the
+ * operation. See g_dbus_connection_close_sync() for the synchronous
+ * version.
*
* Since: 2.26
*/
void
-g_dbus_connection_close (GDBusConnection *connection)
+g_dbus_connection_close (GDBusConnection *connection,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
+ GSimpleAsyncResult *simple;
+
g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
+ simple = g_simple_async_result_new (G_OBJECT (connection),
+ callback,
+ user_data,
+ g_dbus_connection_close);
+ g_simple_async_result_run_in_thread (simple,
+ close_in_thread_func,
+ G_PRIORITY_DEFAULT,
+ cancellable);
+ g_object_unref (simple);
+}
+
+/**
+ * g_dbus_connection_close_finish:
+ * @connection: A #GDBusConnection.
+ * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to g_dbus_connection_close().
+ * @error: Return location for error or %NULL.
+ *
+ * Finishes an operation started with g_dbus_connection_close().
+ *
+ * Returns: %TRUE if the operation succeeded, %FALSE if @error is set.
+ *
+ * Since: 2.26
+ */
+gboolean
+g_dbus_connection_close_finish (GDBusConnection *connection,
+ GAsyncResult *res,
+ GError **error)
+{
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
+ gboolean ret;
+
+ ret = FALSE;
+
+ g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_dbus_connection_close);
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ goto out;
+
+ ret = TRUE;
+
+ out:
+ return ret;
+}
+
+/**
+ * g_dbus_connection_close_sync:
+ * @connection: A #GDBusConnection.
+ * @cancellable: A #GCancellable or %NULL.
+ * @error: Return location for error or %NULL.
+ *
+ * Synchronously closees @connection. The calling thread is blocked
+ * until this is done. See g_dbus_connection_close() for the
+ * asynchronous version of this method and more details about what it
+ * does.
+ *
+ * Returns: %TRUE if the operation succeeded, %FALSE if @error is set.
+ *
+ * Since: 2.26
+ */
+gboolean
+g_dbus_connection_close_sync (GDBusConnection *connection,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret;
+
+ g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ ret = FALSE;
+
CONNECTION_LOCK (connection);
if (!connection->closed)
{
- GError *error = NULL;
-
- /* TODO: do this async */
- //g_debug ("closing connection %p's stream %p", connection, connection->stream);
- if (!g_io_stream_close (connection->stream, NULL, &error))
- {
- g_warning ("Error closing stream: %s", error->message);
- g_error_free (error);
- }
-
- set_closed_unlocked (connection, FALSE, NULL);
+ ret = g_io_stream_close (connection->stream,
+ cancellable,
+ error);
+ if (ret)
+ set_closed_unlocked (connection, FALSE, NULL);
+ }
+ else
+ {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_CLOSED,
+ _("The connection is closed"));
}
CONNECTION_UNLOCK (connection);
+
+ return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
static gboolean
g_dbus_connection_send_message_unlocked (GDBusConnection *connection,
GDBusMessage *message,
+ GDBusSendMessageFlags flags,
volatile guint32 *out_serial,
GError **error)
{
if (blob == NULL)
goto out;
- serial_to_use = g_dbus_message_get_serial (message);
- if (serial_to_use == 0)
- {
- serial_to_use = ++connection->last_serial; /* TODO: handle overflow */
- }
+ if (flags & G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL)
+ serial_to_use = g_dbus_message_get_serial (message);
+ else
+ serial_to_use = ++connection->last_serial; /* TODO: handle overflow */
switch (blob[0])
{
g_dbus_message_set_serial (message, serial_to_use);
+ g_dbus_message_lock (message);
_g_dbus_worker_send_message (connection->worker,
message,
(gchar*) blob,
* g_dbus_connection_send_message:
* @connection: A #GDBusConnection.
* @message: A #GDBusMessage
+ * @flags: Flags affecting how the message is sent.
* @out_serial: Return location for serial number assigned to @message when sending it or %NULL.
* @error: Return location for error or %NULL.
*
* Asynchronously sends @message to the peer represented by @connection.
*
- * If g_dbus_message_get_serial() returns non-zero for @message, then
- * that value is used for the message serial number. Otherwise a
- * serial number will be assigned by @connection and set on @message
- * via g_dbus_message_set_serial(). If @out_serial is not %NULL, then
- * the serial number used will be written to this location prior to
+ * Unless @flags contain the
+ * %G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag, the serial number
+ * will be assigned by @connection and set on @message via
+ * g_dbus_message_set_serial(). If @out_serial is not %NULL, then the
+ * serial number used will be written to this location prior to
* submitting the message to the underlying transport.
*
* If @connection is closed then the operation will fail with
* linkend="gdbus-unix-fd-client"/> for an example of how to use this
* low-level API to send and receive UNIX file descriptors.
*
+ * Note that @message must be unlocked, unless @flags contain the
+ * %G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag.
+ *
* Returns: %TRUE if the message was well-formed and queued for
* transmission, %FALSE if @error is set.
*
gboolean
g_dbus_connection_send_message (GDBusConnection *connection,
GDBusMessage *message,
+ GDBusSendMessageFlags flags,
volatile guint32 *out_serial,
GError **error)
{
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), FALSE);
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), FALSE);
+ g_return_val_if_fail ((flags & G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL) || !g_dbus_message_get_locked (message), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
CONNECTION_LOCK (connection);
- ret = g_dbus_connection_send_message_unlocked (connection, message, out_serial, error);
+ ret = g_dbus_connection_send_message_unlocked (connection, message, flags, out_serial, error);
CONNECTION_UNLOCK (connection);
return ret;
}
static void
g_dbus_connection_send_message_with_reply_unlocked (GDBusConnection *connection,
GDBusMessage *message,
+ GDBusSendMessageFlags flags,
gint timeout_msec,
volatile guint32 *out_serial,
GCancellable *cancellable,
}
error = NULL;
- if (!g_dbus_connection_send_message_unlocked (connection, message, out_serial, &error))
+ if (!g_dbus_connection_send_message_unlocked (connection, message, flags, out_serial, &error))
{
g_simple_async_result_set_from_error (simple, error);
g_simple_async_result_complete_in_idle (simple);
* g_dbus_connection_send_message_with_reply:
* @connection: A #GDBusConnection.
* @message: A #GDBusMessage.
+ * @flags: Flags affecting how the message is sent.
* @timeout_msec: The timeout in milliseconds or -1 to use the default timeout.
* @out_serial: Return location for serial number assigned to @message when sending it or %NULL.
* @cancellable: A #GCancellable or %NULL.
*
* Asynchronously sends @message to the peer represented by @connection.
*
- * If g_dbus_message_get_serial() returns non-zero for @message, then
- * that value is used for the message serial number. Otherwise a
- * serial number will be assigned by @connection and set on @message
- * via g_dbus_message_set_serial(). If @out_serial is not %NULL, then
- * the serial number used will be written to this location prior to
+ * Unless @flags contain the
+ * %G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag, the serial number
+ * will be assigned by @connection and set on @message via
+ * g_dbus_message_set_serial(). If @out_serial is not %NULL, then the
+ * serial number used will be written to this location prior to
* submitting the message to the underlying transport.
*
* If @connection is closed then the operation will fail with
* g_dbus_connection_send_message_with_reply_finish() to get the result of the operation.
* See g_dbus_connection_send_message_with_reply_sync() for the synchronous version.
*
+ * Note that @message must be unlocked, unless @flags contain the
+ * %G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag.
+ *
* See <xref linkend="gdbus-server"/> and <xref
* linkend="gdbus-unix-fd-client"/> for an example of how to use this
* low-level API to send and receive UNIX file descriptors.
void
g_dbus_connection_send_message_with_reply (GDBusConnection *connection,
GDBusMessage *message,
+ GDBusSendMessageFlags flags,
gint timeout_msec,
volatile guint32 *out_serial,
GCancellable *cancellable,
{
g_return_if_fail (G_IS_DBUS_CONNECTION (connection));
g_return_if_fail (G_IS_DBUS_MESSAGE (message));
+ g_return_if_fail ((flags & G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL) || !g_dbus_message_get_locked (message));
g_return_if_fail (timeout_msec >= 0 || timeout_msec == -1);
CONNECTION_LOCK (connection);
g_dbus_connection_send_message_with_reply_unlocked (connection,
message,
+ flags,
timeout_msec,
out_serial,
cancellable,
* linkend="gdbus-unix-fd-client"/> for an example of how to use this
* low-level API to send and receive UNIX file descriptors.
*
- * Returns: A #GDBusMessage or %NULL if @error is set.
+ * Returns: A locked #GDBusMessage or %NULL if @error is set.
*
* Since: 2.26
*/
* g_dbus_connection_send_message_with_reply_sync:
* @connection: A #GDBusConnection.
* @message: A #GDBusMessage.
+ * @flags: Flags affecting how the message is sent.
* @timeout_msec: The timeout in milliseconds or -1 to use the default timeout.
* @out_serial: Return location for serial number assigned to @message when sending it or %NULL.
* @cancellable: A #GCancellable or %NULL.
* timeout is reached. See g_dbus_connection_send_message_with_reply()
* for the asynchronous version of this method.
*
- * If g_dbus_message_get_serial() returns non-zero for @message, then
- * that value is used for the message serial number. Otherwise a
- * serial number will be assigned by @connection and set on @message
- * via g_dbus_message_set_serial(). If @out_serial is not %NULL, then
- * the serial number used will be written to this location prior to
+ * Unless @flags contain the
+ * %G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag, the serial number
+ * will be assigned by @connection and set on @message via
+ * g_dbus_message_set_serial(). If @out_serial is not %NULL, then the
+ * serial number used will be written to this location prior to
* submitting the message to the underlying transport.
*
* If @connection is closed then the operation will fail with
* linkend="gdbus-unix-fd-client"/> for an example of how to use this
* low-level API to send and receive UNIX file descriptors.
*
- * Returns: A #GDBusMessage that is the reply to @message or %NULL if @error is set.
+ * Note that @message must be unlocked, unless @flags contain the
+ * %G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag.
+ *
+ * Returns: A locked #GDBusMessage that is the reply to @message or %NULL if @error is set.
*
* Since: 2.26
*/
GDBusMessage *
g_dbus_connection_send_message_with_reply_sync (GDBusConnection *connection,
GDBusMessage *message,
+ GDBusSendMessageFlags flags,
gint timeout_msec,
volatile guint32 *out_serial,
GCancellable *cancellable,
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
+ g_return_val_if_fail ((flags & G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL) || !g_dbus_message_get_locked (message), FALSE);
g_return_val_if_fail (timeout_msec >= 0 || timeout_msec == -1, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
g_dbus_connection_send_message_with_reply (connection,
message,
+ flags,
timeout_msec,
out_serial,
cancellable,
GDBusMessage *message,
gpointer user_data)
{
- GDBusConnection *connection = G_DBUS_CONNECTION (user_data);
+ GDBusConnection *connection;
FilterCallback *filters;
gboolean consumed_by_filter;
+ gboolean altered_by_filter;
guint num_filters;
guint n;
+ gboolean alive;
+
+ G_LOCK (message_bus_lock);
+ alive = (g_hash_table_lookup (alive_connections, user_data) != NULL);
+ if (!alive)
+ {
+ G_UNLOCK (message_bus_lock);
+ return;
+ }
+ connection = G_DBUS_CONNECTION (user_data);
+ g_object_ref (connection);
+ G_UNLOCK (message_bus_lock);
//g_debug ("in on_worker_message_received");
- g_object_ref (connection);
+ g_object_ref (message);
+ g_dbus_message_lock (message);
+
+ //g_debug ("boo ref_count = %d %p %p", G_OBJECT (connection)->ref_count, connection, connection->worker);
/* First collect the set of callback functions */
CONNECTION_LOCK (connection);
}
CONNECTION_UNLOCK (connection);
- /* the call the filters in order (without holding the lock) */
+ /* then call the filters in order (without holding the lock) */
consumed_by_filter = FALSE;
+ altered_by_filter = FALSE;
for (n = 0; n < num_filters; n++)
{
- consumed_by_filter = filters[n].func (connection,
- message,
- TRUE,
- filters[n].user_data);
- if (consumed_by_filter)
+ message = filters[n].func (connection,
+ message,
+ TRUE,
+ filters[n].user_data);
+ if (message == NULL)
break;
+ g_dbus_message_lock (message);
}
- /* Standard dispatch unless the filter ate the message */
- if (!consumed_by_filter)
+ /* Standard dispatch unless the filter ate the message - no need to
+ * do anything if the message was altered
+ */
+ if (message != NULL)
{
GDBusMessageType message_type;
}
}
+ if (message != NULL)
+ g_object_unref (message);
g_object_unref (connection);
g_free (filters);
}
/* Called in worker's thread */
-static gboolean
+static GDBusMessage *
on_worker_message_about_to_be_sent (GDBusWorker *worker,
GDBusMessage *message,
gpointer user_data)
{
- GDBusConnection *connection = G_DBUS_CONNECTION (user_data);
+ GDBusConnection *connection;
FilterCallback *filters;
- gboolean consumed_by_filter;
guint num_filters;
guint n;
+ gboolean alive;
- //g_debug ("in on_worker_message_about_to_be_sent");
-
+ G_LOCK (message_bus_lock);
+ alive = (g_hash_table_lookup (alive_connections, user_data) != NULL);
+ if (!alive)
+ {
+ G_UNLOCK (message_bus_lock);
+ return message;
+ }
+ connection = G_DBUS_CONNECTION (user_data);
g_object_ref (connection);
+ G_UNLOCK (message_bus_lock);
+
+ //g_debug ("in on_worker_message_about_to_be_sent");
/* First collect the set of callback functions */
CONNECTION_LOCK (connection);
}
CONNECTION_UNLOCK (connection);
- /* the call the filters in order (without holding the lock) */
- consumed_by_filter = FALSE;
+ /* then call the filters in order (without holding the lock) */
for (n = 0; n < num_filters; n++)
{
- consumed_by_filter = filters[n].func (connection,
- message,
- FALSE,
- filters[n].user_data);
- if (consumed_by_filter)
+ g_dbus_message_lock (message);
+ message = filters[n].func (connection,
+ message,
+ FALSE,
+ filters[n].user_data);
+ if (message == NULL)
break;
}
g_object_unref (connection);
g_free (filters);
- return consumed_by_filter;
+ return message;
}
/* Called in worker's thread - we must not block */
GError *error,
gpointer user_data)
{
- GDBusConnection *connection = G_DBUS_CONNECTION (user_data);
+ GDBusConnection *connection;
+ gboolean alive;
+
+ G_LOCK (message_bus_lock);
+ alive = (g_hash_table_lookup (alive_connections, user_data) != NULL);
+ if (!alive)
+ {
+ G_UNLOCK (message_bus_lock);
+ return;
+ }
+ connection = G_DBUS_CONNECTION (user_data);
+ g_object_ref (connection);
+ G_UNLOCK (message_bus_lock);
//g_debug ("in on_worker_closed: %s", error->message);
if (!connection->closed)
set_closed_unlocked (connection, remote_peer_vanished, error);
CONNECTION_UNLOCK (connection);
+
+ g_object_unref (connection);
}
/* ---------------------------------------------------------------------------------------------------- */
(connection->flags & G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS),
get_offered_capabilities_max (connection),
&connection->capabilities,
- &connection->crendentials,
+ &connection->credentials,
cancellable,
&connection->initialization_error))
goto out;
}
#endif
+ G_LOCK (message_bus_lock);
+ if (alive_connections == NULL)
+ alive_connections = g_hash_table_new (g_direct_hash, g_direct_equal);
+ g_hash_table_insert (alive_connections, connection, connection);
+ G_UNLOCK (message_bus_lock);
+
connection->worker = _g_dbus_worker_new (connection->stream,
connection->capabilities,
(connection->flags & G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING),
g_dbus_connection_get_peer_credentials (GDBusConnection *connection)
{
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
- return connection->crendentials;
+ return connection->credentials;
}
/* ---------------------------------------------------------------------------------------------------- */
* are run in the order that they were added. The same handler can be
* added as a filter more than once, in which case it will be run more
* than once. Filters added during a filter callback won't be run on
- * the message being processed.
+ * the message being processed. Filter functions are allowed to modify
+ * and even drop messages - see the #GDBusMessageFilterResult
+ * enumeration for details.
*
* Note that filters are run in a dedicated message handling thread so
* they can't block and, generally, can't do anything but signal a
* g_dbus_connection_signal_subscribe() or
* g_dbus_connection_call() instead.
*
- * If a filter consumes an incoming message (by returning %TRUE), the
- * message is not dispatched anywhere else - not even the standard
- * dispatch machinery (that API such as
- * g_dbus_connection_signal_subscribe() and
+ * If a filter consumes an incoming message the message is not
+ * dispatched anywhere else - not even the standard dispatch machinery
+ * (that API such as g_dbus_connection_signal_subscribe() and
* g_dbus_connection_send_message_with_reply() relies on) will see the
* message. Similary, if a filter consumes an outgoing message, the
* message will not be sent to the other peer.
error = NULL;
if (!g_dbus_connection_send_message_unlocked (connection,
message,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
NULL,
&error))
{
error = NULL;
if (!g_dbus_connection_send_message_unlocked (connection,
message,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
NULL,
&error))
{
* @member: D-Bus signal name to match on or %NULL to match on all signals.
* @object_path: Object path to match on or %NULL to match on all object paths.
* @arg0: Contents of first string argument to match on or %NULL to match on all kinds of arguments.
+ * @flags: Flags describing how to subscribe to the signal (currently unused).
* @callback: Callback to invoke when there is a signal matching the requested data.
* @user_data: User data to pass to @callback.
* @user_data_free_func: Function to free @user_data with when subscription is removed or %NULL.
const gchar *member,
const gchar *object_path,
const gchar *arg0,
+ GDBusSignalFlags flags,
GDBusSignalCallback callback,
gpointer user_data,
GDestroyNotify user_data_free_func)
/* ---------------------------------------------------------------------------------------------------- */
-/* must hold lock when calling this */
+/* must hold lock when calling this (except if connection->finalizing is TRUE) */
static void
unsubscribe_id_internal (GDBusConnection *connection,
guint subscription_id,
if (connection->flags & G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION)
{
if (!is_signal_data_for_name_lost_or_acquired (signal_data))
- if (!connection->closed)
+ if (!connection->closed && !connection->finalizing)
remove_match_rule (connection, signal_data->rule);
}
signal_data_free (signal_data);
{
SignalSubscriber *subscriber;
subscriber = &(g_array_index (subscribers, SignalSubscriber, n));
- if (subscriber->user_data_free_func != NULL)
- subscriber->user_data_free_func (subscriber->user_data);
+ call_destroy_notify (subscriber->context,
+ subscriber->user_data_free_func,
+ subscriber->user_data);
if (subscriber->context != NULL)
g_main_context_unref (subscriber->context);
}
_g_dbus_debug_print_lock ();
g_print ("========================================================================\n"
"GDBus-debug:Signal:\n"
- " >>>> SIGNAL %s.%s\n"
+ " <<<< RECEIVED SIGNAL %s.%s\n"
" on object %s\n"
" sent by name %s\n",
g_dbus_message_get_interface (message),
{
SignalSubscriber *subscriber;
subscriber = &(g_array_index (subscribers, SignalSubscriber, n));
- if (subscriber->user_data_free_func != NULL)
- subscriber->user_data_free_func (subscriber->user_data);
+ call_destroy_notify (subscriber->context,
+ subscriber->user_data_free_func,
+ subscriber->user_data);
if (subscriber->context != NULL)
g_main_context_unref (subscriber->context);
}
/* ---------------------------------------------------------------------------------------------------- */
+static GDBusInterfaceVTable *
+_g_dbus_interface_vtable_copy (const GDBusInterfaceVTable *vtable)
+{
+ /* Don't waste memory by copying padding - remember to update this
+ * when changing struct _GDBusInterfaceVTable in gdbusconnection.h
+ */
+ return g_memdup ((gconstpointer) vtable, 3 * sizeof (gpointer));
+}
+
+static void
+_g_dbus_interface_vtable_free (GDBusInterfaceVTable *vtable)
+{
+ g_free (vtable);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static GDBusSubtreeVTable *
+_g_dbus_subtree_vtable_copy (const GDBusSubtreeVTable *vtable)
+{
+ /* Don't waste memory by copying padding - remember to update this
+ * when changing struct _GDBusSubtreeVTable in gdbusconnection.h
+ */
+ return g_memdup ((gconstpointer) vtable, 3 * sizeof (gpointer));
+}
+
+static void
+_g_dbus_subtree_vtable_free (GDBusSubtreeVTable *vtable)
+{
+ g_free (vtable);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
struct ExportedObject
{
gchar *object_path;
guint id;
gchar *interface_name;
- const GDBusInterfaceVTable *vtable;
- const GDBusInterfaceInfo *interface_info;
+ GDBusInterfaceVTable *vtable;
+ GDBusInterfaceInfo *interface_info;
GMainContext *context;
gpointer user_data;
{
g_dbus_interface_info_unref ((GDBusInterfaceInfo *) ei->interface_info);
- if (ei->user_data_free_func != NULL)
- /* TODO: push to thread-default mainloop */
- ei->user_data_free_func (ei->user_data);
+ call_destroy_notify (ei->context,
+ ei->user_data_free_func,
+ ei->user_data);
if (ei->context != NULL)
g_main_context_unref (ei->context);
g_free (ei->interface_name);
+ _g_dbus_interface_vtable_free (ei->vtable);
g_free (ei);
}
gpointer user_data;
const gchar *property_name;
const GDBusInterfaceVTable *vtable;
- const GDBusInterfaceInfo *interface_info;
+ GDBusInterfaceInfo *interface_info;
const GDBusPropertyInfo *property_info;
guint registration_id;
guint subtree_registration_id;
"org.freedesktop.DBus.Error.UnknownMethod",
_("No such interface `org.freedesktop.DBus.Properties' on object at path %s"),
g_dbus_message_get_path (data->message));
- g_dbus_connection_send_message (data->connection, reply, NULL, NULL);
+ g_dbus_connection_send_message (data->connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
goto out;
}
{
g_assert_no_error (error);
- g_variant_ref_sink (value);
+ if (g_variant_is_floating (value))
+ g_variant_ref_sink (value);
reply = g_dbus_message_new_method_reply (data->message);
g_dbus_message_set_body (reply, g_variant_new ("(v)", value));
- g_dbus_connection_send_message (data->connection, reply, NULL, NULL);
+ g_dbus_connection_send_message (data->connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_variant_unref (value);
g_object_unref (reply);
}
reply = g_dbus_message_new_method_error_literal (data->message,
dbus_error_name,
error->message);
- g_dbus_connection_send_message (data->connection, reply, NULL, NULL);
+ g_dbus_connection_send_message (data->connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_free (dbus_error_name);
g_error_free (error);
g_object_unref (reply);
out:
g_assert (reply != NULL);
- g_dbus_connection_send_message (data->connection, reply, NULL, NULL);
+ g_dbus_connection_send_message (data->connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
+ g_variant_unref (value);
return FALSE;
}
guint registration_id,
guint subtree_registration_id,
gboolean is_get,
- const GDBusInterfaceInfo *interface_info,
+ GDBusInterfaceInfo *interface_info,
const GDBusInterfaceVTable *vtable,
GMainContext *main_context,
gpointer user_data)
"org.freedesktop.DBus.Error.InvalidArgs",
_("No such property `%s'"),
property_name);
- g_dbus_connection_send_message_unlocked (connection, reply, NULL, NULL);
+ g_dbus_connection_send_message_unlocked (connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
handled = TRUE;
goto out;
"org.freedesktop.DBus.Error.InvalidArgs",
_("Property `%s' is not readable"),
property_name);
- g_dbus_connection_send_message_unlocked (connection, reply, NULL, NULL);
+ g_dbus_connection_send_message_unlocked (connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
handled = TRUE;
goto out;
"org.freedesktop.DBus.Error.InvalidArgs",
_("Property `%s' is not writable"),
property_name);
- g_dbus_connection_send_message_unlocked (connection, reply, NULL, NULL);
+ g_dbus_connection_send_message_unlocked (connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
handled = TRUE;
goto out;
"org.freedesktop.DBus.Error.InvalidArgs",
_("No such interface `%s'"),
interface_name);
- g_dbus_connection_send_message_unlocked (eo->connection, reply, NULL, NULL);
+ g_dbus_connection_send_message_unlocked (eo->connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
handled = TRUE;
goto out;
GDBusMessage *message;
gpointer user_data;
const GDBusInterfaceVTable *vtable;
- const GDBusInterfaceInfo *interface_info;
+ GDBusInterfaceInfo *interface_info;
guint registration_id;
guint subtree_registration_id;
} PropertyGetAllData;
"org.freedesktop.DBus.Error.UnknownMethod",
_("No such interface `org.freedesktop.DBus.Properties' on object at path %s"),
g_dbus_message_get_path (data->message));
- g_dbus_connection_send_message (data->connection, reply, NULL, NULL);
+ g_dbus_connection_send_message (data->connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
goto out;
}
if (value == NULL)
continue;
+ if (g_variant_is_floating (value))
+ g_variant_ref_sink (value);
g_variant_builder_add (&builder,
"{sv}",
property_info->name,
value);
+ g_variant_unref (value);
}
g_variant_builder_close (&builder);
reply = g_dbus_message_new_method_reply (data->message);
g_dbus_message_set_body (reply, g_variant_builder_end (&builder));
- g_dbus_connection_send_message (data->connection, reply, NULL, NULL);
+ g_dbus_connection_send_message (data->connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
out:
GDBusMessage *message,
guint registration_id,
guint subtree_registration_id,
- const GDBusInterfaceInfo *interface_info,
+ GDBusInterfaceInfo *interface_info,
const GDBusInterfaceVTable *vtable,
GMainContext *main_context,
gpointer user_data)
"org.freedesktop.DBus.Error.InvalidArgs",
_("No such interface"),
interface_name);
- g_dbus_connection_send_message_unlocked (eo->connection, reply, NULL, NULL);
+ g_dbus_connection_send_message_unlocked (eo->connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
handled = TRUE;
goto out;
reply = g_dbus_message_new_method_reply (message);
g_dbus_message_set_body (reply, g_variant_new ("(s)", s->str));
- g_dbus_connection_send_message_unlocked (connection, reply, NULL, NULL);
+ g_dbus_connection_send_message_unlocked (connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
g_string_free (s, TRUE);
_("No such interface `%s' on object at path %s"),
g_dbus_method_invocation_get_interface_name (invocation),
g_dbus_method_invocation_get_object_path (invocation));
- g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), reply, NULL, NULL);
+ g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
goto out;
}
GDBusMessage *message,
guint registration_id,
guint subtree_registration_id,
- const GDBusInterfaceInfo *interface_info,
+ GDBusInterfaceInfo *interface_info,
const GDBusInterfaceVTable *vtable,
GMainContext *main_context,
gpointer user_data)
"org.freedesktop.DBus.Error.UnknownMethod",
_("No such method `%s'"),
g_dbus_message_get_member (message));
- g_dbus_connection_send_message_unlocked (connection, reply, NULL, NULL);
+ g_dbus_connection_send_message_unlocked (connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
handled = TRUE;
goto out;
_("Type of message, `%s', does not match expected type `%s'"),
g_variant_get_type_string (parameters),
type_string);
- g_dbus_connection_send_message_unlocked (connection, reply, NULL, NULL);
+ g_dbus_connection_send_message_unlocked (connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_variant_type_free (in_type);
g_variant_unref (parameters);
g_object_unref (reply);
g_variant_type_free (in_type);
/* schedule the call in idle */
- invocation = g_dbus_method_invocation_new (g_dbus_message_get_sender (message),
- g_dbus_message_get_path (message),
- g_dbus_message_get_interface (message),
- g_dbus_message_get_member (message),
- method_info,
- connection,
- message,
- parameters,
- user_data);
+ invocation = _g_dbus_method_invocation_new (g_dbus_message_get_sender (message),
+ g_dbus_message_get_path (message),
+ g_dbus_message_get_interface (message),
+ g_dbus_message_get_member (message),
+ method_info,
+ connection,
+ message,
+ parameters,
+ user_data);
g_variant_unref (parameters);
/* TODO: would be nicer with a real MethodData like we already
* If an existing callback is already registered at @object_path and
* @interface_name, then @error is set to #G_IO_ERROR_EXISTS.
*
- * Note that @vtable is not copied, so the struct you pass must exist until
- * the path is unregistered. One possibility is to free @vtable at the
- * same time as @user_data when @user_data_free_func is called.
- *
* GDBus automatically implements the standard D-Bus interfaces
* org.freedesktop.DBus.Properties, org.freedesktop.DBus.Introspectable
* and org.freedesktop.Peer, so you don't have to implement those for
* org.freedesktop.DBus.Properties yourself, e.g. to handle getting
* and setting of properties asynchronously.
*
+ * Note that the reference count on @interface_info will be
+ * incremented by 1 (unless allocated statically, e.g. if the
+ * reference count is -1, see g_dbus_interface_info_ref()) for as long
+ * as the object is exported. Also note that @vtable will be copied.
+ *
* See <xref linkend="gdbus-server"/> for an example of how to use this method.
*
* Returns: 0 if @error is set, otherwise a registration id (never 0)
guint
g_dbus_connection_register_object (GDBusConnection *connection,
const gchar *object_path,
- const GDBusInterfaceInfo *interface_info,
+ GDBusInterfaceInfo *interface_info,
const GDBusInterfaceVTable *vtable,
gpointer user_data,
GDestroyNotify user_data_free_func,
ei->eo = eo;
ei->user_data = user_data;
ei->user_data_free_func = user_data_free_func;
- ei->vtable = vtable;
- ei->interface_info = g_dbus_interface_info_ref ((GDBusInterfaceInfo *) interface_info);
+ ei->vtable = _g_dbus_interface_vtable_copy (vtable);
+ ei->interface_info = g_dbus_interface_info_ref (interface_info);
ei->interface_name = g_strdup (interface_info->name);
ei->context = g_main_context_get_thread_default ();
if (ei->context != NULL)
if (parameters != NULL)
g_dbus_message_set_body (message, parameters);
- ret = g_dbus_connection_send_message (connection, message, NULL, error);
+ ret = g_dbus_connection_send_message (connection, message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, error);
g_object_unref (message);
return ret;
_g_dbus_debug_print_lock ();
g_print ("========================================================================\n"
"GDBus-debug:Call:\n"
- " >>>> ASYNC COMPLETE %s() (serial %d)\n"
+ " <<<< ASYNC COMPLETE %s() (serial %d)\n"
" ",
state->method_name,
state->serial);
g_dbus_connection_send_message_with_reply (connection,
message,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
timeout_msec,
&state->serial,
cancellable,
simple = G_SIMPLE_ASYNC_RESULT (res);
if (g_simple_async_result_propagate_error (simple, error))
- return FALSE;
+ return NULL;
return g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple));
}
local_error = NULL;
reply = g_dbus_connection_send_message_with_reply_sync (connection,
message,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
timeout_msec,
NULL, /* volatile guint32 *out_serial */
cancellable,
guint id;
gchar *object_path;
GDBusConnection *connection;
- const GDBusSubtreeVTable *vtable;
+ GDBusSubtreeVTable *vtable;
GDBusSubtreeFlags flags;
GMainContext *context;
static void
exported_subtree_free (ExportedSubtree *es)
{
- if (es->user_data_free_func != NULL)
- /* TODO: push to thread-default mainloop */
- es->user_data_free_func (es->user_data);
+ call_destroy_notify (es->context,
+ es->user_data_free_func,
+ es->user_data);
if (es->context != NULL)
g_main_context_unref (es->context);
+ _g_dbus_subtree_vtable_free (es->vtable);
g_free (es->object_path);
g_free (es);
}
const gchar *sender;
const gchar *requested_object_path;
const gchar *requested_node;
- GPtrArray *interfaces;
+ GDBusInterfaceInfo **interfaces;
guint n;
gchar **subnode_paths;
}
else
{
- requested_node = "/";
+ requested_node = NULL;
}
interfaces = es->vtable->introspect (es->connection,
es->user_data);
if (interfaces != NULL)
{
- if (interfaces->len > 0)
- {
- /* we're in business */
- introspect_append_standard_interfaces (s);
+ introspect_append_standard_interfaces (s);
- for (n = 0; n < interfaces->len; n++)
- {
- const GDBusInterfaceInfo *interface_info = interfaces->pdata[n];
- g_dbus_interface_info_generate_xml (interface_info, 2, s);
- }
+ for (n = 0; interfaces[n] != NULL; n++)
+ {
+ g_dbus_interface_info_generate_xml (interfaces[n], 2, s);
+ g_dbus_interface_info_unref (interfaces[n]);
}
- g_ptr_array_unref (interfaces);
+ g_free (interfaces);
}
/* then include <node> entries from the Subtree for the root */
reply = g_dbus_message_new_method_reply (message);
g_dbus_message_set_body (reply, g_variant_new ("(s)", s->str));
- g_dbus_connection_send_message (connection, reply, NULL, NULL);
+ g_dbus_connection_send_message (connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
handled = TRUE;
const gchar *requested_object_path;
const gchar *requested_node;
gboolean is_root;
- gchar **children;
- const GDBusInterfaceInfo *interface_info;
+ GDBusInterfaceInfo *interface_info;
const GDBusInterfaceVTable *interface_vtable;
gpointer interface_user_data;
guint n;
- GPtrArray *interfaces;
+ GDBusInterfaceInfo **interfaces;
gboolean is_property_get;
gboolean is_property_set;
gboolean is_property_get_all;
is_property_get_all = TRUE;
}
- children = es->vtable->enumerate (es->connection,
- sender,
- es->object_path,
- es->user_data);
-
if (!is_root)
{
requested_node = strrchr (requested_object_path, '/') + 1;
- /* If not dynamic, skip if requested node is not part of children */
- if (!(es->flags & G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES) &&
- !_g_strv_has_string ((const gchar * const *) children, requested_node))
- goto out;
+ if (~es->flags & G_DBUS_SUBTREE_FLAGS_DISPATCH_TO_UNENUMERATED_NODES)
+ {
+ /* We don't want to dispatch to unenumerated
+ * nodes, so ensure that the child exists.
+ */
+ gchar **children;
+ gboolean exists;
+
+ children = es->vtable->enumerate (es->connection,
+ sender,
+ es->object_path,
+ es->user_data);
+
+ exists = _g_strv_has_string ((const gchar * const *) children, requested_node);
+ g_strfreev (children);
+
+ if (!exists)
+ goto out;
+ }
}
else
{
- requested_node = "/";
+ requested_node = NULL;
}
/* get introspection data for the node */
requested_object_path,
requested_node,
es->user_data);
- g_assert (interfaces != NULL);
+
+ if (interfaces == NULL)
+ goto out;
+
interface_info = NULL;
- for (n = 0; n < interfaces->len; n++)
+ for (n = 0; interfaces[n] != NULL; n++)
{
- const GDBusInterfaceInfo *id_n = (const GDBusInterfaceInfo *) interfaces->pdata[n];
- if (g_strcmp0 (id_n->name, interface_name) == 0)
- interface_info = id_n;
+ if (g_strcmp0 (interfaces[n]->name, interface_name) == 0)
+ interface_info = interfaces[n];
}
/* dispatch the call if the user wants to handle it */
g_assert_not_reached ();
/* see if the object supports this interface at all */
- for (n = 0; n < interfaces->len; n++)
+ for (n = 0; interfaces[n] != NULL; n++)
{
- const GDBusInterfaceInfo *id_n = (const GDBusInterfaceInfo *) interfaces->pdata[n];
- if (g_strcmp0 (id_n->name, interface_name) == 0)
- interface_info = id_n;
+ if (g_strcmp0 (interfaces[n]->name, interface_name) == 0)
+ interface_info = interfaces[n];
}
/* Fail with org.freedesktop.DBus.Error.InvalidArgs if the user-code
"org.freedesktop.DBus.Error.InvalidArgs",
_("No such interface `%s'"),
interface_name);
- g_dbus_connection_send_message (es->connection, reply, NULL, NULL);
+ g_dbus_connection_send_message (es->connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
handled = TRUE;
goto out;
&interface_user_data,
es->user_data);
if (interface_vtable == NULL)
- goto out;
+ {
+ g_warning ("The subtree introspection function indicates that '%s' "
+ "is a valid interface name, but calling the dispatch "
+ "function on that interface gave us NULL", interface_name);
+ goto out;
+ }
if (is_property_get || is_property_set)
{
out:
if (interfaces != NULL)
- g_ptr_array_unref (interfaces);
- g_strfreev (children);
+ {
+ for (n = 0; interfaces[n] != NULL; n++)
+ g_dbus_interface_info_unref (interfaces[n]);
+ g_free (interfaces);
+ }
+
return handled;
}
g_dbus_message_get_member (data->message),
g_dbus_message_get_interface (data->message),
g_dbus_message_get_signature (data->message));
- g_dbus_connection_send_message (data->es->connection, reply, NULL, NULL);
+ g_dbus_connection_send_message (data->es->connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
}
* for object paths not registered via g_dbus_connection_register_object()
* or other bindings.
*
+ * Note that @vtable will be copied so you cannot change it after
+ * registration.
+ *
* See <xref linkend="gdbus-subtree-server"/> for an example of how to use this method.
*
* Returns: 0 if @error is set, otherwise a subtree registration id (never 0)
es->object_path = g_strdup (object_path);
es->connection = connection;
- es->vtable = vtable;
+ es->vtable = _g_dbus_subtree_vtable_copy (vtable);
es->flags = flags;
es->id = _global_subtree_registration_id++; /* TODO: overflow etc. */
es->user_data = user_data;
{
GDBusMessage *reply;
reply = g_dbus_message_new_method_reply (message);
- g_dbus_connection_send_message_unlocked (connection, reply, NULL, NULL);
+ g_dbus_connection_send_message_unlocked (connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
}
reply = g_dbus_message_new_method_reply (message);
g_dbus_message_set_body (reply, g_variant_new ("(s)", connection->machine_id));
}
- g_dbus_connection_send_message_unlocked (connection, reply, NULL, NULL);
+ g_dbus_connection_send_message_unlocked (connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
}
reply = g_dbus_message_new_method_reply (message);
g_dbus_message_set_body (reply, g_variant_new ("(s)", s->str));
- g_dbus_connection_send_message_unlocked (connection, reply, NULL, NULL);
+ g_dbus_connection_send_message_unlocked (connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
g_string_free (s, TRUE);
}
_g_dbus_debug_print_lock ();
g_print ("========================================================================\n"
"GDBus-debug:Incoming:\n"
- " >>>> METHOD INVOCATION %s.%s()\n"
+ " <<<< METHOD INVOCATION %s.%s()\n"
" on object %s\n"
- " invoked by name %s\n",
+ " invoked by name %s\n"
+ " serial %d\n",
interface_name, member,
path,
- g_dbus_message_get_sender (message) != NULL ? g_dbus_message_get_sender (message) : "(none)");
+ g_dbus_message_get_sender (message) != NULL ? g_dbus_message_get_sender (message) : "(none)",
+ g_dbus_message_get_serial (message));
_g_dbus_debug_print_unlock ();
}
_("No such interface `%s' on object at path %s"),
interface_name,
object_path);
- g_dbus_connection_send_message_unlocked (connection, reply, NULL, NULL);
+ g_dbus_connection_send_message_unlocked (connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
g_object_unref (reply);
out: