[glibmm] DBusConnection: Add send_message_with_reply_sync() methods.



commit ed337b9eabcd804f4f5128511e027846a02161d3
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Sun Dec 5 21:57:05 2010 -0500

    	DBusConnection: Add send_message_with_reply_sync() methods.
    
    	* gio/src/dbusconnection.{ccg,hg}: Add cancellable and non-cancellable
    	versions of the send_message_with_reply_sync() methods (following the
    	same logic as the existing send_message_with_reply() methods).  Some
    	minor corrections.

 ChangeLog                  |    9 +++++++
 gio/src/dbusconnection.ccg |   45 +++++++++++++++++++++++++++++++++++++-
 gio/src/dbusconnection.hg  |   51 +++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 100 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0d5add9..a98eb5f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2010-12-05  José Alburquerque  <jaalburqu svn gnome org>
 
+	DBusConnection: Add send_message_with_reply_sync() methods.
+
+	* gio/src/dbusconnection.{ccg,hg}: Add cancellable and non-cancellable
+	versions of the send_message_with_reply_sync() methods (following the
+	same logic as the existing send_message_with_reply() methods).  Some
+	minor corrections.
+
+2010-12-05  José Alburquerque  <jaalburqu svn gnome org>
+
 	DBusConnection: Add signal_subscribe() and add_filter().
 
 	* gio/src/dbusconnection.{ccg,hg}: Add signal_subscribe(),
