From 60e66b9e631c455ee4630b47ddeea198cf243735 Mon Sep 17 00:00:00 2001 From: Vyacheslav Yurkov Date: Fri, 12 May 2017 19:18:26 +0200 Subject: 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 b13f92f0..0855f88e 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, 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(parameters.gobj()), - static_cast(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(parameters.gobj()), - static_cast(flags), timeout_msec, nullptr, &SignalProxy_async_callback, - slot_copy); -} - -Glib::VariantContainerBase -Proxy::call_sync(const Glib::ustring& method_name, const Glib::RefPtr& 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(parameters.gobj()), - static_cast(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(parameters.gobj()), - static_cast(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, - const Glib::RefPtr& 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(parameters.gobj()), static_cast(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& 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(parameters.gobj()), static_cast(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 a6e74191..1b79db3f 100644 --- a/gio/src/dbusproxy.hg +++ b/gio/src/dbusproxy.hg @@ -260,24 +260,17 @@ public: _WRAP_METHOD(Glib::RefPtr get_interface_info(), g_dbus_proxy_get_interface_info) _WRAP_METHOD(Glib::RefPtr 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, - const Glib::VariantContainerBase& parameters = Glib::VariantContainerBase(), - int timeout_msec = -1, - CallFlags flags = Gio::DBus::CALL_FLAGS_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::CALL_FLAGS_NONE - ); + _WRAP_METHOD( + void call( + const Glib::ustring& method_name{.}, + const SlotAsyncReady& slot{callback?}, + const Glib::RefPtr& cancellable{.?}, + const Glib::VariantContainerBase& parameters{.} = Glib::VariantContainerBase(), + int timeout_msec{.} = -1, + CallFlags flags{.} = Gio::DBus::CALL_FLAGS_NONE + ), + g_dbus_proxy_call, slot_name slot, slot_callback SignalProxy_async_callback + ) /** Finishes an operation started with call(). * @@ -289,81 +282,30 @@ public: */ _WRAP_METHOD(Glib::VariantContainerBase call_finish(const Glib::RefPtr& 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, - const Glib::VariantContainerBase& parameters = Glib::VariantContainerBase(), - int timeout_msec = -1, - CallFlags flags = Gio::DBus::CALL_FLAGS_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::CALL_FLAGS_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 0 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, - const Glib::RefPtr& fd_list, - int timeout_msec = -1, - CallFlags flags = Gio::DBus::CALL_FLAGS_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& fd_list, - int timeout_msec = -1, - CallFlags flags = Gio::DBus::CALL_FLAGS_NONE); + _WRAP_METHOD( + Glib::VariantContainerBase call_sync( + const Glib::ustring& method_name{.}, + const Glib::RefPtr& cancellable{.?}, + const Glib::VariantContainerBase& parameters{.} = Glib::VariantContainerBase(), + int timeout_msec{.} = -1, + CallFlags flags{.} = Gio::DBus::CALL_FLAGS_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{.?}, + const Glib::RefPtr& fd_list{.}, + int timeout_msec{.} = -1, + CallFlags flags{.} = Gio::DBus::CALL_FLAGS_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 @@ -374,7 +316,6 @@ public: * @newin{2,34} */ _WRAP_METHOD(Glib::VariantContainerBase call_finish(const Glib::RefPtr& res{.}, Glib::RefPtr& 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 5ea862dd..053ef093 100644 --- a/gio/src/gio_docs_override.xml +++ b/gio/src/gio_docs_override.xml @@ -1714,4 +1714,86 @@ errors that can happen due to races when you execute the operation. + + + + A #GDBusProxy. + + + + Name of method to invoke. + + + + A #GVariant tuple with parameters for the signal or %NULL if not passing parameters. + + + + Flags from the #GDBusCallFlags enumeration. + + + + The timeout in milliseconds (with %G_MAXINT meaning +"infinite") or -1 to use the proxy default timeout. + + + + A #GCancellable or %NULL. + + + + 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. + + + + The data to pass to @callback. + + + + + + + + + A #GDBusProxy. + + + + Name of method to invoke. + + + + A #GVariant tuple with parameters for the signal or %NULL if not passing parameters. + + + + Flags from the #GDBusCallFlags enumeration. + + + + The timeout in milliseconds (with %G_MAXINT meaning +"infinite") or -1 to use the proxy default timeout. + + + + A #GUnixFDList or %NULL. + + + + A #GCancellable or %NULL. + + + + 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. + + + + The data to pass to @callback. + + + + + -- cgit v1.2.1