[glibmm] DBusProxy: Wrap call(), call_finish() and call_sync() methods.



commit 01d87668701262180ac56f8cba3a7c1d23cd3e78
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Tue Oct 26 03:08:25 2010 -0400

    	DBusProxy: Wrap call(), call_finish() and call_sync() methods.
    
    	* gio/src/dbusconnection.hg: Wrap the DBusCallFlags enum.
    	* gio/src/dbusproxy.{ccg,hg}: Wrap the call(), call_finish() and
    	call_sync() methods.

 ChangeLog                 |    8 +++++++
 gio/src/dbusconnection.hg |    1 +
 gio/src/dbusproxy.ccg     |   49 +++++++++++++++++++++++++++++++++++++++++++++
 gio/src/dbusproxy.hg      |   43 ++++++++++++++++++++++++++++++++++-----
 4 files changed, 95 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c02ba7c..6056e1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2010-10-26  José Alburquerque  <jaalburqu svn gnome org>
 
+	DBusProxy: Wrap call(), call_finish() and call_sync() methods.
+
+	* gio/src/dbusconnection.hg: Wrap the DBusCallFlags enum.
+	* gio/src/dbusproxy.{ccg,hg}: Wrap the call(), call_finish() and
+	call_sync() methods.
+
+2010-10-26  José Alburquerque  <jaalburqu svn gnome org>
+
 	Variant: Remove floating reference on creation.
 
 	* glib/src/variant.ccg:
diff --git a/gio/src/dbusconnection.hg b/gio/src/dbusconnection.hg
index 7bb3b17..b0e8bda 100644
--- a/gio/src/dbusconnection.hg
+++ b/gio/src/dbusconnection.hg
@@ -35,6 +35,7 @@ namespace Gio
 _WRAP_ENUM(BusType, GBusType)
 _WRAP_ENUM(DBusConnectionFlags, GDBusConnectionFlags, NO_GTYPE)
 _WRAP_ENUM(DBusSendMessageFlags, GDBusSendMessageFlags, NO_GTYPE)
+_WRAP_ENUM(DBusCallFlags, GDBusCallFlags, NO_GTYPE)
 
 class DBusAuthObserver;
 
diff --git a/gio/src/dbusproxy.ccg b/gio/src/dbusproxy.ccg
index 2ae72ca..975b72c 100644
--- a/gio/src/dbusproxy.ccg
+++ b/gio/src/dbusproxy.ccg
@@ -21,6 +21,7 @@
 #include <giomm/asyncresult.h>
 #include <giomm/dbusconnection.h>
 #include <giomm/dbusintrospection.h>
+#include <giomm/slot_async.h>
 
 namespace Gio
 {
@@ -135,4 +136,52 @@ Glib::RefPtr<DBusProxy> DBusProxy::create_for_bus(BusType bus_type,
     object_path, interface_name, cancellable));
 }
 
+void DBusProxy::call(const Glib::ustring& method_name,
+  int timeout_msec, const SlotAsyncReady& slot, DBusCallFlags flags,
+  const Glib::VariantBase& parameters,
+  const Glib::RefPtr<Cancellable>& cancellable)
+{
+  // Create a copy of the slot.
+  // A pointer to it will be passed through the callback's data parameter
+  // and deleted in the callback.
+  SlotAsyncReady* slot_copy = new SlotAsyncReady(slot);
+
+  g_dbus_proxy_call(gobj(), method_name.c_str(),
+    const_cast<GVariant*>(parameters.gobj()),
+    static_cast<GDBusCallFlags>(flags), timeout_msec,
+    Glib::unwrap(cancellable), &SignalProxy_async_callback, slot_copy);
+}
+
+void DBusProxy::call_finish(Glib::VariantBase& ret, const Glib::RefPtr<AsyncResult>& res)
+{
+  GError *g_error = 0;
+
+  GVariant* const g_variant =
+    g_dbus_proxy_call_finish(gobj(), Glib::unwrap(res), &g_error);
+
+  if(g_error)
+    ::Glib::Error::throw_exception(g_error);
+
+  ret.init(g_variant, false /* don't take extra reference */);
+}
+
+void DBusProxy::call_sync(Glib::VariantBase& result,
+  const Glib::ustring& method_name, int timeout_msec, DBusCallFlags flags,
+  const Glib::VariantBase& parameters, 
+  const Glib::RefPtr<Cancellable>& cancellable)
+{
+  GError *g_error = 0;
+
+  GVariant* const g_variant =
+    g_dbus_proxy_call_sync(gobj(), method_name.c_str(), 
+    const_cast<GVariant*>(parameters.gobj()),
+    static_cast<GDBusCallFlags>(flags), timeout_msec,
+    Glib::unwrap(cancellable), &g_error);
+
+  if(g_error)
+    ::Glib::Error::throw_exception(g_error);
+
+  result.init(g_variant, false /* don't take extra reference */);
+}
+
 } // namespace Gio
