[glibmm] DBus: Well known service example: Complete the example.
- From: José Alburquerque <jaalburqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] DBus: Well known service example: Complete the example.
- Date: Wed, 22 Dec 2010 01:11:08 +0000 (UTC)
commit cac3585d825f96852df4a85e13f2143dda0d4239
Author: José Alburquerque <jaalburqu svn gnome org>
Date: Tue Dec 21 20:05:34 2010 -0500
DBus: Well known service example: Complete the example.
* examples/dbus/well-known-address-client.cc: Complete the well known
service example by calling the 'ListNames' method of the user's
session bus.
ChangeLog | 8 +++++++
examples/dbus/well-known-address-client.cc | 29 ++++++++++++++++++++++++---
2 files changed, 33 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c23ebeb..80c05b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2010-12-21 José Alburquerque <jaalburqu svn gnome org>
+ DBus: Well known service example: Complete the example.
+
+ * examples/dbus/well-known-address-client.cc: Complete the well known
+ service example by calling the 'ListNames' method of the user's
+ session bus.
+
+2010-12-21 José Alburquerque <jaalburqu svn gnome org>
+
Add Variant< std::vector<[Glib::ustring|std::string]> specializations.
* glib/src/variant.{ccg,hg}: Add two Variant specializations to deal
diff --git a/examples/dbus/well-known-address-client.cc b/examples/dbus/well-known-address-client.cc
index 47a2944..0db6447 100644
--- a/examples/dbus/well-known-address-client.cc
+++ b/examples/dbus/well-known-address-client.cc
@@ -44,7 +44,31 @@ void dbus_proxy_available(Glib::RefPtr<Gio::AsyncResult>& result)
return;
}
- // Call the 'ListNames' method and print the results.
+ try
+ {
+ // The 'ListNames' method returns a single element tuple of string arrays
+ // so first receive the tuple as a VariantBase container (that works fine
+ // for now).
+ Glib::Variant<Glib::VariantBase> result;
+ proxy->call_sync(result, "ListNames");
+
+ // Now extract the single item in the VariantBase container which is the
+ // array of strings (the names).
+ Glib::Variant< std::vector<Glib::ustring> > names_variant;
+ result.get(names_variant);
+
+ // Get the vector of strings.
+ std::vector<Glib::ustring> names = names_variant.get();
+
+ std::cout << "The names on the message bus are:" << std::endl;
+
+ for(unsigned i = 0; i < names.size(); i++)
+ std::cout << names[i] << "." << std::endl;
+ }
+ catch (Glib::Error& error)
+ {
+ std::cerr << "Got an error: '" << error.what() << "'." << std::endl;
+ }
// Connect an idle callback to the main loop to quit when the main loop is
// idle now that the method call is finished.
@@ -69,9 +93,6 @@ int main(int, char**)
return 1;
}
- // Print out the unique name of the connection to the user session bus.
- std::cout << connection->get_unique_name() << std::endl;
-
// Create the proxy to the bus asynchronously.
Gio::DBusProxy::create(connection, "org.freedesktop.DBus",
"/org/freedesktop/DBus", "org.freedesktop.DBus",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]