[glibmm] Gio::DBus::Proxy: Wrap call() and call_sync() methods. Bug 781818



commit 97ed2764fa1833528fb5bed92306f1148cf0ff4f
Author: Vyacheslav Yurkov <uvv mail gmail com>
Date:   Fri May 12 19:28:49 2017 +0200

    Gio::DBus::Proxy: Wrap call() and call_sync() methods. Bug 781818

 gio/src/dbusproxy.ccg         |   95 ------------------------------
 gio/src/dbusproxy.hg          |  129 +++++++++++------------------------------
 gio/src/gio_docs_override.xml |   82 ++++++++++++++++++++++++++
 3 files changed, 117 insertions(+), 189 deletions(-)
---
diff --git a/gio/src/dbusproxy.ccg b/gio/src/dbusproxy.ccg
index 4bc9ecd..67ad4fa 100644
--- a/gio/src/dbusproxy.ccg
+++ b/gio/src/dbusproxy.ccg
@@ -202,101 +202,6 @@ Proxy::get_cached_property(Glib::VariantBase& property, const Glib::ustring& pro
   property.init(g_variant, false /* no extra reference needed */);
 }
 
-void
-Proxy::call(const Glib::ustring& method_name, const SlotAsyncReady& slot,
-  const Glib::RefPtr<Cancellable>& cancellable, const Glib::VariantContainerBase& parameters,
-  int timeout_msec, CallFlags flags)
-{
-  // Create a copy of the slot.
-  // A pointer to it will be passed through the callback's data parameter
-  // and deleted in the callback.
-  auto 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
-Proxy::call(const Glib::ustring& method_name, const SlotAsyncReady& slot,
-  const Glib::VariantContainerBase& parameters, int timeout_msec, CallFlags flags)
-{
-  // Create a copy of the slot.
-  // A pointer to it will be passed through the callback's data parameter
-  // and deleted in the callback.
-  auto 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, nullptr, &SignalProxy_async_callback,
-    slot_copy);
-}
-
-Glib::VariantContainerBase
-Proxy::call_sync(const Glib::ustring& method_name, const Glib::RefPtr<Cancellable>& cancellable,
-  const Glib::VariantContainerBase& parameters, int timeout_msec, CallFlags flags)
-{
-  GError* g_error = nullptr;
-
-  GVariant* const gvariant =
-    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);
-
-  return Glib::VariantContainerBase(gvariant, false); // Dont' take an extra reference.
-}
-
-Glib::VariantContainerBase
-Proxy::call_sync(const Glib::ustring& method_name, const Glib::VariantContainerBase& parameters,
-  int timeout_msec, CallFlags flags)
-{
-  GError* g_error = nullptr;
-
-  GVariant* const gvariant =
-    g_dbus_proxy_call_sync(gobj(), method_name.c_str(), const_cast<GVariant*>(parameters.gobj()),
-      static_cast<GDBusCallFlags>(flags), timeout_msec, nullptr, &g_error);
-
-  if (g_error)
-    ::Glib::Error::throw_exception(g_error);
-
-  return Glib::VariantContainerBase(gvariant, false); // Dont' take an extra reference.
-}
-
-#ifdef G_OS_UNIX
-// With a UnixFDList.
-void
-Proxy::call(const Glib::ustring& method_name, const Glib::VariantContainerBase& parameters,
-  const SlotAsyncReady& slot, const Glib::RefPtr<Cancellable>& cancellable,
-  const Glib::RefPtr<UnixFDList>& fd_list, int timeout_msec, CallFlags flags)
-{
-  // Create a copy of the slot.
-  // A pointer to it will be passed through the callback's data parameter
-  // and deleted in the callback.
-  auto slot_copy = new SlotAsyncReady(slot);
-
-  g_dbus_proxy_call_with_unix_fd_list(gobj(), method_name.c_str(),
-    const_cast<GVariant*>(parameters.gobj()), static_cast<GDBusCallFlags>(flags), timeout_msec,
-    Glib::unwrap(fd_list), Glib::unwrap(cancellable), &SignalProxy_async_callback, slot_copy);
-}
-
-// Non-cancellable version (with a UnixFDList).
-void
-Proxy::call(const Glib::ustring& method_name, const Glib::VariantContainerBase& parameters,
-  const SlotAsyncReady& slot, const Glib::RefPtr<UnixFDList>& fd_list, int timeout_msec,
-  CallFlags flags)
-{
-  // Create a copy of the slot.
-  // A pointer to it will be passed through the callback's data parameter
-  // and deleted in the callback.
-  auto slot_copy = new SlotAsyncReady(slot);
-
-  g_dbus_proxy_call_with_unix_fd_list(gobj(), method_name.c_str(),
-    const_cast<GVariant*>(parameters.gobj()), static_cast<GDBusCallFlags>(flags), timeout_msec,
-    Glib::unwrap(fd_list), nullptr, &SignalProxy_async_callback, slot_copy);
-}
-#endif // G_OS_UNIX
-
 } // namespace DBus
 
 } // namespace Gio
