Re: Send a message using Gio::Dbus



On Wed, Mar 6, 2013 at 6:06 PM, Yoann LE BARS <yoann le-bars net> wrote:
initialised. The thing is, I do not have a clue on how to initialise the
proxy in a proper way. Also, "connection" initialisation does not seem
quite right. Actually, I am not sure I am not using a completely wrong
approach.

        Can someone help me out this?
You'll want to use Glib::DBus::Proxy::create_for_bus_sync() (the async version is fine too)
https://developer.gnome.org/glibmm/2.34/classGio_1_1DBus_1_1Proxy.html#a275770db372ac7becfea4bb5fc2e9154

Then use proxy->call() or call_sync(). I guess you need a tuple variant with two strings, and you'll get a variant with just the cookie in it back.

Glib::Variant<Glib::ustring> app_name = Glib::Variant<Glib::ustring>::create("MyApp");
Glib::Variant<Glib::ustring> reason = Glib::Variant<Glib::ustring>::create("Playing movie");
std::vector<Glib::VariantBase> vec; 
vec.push_back(app_name);
vec.push_back(reason);
Glib::VariantContainerBase bundle = Glib::VariantContainerBase::create_tuple(vec);
Glib::VariantContainerBase result = proxy->call_sync(..., bundle, ...);
Glib::VariantBase child = result.get_child(0);
Glib::Variant<unsigned int> cookie;
try {
cookie = Glib::Variant<unsigned int>::cast_dynamic(child);
} catch (std::bad_cast e) {}

Although there's probably no reason to take apart the result, since for the UnInhibit you'll just shove 'result' right back into proxy->call_sync().

I have a class that uses the dbus notification interface here: 
https://github.com/talisein/Horizon/blob/master/src/notifier.cpp




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