Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application needs to be running for dbus_g_proxy_new_for_name to work?

Tags:

unix

glib

dbus

Can i call dbus_g_proxy_new_for_name without the application that implements the D-Bus method to be up and running ? I'm not sure if it is good practice to do so, or if is usual.

like image 734
Cumatru Avatar asked Nov 17 '25 21:11

Cumatru


1 Answers

Before I answer, I'd like to point out that DBus-GLib is deprecated. However, the answer applies to g_dbus_proxy_new (which is basically the replacement for dbus_g_proxy_new_for_name) as well.

Yes. The the dbus_g_proxy_new_for_name talks about how the owner can change over time, though it doesn't explicitly mention the case of when there is no owner at the time of the call (original emphasis):

THE NAME OWNER MAY CHANGE OVER TIME, for example between two different method calls, unless the name is a unique name. If you need a fixed owner, you need to request the current owner and bind a proxy to its unique name rather than to the generic name; see dbus_g_proxy_new_for_name_owner().

It's actually very common to use this with D-Bus activation. Check out the "Client Implementation" section of Raphaël Slinckx' DBus Activation Tutorial. It includes this snippet (pay attention to the comments):

/* This won't trigger activation! */
proxy = dbus_g_proxy_new_for_name (connection,
        "org.gnome.ServiceName",
        "/org/gnome/ServiceName",
        "org.gnome.ServiceName");

/* The method call will trigger activation, more on that later */
if (!org_gnome_ServiceName_echo_string (proxy, "The string we want echo-ed", &result, &error))
{
    /* Method failed, the GError is set, let's warn everyone */
    g_warning ("Woops remote method failed: %s", error->message);
    g_error_free (error);
    return;
}

D-Bus activation doesn't even get triggered until after a method is called, so obviously the name doesn't necessarily exist before then.

like image 195
nemequ Avatar answered Nov 19 '25 13:11

nemequ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!