loop

Fritz Code codefritz at googlemail.com
Mon Jun 30 13:41:17 PDT 2008


Hi,

Im working on an application which doesnt use a main loop but the following
construct:


while (1) {
        dbus_connection_read_write(dbus_conn, 0);
        msg = dbus_connection_pop_message(dbus_conn);
        if (NULL == msg ) {
            //check if user wants to cancel the loop and if yes send the
Signal/Message "DiscoveryCompleted"


            usleep(300000);
            continue;
        }
        if (dbus_message_is_signal(msg, "org.bluez.Adapter",
"RemoteDeviceFound")) {
         //do something
        }

        else if (dbus_message_is_signal(msg, "org.bluez.Adapter",
"DiscoveryCompleted")){

         break; //cancel condition
        }
}

As you can see Im working with bluez libs. Anyway my question if this
construct is really safe.
Im afraid of an infinite loop.
The problem might be if the message/signal DiscoveryCompleted gets lost
Well I can check if the message DiscoveryCompleted could be sent probably,
but if it gets lost on the bus or the bus crashes then
this construct ends up in an infinite loop. How likely is this scenario of
an infinite loop?
Unfortunately using a simple variable as flag to cancel the loop is not
possible since I have to get rid of the message DiscoveryCompleted.
Because if this message gets not read and deleted from the bus a new session
gets canceled before it can even start.

Hope you got my problem

thanks



-- 
Regards,
--Codefritz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20080630/0c929b58/attachment.htm 


More information about the dbus mailing list