diff --git a/gio/src/dbusproxy.hg b/gio/src/dbusproxy.hg
index bedcb83..fb49e88 100644
--- a/gio/src/dbusproxy.hg
+++ b/gio/src/dbusproxy.hg
@@ -263,24 +263,17 @@ public:
   _WRAP_METHOD(Glib::RefPtr<InterfaceInfo> get_interface_info(), g_dbus_proxy_get_interface_info)
   _WRAP_METHOD(Glib::RefPtr<const InterfaceInfo> get_interface_info() const, 
g_dbus_proxy_get_interface_info, constversion)
 
-  _WRAP_METHOD_DOCS_ONLY(g_dbus_proxy_call)
-  void call(
-    const Glib::ustring& method_name,
-    const SlotAsyncReady& slot,
-    const Glib::RefPtr<Cancellable>& cancellable,
-    const Glib::VariantContainerBase& parameters = Glib::VariantContainerBase(),
-    int timeout_msec = -1,
-    CallFlags flags = Gio::DBus::CallFlags::NONE
-  );
-
-  /// A non-cancellable version of call().
-  void call(
-    const Glib::ustring& method_name,
-    const SlotAsyncReady& slot,
-    const Glib::VariantContainerBase& parameters = Glib::VariantContainerBase(),
-    int timeout_msec = -1,
-    CallFlags flags = Gio::DBus::CallFlags::NONE
-  );
+  _WRAP_METHOD(
+    void call(
+      const Glib::ustring&               method_name{.},
+      const SlotAsyncReady&              slot{callback?},
+      const Glib::RefPtr<Cancellable>&   cancellable{.?},
+      const Glib::VariantContainerBase&  parameters{.} = Glib::VariantContainerBase(),
+      int                                timeout_msec{.} = -1,
+      CallFlags                          flags{.} = Gio::DBus::CallFlags::NONE
+    ),
+    g_dbus_proxy_call, slot_name slot, slot_callback SignalProxy_async_callback
+  )
 
   /** Finishes an operation started with call().
    *
@@ -292,81 +285,30 @@ public:
    */
   _WRAP_METHOD(Glib::VariantContainerBase call_finish(const Glib::RefPtr<AsyncResult>& res), 
g_dbus_proxy_call_finish, errthrow)
 
