understanding the g_bus_own_name_on_connection() method

Bogdan Lotko boguslaw.lotko at chello.at
Tue Jul 30 11:58:41 PDT 2013


Hello,

Once more thanks for these explanations!

bogdan

On 7/30/2013 20:53, David Zeuthen wrote:
> Hi,
>
>
> On Tue, Jul 30, 2013 at 11:32 AM, Bogdan Lotko 
> <boguslaw.lotko at chello.at <mailto:boguslaw.lotko at chello.at>> wrote:
>
>     Hello David,
>
>     Thank you for the answer and yes, I've read the documentation.
>     Though I still don't understand how shall I proceed to achieve my
>     goal i.e. *atomic acquirement* of service name on D-Bus.
>
>     as I wrote the
>
>     id = g_bus_own_name_on_connection(...);
>     wait_for_handler(s)
>
>     is for me rather strange solution, beside of this it creates a
>     time window where other application can register the name.
>
>
> What's so strange about it? The exact same window exists with libdbus 
> ... that is, if you're using dbus_bus_request_name() - the only 
> difference is that g_dbus_own_name() gives is non-blocking and 
> dbus_bus_request_name() is blocking.
>
>     Shall I really wait for these callbacks? The documentation states
>     "callbacks will be invoked after calling this function" - does it
>     mean immediately after calling this function?
>
>
> No, of course not. They're called from the main loop when the response 
> from the D-Bus daemon comes in.
>
>     What I still don't have my main loop started and the decision if
>     to start it depends on result of this method?
>
>     For me the simple and clean solution would be:
>     returns 0 - failure name already on use
>     returns > 0 - OK success name acquired
>
>
> The way g_bus_own_name() is designed, is that it _explicitly_ requires 
> the use of a main-loop. Why? Because the philosophy is that sync, 
> blocking APIs - such as dbus_bus_request_name() - are bad. By only 
> providing an async API, it's harder for programmers to screw up and 
> write bad programs that block indefinitely ... or at least, up to 25 
> seconds which is timeout used in this case.
>
> It's not a big deal. You really just move the everything but 
> g_main_loop() out of main() and into on_name_acquired(). That's it. 
> It's cleaner that way.
>
> If you don't like this - but you really should - you can always use 
> g_dbus_connection_call_sync() and invoke the RequstName() method yourself.
>
>     David
>


-- 

*Bogdan Lotko*

b.lotko at chello.at
Phone: +43 1 2852458
Mobile: +43 676 6615012
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20130730/26fe612c/attachment-0001.html>


More information about the dbus mailing list