the main loop

sfora dim sfora.dim at gmail.com
Mon Sep 15 10:40:25 PDT 2008


On Mon, Sep 15, 2008 at 1:41 PM, Thiago Macieira <thiago at kde.org> wrote:
>> I'm writing a dbus service in C using libdbus. What dbus function
>> should I call periodically in my main loop ?
>
> See the part of my email that you deleted:
>>>Applications wouldn't call dbus_connection_read_write(). They'd use the
>>>callbacks to handling socket and timer events, then the library calls
>>>some registered callbacks.

Can you please mention the names of these callbacks and library calls
that the main loop should use ? I will go and read them in the source
code to understand more how to build a healthy main loop.

I have compiled and tested the example in
http://dbus.freedesktop.org/doc/dbus/dbus-example.c.
This is its main loop - it periodically reads new messages using the
dbus_connection_read_write() function, and that's it. I can't see any
callbacks registering or other library calls. why isn't it good (i
have compiled and run it, and it seems to work and receive all the
messages I've sent it) ?

// loop, testing for new messages
   while (true) {
      // non blocking read of the next available message
      dbus_connection_read_write(conn, 0);
      msg = dbus_connection_pop_message(conn);

      // loop again if we haven't got a message
      if (NULL == msg) {
         sleep(1);
         continue;
      }

      // check this is a method call for the right interface & method
      if (dbus_message_is_method_call(msg, "test.method.Type", "Method"))
         reply_to_method_call(msg, conn);

      // free the message
      dbus_message_unref(msg);
   }

Thank you for the help !
Sfora


More information about the dbus mailing list