Synchronous method in asynchronous signal callback
Marco Bascetta
marco.bascetta at sadel.it
Thu May 14 08:16:05 PDT 2015
Hello,
I'm using libdbus with a poll mainloop. I monitor the DBusWatch file
descriptor to call "dbus_watch_handle" and "dbus_connection_dispatch".
Also, I add a connection filter to handle asynchronous signals (only
DBUS_MESSAGE_TYPE_SIGNAL messages).
When an event occurs, a callback is called and a specified method is
performed throught "dbus_connection_send_with_reply_and_block" and a
flag is set in order to indicates that the dispatch function must run
another time.
This is an example of the code
[pseudocode]
init_func()
{
dbus_threads_init_default()
conn = dbus_bus_get(...)
dbus_connection_set_watch_functions(conn, ...) # This
store watch_fd in poll
dbus_connection_add_filter(conn, filter_func, ...)
}
invoke_method()
{
dbus_connection_send_with_reply_and_block(conn, ...)
use_reply()
flag_set(force_dispatch)
}
filter_func()
{
if( dbus_message_get_type(...) == DBUS_MESSAGE_TYPE_SIGNAL ) {
if( is(signal_A) ) {
invoke_method()
} else {
do_other_things()
}
}
}
# This is called when watch_fd
dispach_func()
{
do {
flag_unset(force_dispatch)
dbus_watch_handle(dbus_watch,
dbus_watch_get_flags(dbus_watch));
while (dbus_connection_get_dispatch_status(conn) ==
DBUS_DISPATCH_DATA_REMAINS) {
dbus_connection_dispatch(conn);
}
} while( flag_is_set(force_dispatch) );
}
[pseudocode]
It works without deadlock or message missing, but the signals received
during the "invoke_method" are delayed until another signal is received
(watch fd unlocks the poll) (and this could occurs much later...)
Could you suggest me how to resolve this issue without using the
asynchronous calls only?
Thanks
Best regards
--
Marco Bascetta - Sadel SpA
Software Development
Via Serenari 1, Castel Maggiore (BO)
More information about the dbus
mailing list