diff --git a/gio/src/dbusproxy.hg b/gio/src/dbusproxy.hg
index d654bed..43e72e9 100644
--- a/gio/src/dbusproxy.hg
+++ b/gio/src/dbusproxy.hg
@@ -154,12 +154,43 @@ public:
   _WRAP_METHOD(Glib::RefPtr<DBusInterfaceInfo> get_interface_info(), g_dbus_proxy_get_interface_info)
   _WRAP_METHOD(Glib::RefPtr<const DBusInterfaceInfo> get_interface_info() const, g_dbus_proxy_get_interface_info, constversion)
 
-/* TODO:
-  _WRAP_METHOD(void call(const gchar* method_name, GVariant* parameters, GDBusCallFlags flags, gint timeout_msec, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data), g_dbus_proxy_call)
-  _WRAP_METHOD(GVariant* call_finish(GAsyncResult* res, GError** error),
-g_dbus_proxy_call_finish)
-  _WRAP_METHOD(GVariant* call_sync(const gchar* method_name, GVariant* parameters, GDBusCallFlags flags, gint timeout_msec, GCancellable* cancellable, GError** error), g_dbus_proxy_call_sync)
- */
+  _WRAP_METHOD_DOCS_ONLY(g_dbus_proxy_call)
+  void call(const Glib::ustring& method_name,
+    int timeout_msec, const SlotAsyncReady& slot,
+    DBusCallFlags flags = Gio::DBUS_CALL_FLAGS_NONE,
+    const Glib::VariantBase& parameters = Glib::VariantBase(),
+    const Glib::RefPtr<Cancellable>& cancellable = Glib::RefPtr<Cancellable>());
+
+  /** Finishes an operation started with call().
+   *
+   * @param ret An output variable in which to store the return.
+   * @param res An AsyncResult obtained from the SlotAsyncReady passed to
+   * call().
+   *
+   * @throw Glib::Error.
+   */
+  void call_finish(Glib::VariantBase& ret, const Glib::RefPtr<AsyncResult>& res);
+  _IGNORE(g_dbus_proxy_call_finish)
+
+  /** Synchronously invokes the method_name method on proxy.
+   * See call(), the asynchronous version of this method for more information.
+   *
+   * @param result An output parameter in which to store the return.
+   * @param method_name Name of method to invoke.
+   * @param timeout_msec The timeout in milliseconds or -1 to use the proxy
+   * default timeout.
+   * @param flags Flags from the DBusCallFlags enumeration.
+   * @param parameters A Glib::VariantBase tuple with parameters for the
+   * signal.
+   * @param cancellable A Cancellable.
+   *
+   * @throw Glib::Error.
+   */
+  void call_sync(Glib::VariantBase& result, const Glib::ustring& method_name,
+    int timeout_msec,
+    DBusCallFlags flags = Gio::DBUS_CALL_FLAGS_NONE,
+    const Glib::VariantBase& parameters = Glib::VariantBase(),
+    const Glib::RefPtr<Cancellable>& cancellable = Glib::RefPtr<Cancellable>());
 
  _WRAP_PROPERTY("g-bus-type", BusType)
  _WRAP_PROPERTY("g-connection", Glib::RefPtr<DBusConnection>)



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