understanding the g_bus_own_name_on_connection() method

Bogdan Lotko boguslaw.lotko at chello.at
Tue Jul 30 00:40:50 PDT 2013


Hello,

I'd like to make sure, that the service name is not acquired and only 
one instance of my application is running at time.
I tried to use the g_bus_own_name_on_connection() method but it seems 
not to be the best one for my purposes.

As I understand the description of this method, if the name is already 
acquired, the /|bus_acquired_handler |/will be called. My problem is 
that the handler will be called "sometime" later so after calling the 
method I have no idea if I shell proceed or not.

id = g_bus_own_name_on_connection(...);
wait_for_handler

is somehow dubious solution

Additionally it seems there is (at least logical) bug in the return 
value (id) "that can be used with g_bus_unown_name() to stop owning the 
name".
Calling the method with G_BUS_NAME_OWNER_FLAGS_NONE flag I've started 
several applications and always got the return value equal 1.
This flag shall inhibit the the loss of the name by other (already 
running) application, so the current application should not get any 
name, so there is no name to "stop owning" it.
Though the return value is 1 and I can call

id = g_bus_own_name_on_connection(...);
g_bus_unown_name( id ); // ??? what now?

Could somebody please
1) explain the correct usage of the method
2) tell me how to reliable (in the atomic way) achieve my goal from the 
1st line

thank you for your help,

regards,

Bogdan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20130730/2949aee4/attachment.html>


More information about the dbus mailing list