[fpc-pascal] D-Bus. Non blocking listening for signals
dibo20 at wp.pl
dibo20 at wp.pl
Sun Jan 2 22:23:08 CET 2011
W dniu 02.01.2011 21:36, Henry Vermaak pisze:
> On 2 January 2011 19:42,<dibo20 at wp.pl> wrote:
>>> You may already know this, but it may help to point out that the
>>> OnIdle event won't fire if there are no other events. For example,
>>> you'll have to move your mouse or hit the keyboard for the OnIdle
>>> event to be called. I don't know if this will affect talking to dbus
>>> (does it queue up the signals?).
>>>
>>> Henry
>> Yes, but I noticed that when there are no events, OnIdle is fired even so
>> (at 5 seconds cycle). I thought it was enough to catch signal, but maybe
>> it's too long and signals may have short live. C example uses glib main loop
>> to check signals. I see that free pascal have some glib librarys. Can I
>> somehow use it (I do not know what it is)? I need this solution only for
>> linux
> 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);
But I declared my own procedure where I call checking for signals:
procedure TestTest(data: Pointer); cdecl;
begin
Form1.CheckForMessage;
end;
dbus_connection_set_wakeup_main_function(conn, @TestTest, nil, nil);
And it works perfect! :) . Thanks again.
BTW: About your suggestion to use threads. I used threads before and it
worked very long on my application. But it stopped after upgrade d-bus
interface. That is why I post this problem
Regards.
More information about the fpc-pascal
mailing list