Fwd: Re: Send a message using Gio::Dbus




Hello everybody out there!

        Thank you very much Andrew. Actually, I was totally mistaken!

        By the way: excuse me for sending this answer as personal message.

On 03/072013 07:07 a.m., Andrew Potter wrote:
You'll want to use Glib::DBus::Proxy::create_for_bus_sync() (the async
version is fine too)

Well, in general, I guess it is probably better to use asynchronous
version, as the application is not waiting for the message to be
transfer. Though, on the one hand this is the first time I am using
D-Bus, for now on I am looking for simple solutions. On the other hand,
I am only asking for inhibit or uninhibit scree-saver, I do not want and
create a slot just for this.

        Using what you gave me, here is the code I have obtained. All my
connections to D-Bus are done in my main window class. I have added as
private declarations the followings:

/* Proxy connected to D-Bus. */
Glib::RefPtr<Gio::DBus::Proxy> proxy;

/* Result of sending to D-Bus. */
Glib::VariantContainerBase result;

Then I have add the following two methods:

void inhibitScreenSaver () {
  /* Sending application name. */
  Glib::Variant<Glib::ustring> app_name =
    Glib::Variant<Glib::ustring>::create("Tutorial4");
  /* Reason for sending the message. */
  Glib::Variant<Glib::ustring> reason =
    Glib::Variant<Glib::ustring>::create("Full-screen animation");
  /* Vector containing the full message. */
  std::vector<Glib::VariantBase> vec;
  vec.push_back(app_name);
  vec.push_back(reason);
  /* Bundling the message. */
  Glib::VariantContainerBase bundle =
    Glib::VariantContainerBase::create_tuple(vec);

  result = proxy->call_sync("Inhibit", bundle);
}

void Interface::Fenetre::uninhibitScreenSaver() {
  proxy->call_sync("Uninhibit", result);
}

I get some errors right at construction, meaning just when I try and
connect to D-Bus:

(tutoriel4:4823): GLib-GIO-CRITICAL **:
g_dbus_connection_signal_subscribe: assertion `sender == NULL ||
(g_dbus_is_name (sender) && (connection->flags &
G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION))' failed

(tutoriel4:4823): GLib-GIO-CRITICAL **:
g_dbus_connection_signal_subscribe: assertion `sender == NULL ||
(g_dbus_is_name (sender) && (connection->flags &
G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION))' failed

I have try and use "gnome.org.DBus" as bus name, but it did not do any
good. I guess the error is not bus name, so this should have something
to do with "info" or "flags" in "create_for_dbus_sync."

        So, I changed proxy initialisation to this:

proxy =
  Gio::DBus::Proxy::create_for_bus_sync(Gio::DBus::BUS_TYPE_SESSION,
                                        ":session",
                                        "/org/gnome/ScreenSaver",
                                        "org.gnome.ScreenSaver",
                              Glib::RefPtr<Gio::DBus::InterfaceInfo>(),
                        Gio::DBus::PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES);

To be honest, I am not sure what it really does, but I have tried and
run it anyway. Now, I get only one error message:

(tutoriel4:4950): GLib-GIO-CRITICAL **:
g_dbus_connection_signal_subscribe: assertion `sender == NULL ||
(g_dbus_is_name (sender) && (connection->flags &
G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION))' failed

It looks like some improvement. The question is, have I done something
that I may regret later? And, where can I find some information on how
to create interface info? I have not found enough information about it
in the documentation
(<https://developer.gnome.org/glibmm/2.34/classGio_1_1DBus_1_1InterfaceInfo.html>)?

        Regards.

                                                        Yoann


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