diff --git a/gio/src/dbusconnection.ccg b/gio/src/dbusconnection.ccg
index 7687d41..992803f 100644
--- a/gio/src/dbusconnection.ccg
+++ b/gio/src/dbusconnection.ccg
@@ -379,7 +379,7 @@ void DBusConnection::flush_sync()
 void DBusConnection::send_message_with_reply(const Glib::RefPtr<DBusMessage>& message, int timeout_msec,const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable)
 {
   SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
-  volatile guint32 out_serial;
+  volatile guint32 out_serial = 0;
   g_dbus_connection_send_message_with_reply(gobj(), Glib::unwrap(message),
                                       static_cast<GDBusSendMessageFlags>(message->get_flags()),
                                       timeout_msec, &out_serial,
@@ -391,7 +391,7 @@ void DBusConnection::send_message_with_reply(const Glib::RefPtr<DBusMessage>& me
 void DBusConnection::send_message_with_reply(const Glib::RefPtr<DBusMessage>& message, int timeout_msec,const SlotAsyncReady& slot)
 {
   SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
-  volatile guint32 out_serial;
+  volatile guint32 out_serial = 0;
   g_dbus_connection_send_message_with_reply(gobj(), Glib::unwrap(message),
                                       static_cast<GDBusSendMessageFlags>(message->get_flags()),
                                       timeout_msec, &out_serial,
@@ -400,6 +400,47 @@ void DBusConnection::send_message_with_reply(const Glib::RefPtr<DBusMessage>& me
   message->set_serial(out_serial);
 }
 
+Glib::RefPtr<DBusMessage> DBusConnection::send_message_with_reply_sync(
+  const Glib::RefPtr<DBusMessage>& message,
+  const Glib::RefPtr<Cancellable>& cancellable,
+  gint timeout_msec
+)
+{
+  volatile guint32 out_serial = 0;
+  GError* gerror = 0;
+
+  GDBusMessage* result =
+    g_dbus_connection_send_message_with_reply_sync(gobj(),
+    Glib::unwrap(message),
+    static_cast<GDBusSendMessageFlags>(message->get_flags()),
+    timeout_msec, &out_serial, Glib::unwrap(cancellable), &gerror);
+
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+  message->set_serial(out_serial);
+  return Glib::wrap(result);
+}
+
+Glib::RefPtr<DBusMessage> DBusConnection::send_message_with_reply_sync(
+  const Glib::RefPtr<DBusMessage>& message,
+  gint timeout_msec
+)
+{
+  volatile guint32 out_serial = 0;
+  GError* gerror = 0;
+
+  GDBusMessage* result =
+    g_dbus_connection_send_message_with_reply_sync(gobj(),
+    Glib::unwrap(message),
+    static_cast<GDBusSendMessageFlags>(message->get_flags()), timeout_msec,
+    &out_serial, 0, &gerror);
+
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+  message->set_serial(out_serial);
+  return Glib::wrap(result);
+}
+
 void DBusConnection::call(
   const Glib::ustring&                  object_path,
   const Glib::ustring&                  interface_name,
diff --git a/gio/src/dbusconnection.hg b/gio/src/dbusconnection.hg
index 22ba833..cfc3169 100644
--- a/gio/src/dbusconnection.hg
+++ b/gio/src/dbusconnection.hg
@@ -402,11 +402,11 @@ public:
   #m4 _CONVERSION(`guint32*',`volatile guint32*',`($3)')
   _WRAP_METHOD(bool send_message(const Glib::RefPtr<DBusMessage>& message, DBusSendMessageFlags flags, guint32* out_serial), g_dbus_connection_send_message, errthrow)
 
-  /** Asynchronously sends message to the peer represented by connection.
+  /** Asynchronously sends message to the peer represented by the connection.
    *
    * Unless flags contain the Gio::DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL
-   * flag, the serial number will be assigned by connection and set on message
-   * via Gio::DBusMessage::set_serial().
+   * flag, the serial number will be assigned by the connection and set on
+   * message via Gio::DBusMessage::set_serial().
    *
    * If the connection is closed then the operation will fail with
    * Gio::IO_ERROR_CLOSED. If @a cancellable is canceled, the operation will
@@ -447,6 +447,51 @@ public:
   /// @throw Glib::Error.
   _WRAP_METHOD(Glib::RefPtr<DBusMessage> send_message_with_reply_finish(const Glib::RefPtr<AsyncResult>& result), g_dbus_connection_send_message_with_reply_finish, errthrow)
 
+  /** Synchronously sends @a message to the peer represented by the connection
+   * and blocks the calling thread until a reply is received or the timeout is
+   * reached. See send_message_with_reply() for the asynchronous version of
+   * this method. 
+   *
+   * Unless flags contain the Gio::DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL
+   * flag, the serial number will be assigned by the connection and set on
+   * message via Gio::DBusMessage::set_serial().
+   *
+   * If the connection is closed then the operation will fail with
+   * Gio::IO_ERROR_CLOSED. If @a cancellable is canceled, the operation will
+   * fail with Gio::IO_ERROR_CANCELLED. If @a message is not well-formed, the
+   * operation fails with Gio::IO_ERROR_INVALID_ARGUMENT.
+   *
+   * Note that a Glib::Error is thrown if a local in-process error occured.
+   * That is to say that the returned DBusMessage object may be of type
+   * G_DBUS_MESSAGE_TYPE_ERROR. Use Gio::DBusMessage::to_exception() to
+   * transcode this to a Glib::Error.
+   *
+   * See the C API docs for examples.
+   *
+   * Note that message must be unlocked, unless flags contain the
+   * Gio::DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL flag.
+   *
+   * @param message A DBusMessage.
+   * @param cancellable A Cancellable.
+   * @param timeout_msec The timeout in milliseconds or -1 to use the default
+   * timeout.
+   * @return A locked DBusMessage that is the reply to @a message or
+   * <tt>0</tt> if a Glib::Error is thrown.
+   * @throw Glib::Error.
+   * @newin{2,28}
+   */
+  Glib::RefPtr<DBusMessage> send_message_with_reply_sync(
+    const Glib::RefPtr<DBusMessage>& message,
+    const Glib::RefPtr<Cancellable>& cancellable,
+    gint timeout_msec
+  );
+
+  /// A non-cancellable version of send_message_with_reply_sync().
+  Glib::RefPtr<DBusMessage> send_message_with_reply_sync(
+    const Glib::RefPtr<DBusMessage>& message,
+    gint timeout_msec
+  );
+
   _WRAP_METHOD(void start_message_processing(), g_dbus_connection_start_message_processing)
   _WRAP_METHOD(bool is_closed() const, g_dbus_connection_is_closed)
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]