[fpc-pascal] D-Bus. Non blocking listening for signals

Henry Vermaak henry.vermaak at gmail.com
Sun Jan 2 22:42:31 CET 2011


On 2 January 2011 21:23,  <dibo20 at wp.pl> wrote:
>> I had a quick look at the dbus functions.  Perhaps you can use
>> dbus_connection_set_wakeup_main_function to set up a function that
>> wakes up your main loop (containing something like:
>> g_main_context_wakeup(g_main_context_default) for gtk+).  This will
>> fire the OnIdle event where you can read the message.
>>
>> Another solution can be to launch a thread that executes a loop of
>> dbus reads.  You can then communicate back to the main thread.
>>
>> Henry
>
> Wow, thanks! I read few examples in different programing languages, but
> nowhere was no mention of this procedure. Although this example doesn't work
> (or I am doing something wrong):
> dbus_connection_set_wakeup_main_function(conn, @g_main_context_wakeup,
> g_main_context_default, nil);

No, I meant almost like you did below.

> But I declared my own procedure where I call checking for signals:
>
> procedure TestTest(data: Pointer); cdecl;
> begin
>  Form1.CheckForMessage;

Here I would use Application.QueueAsyncCall to queue a method to check
for messages, then g_main_context_wakeup(g_main_context_default),
which is asynchronous, so you don't block your dbus callback.  This
may not be a problem.

The way you've done it is probably OK!

Henry



More information about the fpc-pascal mailing list