From 493d8cb2926c0d54a45fd1fdb7f383c730321aa8 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Mon, 19 Jul 2010 17:03:07 -0400 Subject: [PATCH] GDBus: Introduce G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL This is preferable to the current magical solution whereby the serial is only rewritten if non-zero. In particular, it makes it easier to send the same message on multiple connections without having to reset the serial number. Signed-off-by: David Zeuthen --- gio/gdbusconnection.c | 45 ++++++++++++++++++++++----------------------- gio/gioenums.h | 6 +++++- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c index fe81808..6b8ac2c 100644 --- a/gio/gdbusconnection.c +++ b/gio/gdbusconnection.c @@ -1324,11 +1324,10 @@ g_dbus_connection_send_message_unlocked (GDBusConnection *connection, 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]) { @@ -1376,17 +1375,17 @@ g_dbus_connection_send_message_unlocked (GDBusConnection *connection, * g_dbus_connection_send_message: * @connection: A #GDBusConnection. * @message: A #GDBusMessage - * @flags: Flags affecting how the message is sent (currently unused). + * @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 @@ -1690,7 +1689,7 @@ g_dbus_connection_send_message_with_reply_unlocked (GDBusConnection *connect * g_dbus_connection_send_message_with_reply: * @connection: A #GDBusConnection. * @message: A #GDBusMessage. - * @flags: Flags affecting how the message is sent (currently unused). + * @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. @@ -1700,11 +1699,11 @@ g_dbus_connection_send_message_with_reply_unlocked (GDBusConnection *connect * * 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 @@ -1828,7 +1827,7 @@ send_message_with_reply_sync_cb (GDBusConnection *connection, * g_dbus_connection_send_message_with_reply_sync: * @connection: A #GDBusConnection. * @message: A #GDBusMessage. - * @flags: Flags affecting how the message is sent (currently unused). + * @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. @@ -1839,11 +1838,11 @@ send_message_with_reply_sync_cb (GDBusConnection *connection, * 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 diff --git a/gio/gioenums.h b/gio/gioenums.h index 1bd6111..e91f37c 100644 --- a/gio/gioenums.h +++ b/gio/gioenums.h @@ -1155,14 +1155,18 @@ typedef enum /*< flags >*/ /** * GDBusSendMessageFlags: * @G_DBUS_SEND_MESSAGE_FLAGS_NONE: No flags set. + * @G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL: Do not automatically + * assign a serial number from the #GDBusConnection object when + * sending a message. * * Flags used when sending #GDBusMessages on a #GDBusConnection. * * Since: 2.26 */ -typedef enum /*< flags >*/ +typedef enum { G_DBUS_SEND_MESSAGE_FLAGS_NONE = 0, + G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL = (1<<0) } GDBusSendMessageFlags; G_END_DECLS -- 2.7.4