diff options
author | José Alburquerque <jaalburqu@svn.gnome.org> | 2010-12-21 20:05:34 -0500 |
---|---|---|
committer | José Alburquerque <jaalburqu@svn.gnome.org> | 2010-12-21 20:10:00 -0500 |
commit | cac3585d825f96852df4a85e13f2143dda0d4239 (patch) | |
tree | 10b93f4a62b7004436f6e1b332d364ed7a5a0976 /examples | |
parent | c7b7eb5f031c9af764171d071ec764f1f4d65b12 (diff) | |
download | glibmm-cac3585d825f96852df4a85e13f2143dda0d4239.tar.gz |
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.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/dbus/well-known-address-client.cc | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/examples/dbus/well-known-address-client.cc b/examples/dbus/well-known-address-client.cc index 47a2944e..0db6447d 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", |