[glibmm] Gio::DBus: Use VariantContainerBase for tuple Variants.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Gio::DBus: Use VariantContainerBase for tuple Variants.
- Date: Fri, 25 Mar 2011 09:29:12 +0000 (UTC)
commit 19a97d1dec0068421d2c2a1478c53419d26a4132
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Mar 25 10:29:03 2011 +0100
Gio::DBus: Use VariantContainerBase for tuple Variants.
* gio/src/dbusconnection.[hg|ccg]:
* gio/src/dbusproxy.ccg.[hg|ccg]: call_sync(), call(), call_finish():
Use VariantContainerBase, instead of VariantBase, for GVariants that are
documented as being tuples. Because the type is known we can also use
it as a simple return type instead of an output parameter.
* tools/m4/convert_gio.m4: Added a necessary conversion.
* examples/dbus/peer.cc:
* examples/dbus/userbus.cc: Adapted. These already correctly assumed that
the type should be VariantContainerBase.
ChangeLog | 14 ++++++++++++++
examples/dbus/peer.cc | 4 ++--
examples/dbus/userbus.cc | 3 +--
gio/src/dbusconnection.ccg | 35 ++++++++++-------------------------
gio/src/dbusconnection.hg | 28 +++++++++++-----------------
gio/src/dbusproxy.ccg | 30 ++++++++----------------------
gio/src/dbusproxy.hg | 17 +++++++----------
tools/m4/convert_gio.m4 | 3 ++-
8 files changed, 55 insertions(+), 79 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0d5e859..efd5a5b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-03-25 Murray Cumming <murrayc murrayc com>
+
+ Gio::DBus: Use VariantContainerBase for tuple Variants.
+
+ * gio/src/dbusconnection.[hg|ccg]:
+ * gio/src/dbusproxy.ccg.[hg|ccg]: call_sync(), call(), call_finish():
+ Use VariantContainerBase, instead of VariantBase, for GVariants that are
+ documented as being tuples. Because the type is known we can also use
+ it as a simple return type instead of an output parameter.
+ * tools/m4/convert_gio.m4: Added a necessary conversion.
+ * examples/dbus/peer.cc:
+ * examples/dbus/userbus.cc: Adapted. These already correctly assumed that
+ the type should be VariantContainerBase.
+
2.27.99:
2011-03-24 Murray Cumming <murrayc murrayc com>
diff --git a/examples/dbus/peer.cc b/examples/dbus/peer.cc
index be32da3..c35bab8 100644
--- a/examples/dbus/peer.cc
+++ b/examples/dbus/peer.cc
@@ -260,8 +260,8 @@ void run_as_client(Glib::ustring address)
try
{
- Glib::VariantContainerBase result;
- connection->call_sync(result, "/org/glibmm/DBus/TestObject",
+ const Glib::VariantContainerBase result =
+ connection->call_sync( "/org/glibmm/DBus/TestObject",
"org.glibmm.DBus.TestPeerInterface",
"HelloWorld", parameters);
diff --git a/examples/dbus/userbus.cc b/examples/dbus/userbus.cc
index bd6996d..845db3b 100644
--- a/examples/dbus/userbus.cc
+++ b/examples/dbus/userbus.cc
@@ -48,8 +48,7 @@ void dbus_proxy_available(Glib::RefPtr<Gio::AsyncResult>& result)
{
// The proxy's call method returns a tuple of the value(s) that the method
// call produces so just get the tuple as a VariantContainerBase.
- Glib::VariantContainerBase result;
- proxy->call_sync(result, "ListNames");
+ const Glib::VariantContainerBase result = proxy->call_sync("ListNames");
// Now extract the single item in the variant container which is the
// array of strings (the names).
diff --git a/gio/src/dbusconnection.ccg b/gio/src/dbusconnection.ccg
index 631eb55..273647f 100644
--- a/gio/src/dbusconnection.ccg
+++ b/gio/src/dbusconnection.ccg
@@ -42,7 +42,7 @@ static void DBusConnection_Signal_giomm_callback(GDBusConnection* connection,
{
(*the_slot)(Glib::wrap(connection, true), (sender_name ? sender_name : ""),
(object_path ? object_path : ""), (interface_name ? interface_name : ""),
- (signal_name ? signal_name : ""), Glib::VariantBase(parameters, true));
+ (signal_name ? signal_name : ""), Glib::VariantContainerBase(parameters, true));
}
catch(...)
{
@@ -652,7 +652,7 @@ void Connection::call(
const Glib::ustring& object_path,
const Glib::ustring& interface_name,
const Glib::ustring& method_name,
- const Glib::VariantBase& parameters,
+ const Glib::VariantContainerBase& parameters,
const SlotAsyncReady& slot,
const Glib::RefPtr<Cancellable>& cancellable,
const Glib::ustring& bus_name,
@@ -678,7 +678,7 @@ void Connection::call(
const Glib::ustring& object_path,
const Glib::ustring& interface_name,
const Glib::ustring& method_name,
- const Glib::VariantBase& parameters,
+ const Glib::VariantContainerBase& parameters,
const SlotAsyncReady& slot,
const Glib::ustring& bus_name,
int timeout_msec,
@@ -698,25 +698,11 @@ void Connection::call(
&SignalProxy_async_callback, slot_copy);
}
-void Connection::call_finish(
- Glib::VariantBase& output,
- const Glib::RefPtr<AsyncResult>& res
-)
-{
- GError* gerror = 0;
- GVariant* const gvariant =
- g_dbus_connection_call_finish(gobj(), Glib::unwrap(res), &gerror);
- if(gerror)
- ::Glib::Error::throw_exception(gerror);
- output.init(gvariant); // No need for extra ref.
-}
-
-void Connection::call_sync(
- Glib::VariantBase& output,
+Glib::VariantContainerBase Connection::call_sync(
const Glib::ustring& object_path,
const Glib::ustring& interface_name,
const Glib::ustring& method_name,
- const Glib::VariantBase& parameters,
+ const Glib::VariantContainerBase& parameters,
const Glib::RefPtr<Cancellable>& cancellable,
const Glib::ustring& bus_name,
int timeout_msec,
@@ -736,16 +722,15 @@ void Connection::call_sync(
if(gerror)
::Glib::Error::throw_exception(gerror);
- output.init(gvariant); // No need to take extra reference.
+ return Glib::VariantContainerBase(gvariant, false); //Dont' take an extra reference.
}
// Non-cancellable version.
-void Connection::call_sync(
- Glib::VariantBase& output,
+Glib::VariantContainerBase Connection::call_sync(
const Glib::ustring& object_path,
const Glib::ustring& interface_name,
const Glib::ustring& method_name,
- const Glib::VariantBase& parameters,
+ const Glib::VariantContainerBase& parameters,
const Glib::ustring& bus_name,
int timeout_msec,
CallFlags flags,
@@ -763,7 +748,7 @@ void Connection::call_sync(
if(gerror)
::Glib::Error::throw_exception(gerror);
- output.init(gvariant); // No need to take extra reference.
+ return Glib::VariantContainerBase(gvariant, false); //Dont' take an extra reference.
}
void Connection::emit_signal(
@@ -771,7 +756,7 @@ void Connection::emit_signal(
const Glib::ustring& interface_name,
const Glib::ustring& signal_name,
const Glib::ustring& destination_bus_name,
- const Glib::VariantBase& parameters
+ const Glib::VariantContainerBase& parameters
)
{
GError* gerror = 0;
diff --git a/gio/src/dbusconnection.hg b/gio/src/dbusconnection.hg
index 7a5c19e..f3d0b56 100644
--- a/gio/src/dbusconnection.hg
+++ b/gio/src/dbusconnection.hg
@@ -167,7 +167,7 @@ public:
*/
typedef sigc::slot<void, const Glib::RefPtr<Connection>&,
const Glib::ustring&, const Glib::ustring&, const Glib::ustring&,
- const Glib::ustring&, const Glib::VariantBase&> SlotSignal;
+ const Glib::ustring&, const Glib::VariantContainerBase&> SlotSignal;
/** Signature for slot used in add_filter().
* For example,
@@ -652,7 +652,7 @@ public:
const Glib::ustring& object_path,
const Glib::ustring& interface_name,
const Glib::ustring& method_name,
- const Glib::VariantBase& parameters,
+ const Glib::VariantContainerBase& parameters,
const SlotAsyncReady& slot,
const Glib::RefPtr<Cancellable>& cancellable,
const Glib::ustring& bus_name = Glib::ustring(),
@@ -667,7 +667,7 @@ public:
const Glib::ustring& object_path,
const Glib::ustring& interface_name,
const Glib::ustring& method_name,
- const Glib::VariantBase& parameters,
+ const Glib::VariantContainerBase& parameters,
const SlotAsyncReady& slot,
const Glib::ustring& bus_name = Glib::ustring(),
int timeout_msec = -1,
@@ -676,17 +676,13 @@ public:
);
/** Finishes an operation started with call().
- * @param output A location in which to return a tuple with return values.
* @param res A AsyncResult obtained from the SlotAsyncReady passed to
* call().
+ * @result A Variant tuple with return values.
* @throw Glib::Error.
* @newin{2,28}
*/
- void call_finish(
- Glib::VariantBase& output,
- const Glib::RefPtr<AsyncResult>& res
- );
- _IGNORE(g_dbus_connection_call_finish)
+ _WRAP_METHOD(Glib::VariantContainerBase call_finish(const Glib::RefPtr<AsyncResult>& res), g_dbus_connection_call_finish, errthrow)
/** Synchronously invokes the @a method_name method on the @a interface_name
* D-Bus interface on the remote object at @a object_path owned by @a
@@ -706,7 +702,6 @@ public:
* The calling thread is blocked until a reply is received. See call() for
* the asynchronous version of this method.
*
- * @param output A location in which to return a tuple with return values.
* @param object_path Path of remote object.
* @param interface_name D-Bus interface to invoke method on.
* @param method_name The name of the method to invoke.
@@ -719,15 +714,15 @@ public:
* timeout or G_MAXINT for no timeout.
* @param flags Flags from the Gio::DBus::CallFlags enumeration.
* @param reply_type The expected type of the reply, or <tt>0</tt>.
+ * @result A Variant tuple with return values.
* @throw Glib::Error.
* @newin{2,28}
*/
- void call_sync(
- Glib::VariantBase& output,
+ Glib::VariantContainerBase call_sync(
const Glib::ustring& object_path,
const Glib::ustring& interface_name,
const Glib::ustring& method_name,
- const Glib::VariantBase& parameters,
+ const Glib::VariantContainerBase& parameters,
const Glib::RefPtr<Cancellable>& cancellable,
const Glib::ustring& bus_name = Glib::ustring(),
int timeout_msec = -1,
@@ -737,12 +732,11 @@ public:
_IGNORE(g_dbus_connection_call_sync)
/// A non-cancellable version of call_sync().
- void call_sync(
- Glib::VariantBase& output,
+ Glib::VariantContainerBase call_sync(
const Glib::ustring& object_path,
const Glib::ustring& interface_name,
const Glib::ustring& method_name,
- const Glib::VariantBase& parameters,
+ const Glib::VariantContainerBase& parameters,
const Glib::ustring& bus_name = Glib::ustring(),
int timeout_msec = -1,
CallFlags flags = Gio::DBus::CALL_FLAGS_NONE,
@@ -769,7 +763,7 @@ public:
const Glib::ustring& interface_name,
const Glib::ustring& signal_name,
const Glib::ustring& destination_bus_name = Glib::ustring(),
- const Glib::VariantBase& parameters = Glib::VariantBase()
+ const Glib::VariantContainerBase& parameters = Glib::VariantContainerBase()
);
_IGNORE(g_dbus_connection_emit_signal)
diff --git a/gio/src/dbusproxy.ccg b/gio/src/dbusproxy.ccg
index cb6d8ac..532e1a1 100644
--- a/gio/src/dbusproxy.ccg
+++ b/gio/src/dbusproxy.ccg
@@ -319,30 +319,17 @@ void Proxy::call(const Glib::ustring& method_name,
0, &SignalProxy_async_callback, slot_copy);
}
-void Proxy::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 Proxy::call_sync(Glib::VariantBase& result,
+Glib::VariantContainerBase Proxy::call_sync(
const Glib::ustring& method_name,
const Glib::RefPtr<Cancellable>& cancellable,
- const Glib::VariantBase& parameters,
+ const Glib::VariantContainerBase& parameters,
int timeout_msec,
CallFlags flags
)
{
GError* g_error = 0;
- GVariant* const g_variant =
+ GVariant* const gvariant =
g_dbus_proxy_call_sync(gobj(), method_name.c_str(),
const_cast<GVariant*>(parameters.gobj()),
static_cast<GDBusCallFlags>(flags), timeout_msec,
@@ -351,20 +338,19 @@ void Proxy::call_sync(Glib::VariantBase& result,
if(g_error)
::Glib::Error::throw_exception(g_error);
- result.init(g_variant, false /* don't take extra reference */);
+ return Glib::VariantContainerBase(gvariant, false); //Dont' take an extra reference.
}
-void Proxy::call_sync(
- Glib::VariantBase& result,
+Glib::VariantContainerBase Proxy::call_sync(
const Glib::ustring& method_name,
- const Glib::VariantBase& parameters,
+ const Glib::VariantContainerBase& parameters,
int timeout_msec,
CallFlags flags
)
{
GError* g_error = 0;
- GVariant* const g_variant =
+ GVariant* const gvariant =
g_dbus_proxy_call_sync(gobj(), method_name.c_str(),
const_cast<GVariant*>(parameters.gobj()),
static_cast<GDBusCallFlags>(flags), timeout_msec, 0, &g_error);
@@ -372,7 +358,7 @@ void Proxy::call_sync(
if(g_error)
::Glib::Error::throw_exception(g_error);
- result.init(g_variant, false /* don't take extra reference */);
+ return Glib::VariantContainerBase(gvariant, false); //Dont' take an extra reference.
}
} //namespace DBus
diff --git a/gio/src/dbusproxy.hg b/gio/src/dbusproxy.hg
index 7924e26..5dc32fd 100644
--- a/gio/src/dbusproxy.hg
+++ b/gio/src/dbusproxy.hg
@@ -281,19 +281,17 @@ public:
/** 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().
+ * @result A Variant tuple with return values.
*
* @throw Glib::Error.
*/
- void call_finish(Glib::VariantBase& ret, const Glib::RefPtr<AsyncResult>& res);
- _IGNORE(g_dbus_proxy_call_finish)
+ _WRAP_METHOD(Glib::VariantContainerBase call_finish(const Glib::RefPtr<AsyncResult>& res), g_dbus_proxy_call_finish, errthrow)
/** 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.
@@ -301,24 +299,23 @@ public:
* @param parameters A Glib::VariantBase tuple with parameters for the
* signal.
* @param cancellable A Cancellable.
+ * @result A Variant tuple with return values.
*
* @throw Glib::Error.
*/
- void call_sync(
- Glib::VariantBase& result,
+ Glib::VariantContainerBase call_sync(
const Glib::ustring& method_name,
const Glib::RefPtr<Cancellable>& cancellable,
- const Glib::VariantBase& parameters = Glib::VariantBase(),
+ 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().
- void call_sync(
- Glib::VariantBase& result,
+ Glib::VariantContainerBase call_sync(
const Glib::ustring& method_name,
- const Glib::VariantBase& parameters = Glib::VariantBase(),
+ const Glib::VariantContainerBase& parameters = Glib::VariantContainerBase(),
int timeout_msec = -1,
CallFlags flags = Gio::DBus::CALL_FLAGS_NONE
);
diff --git a/tools/m4/convert_gio.m4 b/tools/m4/convert_gio.m4
index 54faac8..67acbce 100644
--- a/tools/m4/convert_gio.m4
+++ b/tools/m4/convert_gio.m4
@@ -188,8 +188,9 @@ _CONVERSION(`const Glib::StringArrayHandle&',`const gchar*-const*',`($3).data()'
_CONVERSION(`const Glib::RefPtr<SettingsBackend>&',`GSettingsBackend*',__CONVERT_REFPTR_TO_P)
-_CONVERSION(`GVariant*',`Glib::VariantBase',`Glib::wrap($3, true)')
+#_CONVERSION(`GVariant*',`Glib::VariantBase',`Glib::wrap($3, true)')
_CONVERSION(`GVariant*',`VariantBase',`Glib::wrap($3, true)')
+_CONVERSION(`GVariant*',`Glib::VariantContainerBase',`Glib::VariantContainerBase($3, false)')
_CONVERSION(`const Glib::VariantBase&',`GVariant*',`const_cast<GVariant*>(($3).gobj())')
#Socket
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]