-//TODO: Use _WRAP_METHOD() for this?
-  /** Synchronously invokes the method_name method on proxy.
-   * See call(), the asynchronous version of this method for more information.
-   *
-   * @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 CallFlags enumeration.
-   * @param parameters A Glib::VariantContainerBase tuple with parameters for the
-   * signal.
-   * @param cancellable A Cancellable.
-   * @result A Variant tuple with return values.
-   *
-   * @throw Glib::Error.
-   */
-  Glib::VariantContainerBase call_sync(
-    const Glib::ustring& method_name,
-    const Glib::RefPtr<Cancellable>& cancellable,
-    const Glib::VariantContainerBase& parameters = Glib::VariantContainerBase(),
-    int timeout_msec = -1,
-    CallFlags flags = Gio::DBus::CallFlags::NONE
-  );
-  _IGNORE(g_dbus_proxy_call_sync)
-
-  /// A non-cancellable version of call_sync().
-  Glib::VariantContainerBase call_sync(
-    const Glib::ustring& method_name,
-    const Glib::VariantContainerBase& parameters = Glib::VariantContainerBase(),
-    int timeout_msec = -1,
-    CallFlags flags = Gio::DBus::CallFlags::NONE
-  );
-
-
-#ifdef G_OS_UNIX
-//TODO: Use _WRAP_METHOD() for this?
-  /** Like call() but also takes a GUnixFDList object.
-   * This method is only available on UNIX.
-   *
-   * This is an asynchronous method. When the operation is finished, callback
-   * will be invoked in the thread-default main loop of the thread you are
-   * calling this method from. You can then call call_with_unix_fd_finish() to
-   * get the result of the operation. See call_sync() for the synchronous
-   * version of this function.
-   *
-   * @param method_name The name of the method to invoke.
-   * @param parameters A Glib::VariantContainerBase tuple with parameters for the
-   * method or <tt>0</tt> if not passing parameters.
-   * @param slot A SlotAsyncReady to call when the request is satisfied.
-   * @param cancellable A Cancellable.
-   * @param fd_list A UnixFDList.
-   * @param timeout_msec The timeout in milliseconds, -1 to use the default
-   * timeout or G_MAXINT for no timeout.
-   * @param flags Flags from the Gio::DBus::CallFlags enumeration.
-   * @newin{2,34}
-   */
-  void call(
-    const Glib::ustring&                method_name,
-    const Glib::VariantContainerBase&   parameters,
-    const SlotAsyncReady&               slot,
-    const Glib::RefPtr<Cancellable>&    cancellable,
-    const Glib::RefPtr<UnixFDList>&     fd_list,
-    int                                 timeout_msec = -1,
-    CallFlags                           flags = Gio::DBus::CallFlags::NONE);
-  _IGNORE(g_dbus_proxy_call_with_unix_fd_list)
-
-  /** A non-cancellable version of call() (with a UnixFDList).
-   * @newin{2,34}
-   */
-  void call(
-    const Glib::ustring&                method_name,
-    const Glib::VariantContainerBase&   parameters,
-    const SlotAsyncReady&               slot,
-    const Glib::RefPtr<UnixFDList>&     fd_list,
-    int                                 timeout_msec = -1,
-    CallFlags                           flags = Gio::DBus::CallFlags::NONE);
+  _WRAP_METHOD(
+    Glib::VariantContainerBase call_sync(
+      const Glib::ustring&               method_name{.},
+      const Glib::RefPtr<Cancellable>&   cancellable{.?},
+      const Glib::VariantContainerBase&  parameters{.} = Glib::VariantContainerBase(),
+      int                                timeout_msec{.} = -1,
+      CallFlags                          flags{.} = Gio::DBus::CallFlags::NONE
+    ),
+    g_dbus_proxy_call_sync, errthrow
+  )
+
+  _WRAP_METHOD(
+    void call(
+      const Glib::ustring&                method_name{.},
+      const Glib::VariantContainerBase&   parameters{.},
+      const SlotAsyncReady&               slot{callback?},
+      const Glib::RefPtr<Cancellable>&    cancellable{.?},
+      const Glib::RefPtr<UnixFDList>&     fd_list{.},
+      int                                 timeout_msec{.} = -1,
+      CallFlags                           flags{.} = Gio::DBus::CallFlags::NONE
+    ),
+    g_dbus_proxy_call_with_unix_fd_list, ifdef G_OS_UNIX,
+      slot_name slot, slot_callback SignalProxy_async_callback
+  )
 
   /** Finishes an operation started with call() (with a UnixFDList).
    * @param res A AsyncResult obtained from the SlotAsyncReady passed to
@@ -377,7 +319,6 @@ public:
    * @newin{2,34}
    */
   _WRAP_METHOD(Glib::VariantContainerBase call_finish(const Glib::RefPtr<AsyncResult>& res{.}, 
Glib::RefPtr<UnixFDList>& out_fd_list{.>>}), g_dbus_proxy_call_with_unix_fd_list_finish, errthrow, ifdef 
G_OS_UNIX)
-#endif // G_OS_UNIX
 
   _WRAP_METHOD(
     Glib::VariantContainerBase call_sync(
diff --git a/gio/src/gio_docs_override.xml b/gio/src/gio_docs_override.xml
index ff8873e..cbeaae1 100644
--- a/gio/src/gio_docs_override.xml
+++ b/gio/src/gio_docs_override.xml
@@ -1808,4 +1808,86 @@ errors that can happen due to races when you execute the operation.
 </return>
 </function>
 
+<function name="g_dbus_proxy_call">
+<parameters>
+<parameter name="proxy">
+<parameter_description> A #GDBusProxy.
+</parameter_description>
+</parameter>
+<parameter name="method_name">
+<parameter_description> Name of method to invoke.
+</parameter_description>
+</parameter>
+<parameter name="parameters">
+<parameter_description> A #GVariant tuple with parameters for the signal or %NULL if not passing parameters.
+</parameter_description>
+</parameter>
+<parameter name="flags">
+<parameter_description> Flags from the #GDBusCallFlags enumeration.
+</parameter_description>
+</parameter>
+<parameter name="timeout_msec">
+<parameter_description> The timeout in milliseconds (with %G_MAXINT meaning
+&quot;infinite&quot;) or -1 to use the proxy default timeout.
+</parameter_description>
+</parameter>
+<parameter name="cancellable">
+<parameter_description> A #GCancellable or %NULL.
+</parameter_description>
+</parameter>
+<parameter name="callback">
+<parameter_description> A #GAsyncReadyCallback to call when the request is satisfied. Use another overload
+without this parameter if your don't care about the result of the method invocation.
+</parameter_description>
+</parameter>
+<parameter name="user_data">
+<parameter_description> The data to pass to @callback.
+</parameter_description>
+</parameter>
+</parameters>
+</function>
+
+<function name="g_dbus_proxy_call_with_unix_fd_list">
+<parameters>
+<parameter name="proxy">
+<parameter_description> A #GDBusProxy.
+</parameter_description>
+</parameter>
+<parameter name="method_name">
+<parameter_description> Name of method to invoke.
+</parameter_description>
+</parameter>
+<parameter name="parameters">
+<parameter_description> A #GVariant tuple with parameters for the signal or %NULL if not passing parameters.
+</parameter_description>
+</parameter>
+<parameter name="flags">
+<parameter_description> Flags from the #GDBusCallFlags enumeration.
+</parameter_description>
+</parameter>
+<parameter name="timeout_msec">
+<parameter_description> The timeout in milliseconds (with %G_MAXINT meaning
+&quot;infinite&quot;) or -1 to use the proxy default timeout.
+</parameter_description>
+</parameter>
+<parameter name="fd_list">
+<parameter_description> A #GUnixFDList or %NULL.
+</parameter_description>
+</parameter>
+<parameter name="cancellable">
+<parameter_description> A #GCancellable or %NULL.
+</parameter_description>
+</parameter>
+<parameter name="callback">
+<parameter_description> A #GAsyncReadyCallback to call when the request is satisfied. Use another overload
+without this parameter if your don't care about the result of the method invocation.
+</parameter_description>
+</parameter>
+<parameter name="user_data">
+<parameter_description> The data to pass to @callback.
+</parameter_description>
+</parameter>
+</parameters>
+</function>
+
 </root>


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