Unable to get response after method call

In continuation of : Sample code to capture screen to memory (raw image) in Wayland - #12 by skeller

Please refer to my code in the above link

The code works fine. If i add a sleep(5) after calling Screenshot method, I do not get the response. If I subscribe to the signal , then every thing works fine.

Is there a requirement to get the response (via g_dbus_proxy_new_for_bus_sync) within a certain amount time/race condition?

GVariant *retval=g_dbus_proxy_call_sync (proxy, “Screenshot”, g_variant_new (“(sa{sv})”,“”,options, NULL),G_DBUS_CALL_FLAGS_NONE,-1, NULL, &error);

sleep(5); //this causes the problem

if (retval)
{

    //now to get the request
    gchar *opath         = NULL;
    g_variant_get (retval, "(o)", &opath);
    auto proxy2 = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                                G_DBUS_PROXY_FLAGS_NONE,
                                                NULL,
                                                "org.freedesktop.portal.Desktop",
                                                opath,
                                                "org.freedesktop.portal.Request",
                                                NULL, NULL);


    g_signal_connect (proxy2, "g-signal",
                     G_CALLBACK (screenshot_freedesktop_dbus_signal),
                     nullptr);

the method for this signal is never called (because of the sleep added earlier)
...

Looking at Request - XDG Desktop Portal documentation

They do discuss a certain race condition, could any one elaborate on this, thanks

PS my code has been picked up from GIMP source code

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.