[fpc-pascal] DBus in GUI application

Luca Olivetti luca at wetron.es
Sat Apr 5 15:35:01 CEST 2014


El 04/04/14 17:46, Krzysztof ha escrit:
> Hi,
> 
> DBus documentation give me a headache. Does anyone know solution how
> to implement DBus in GUI main loop (for signals listening)? I have
> tried with threads but have two problems:
> 1. Not all signals are catched (randomly)
> 2. Deadlock when main thread trying to use dbus methods

Last time (and the only time) I wrote a dbus server was 5 years ago (so
I used the plain translation of the C api and a now obsolete version of
dbus), but it was a daemon (not a gui program) with more or less this
structure:


while not terminated do
begin
   DbusCycle;
   { do other things }
end;

and DbusCycle was managing a non-blocking dbus connection like this:

begin
  //non blocking read of the next available message
  if conn<>nil then
  begin
    if dbus_connection_get_is_connected(conn)=0 then
    begin
       Logger.Error('perdida conexion con bus');
       conn:=nil;
    end;
  end;
  if conn=nil then ConnectToSystembus;
  if conn=nil then exit;
  dbus_connection_read_write(conn,0);
  msg:=dbus_connection_pop_message(conn);
  if msg=nil then exit;

  lastfailed:=false;

  // check this is a method call for the right interface & method
  if (dbus_message_is_method_call(msg,
'es.wetron.almacen_tapas.method.Status', 'GetStatus') <> 0) then
     reply_to_getstatus_call else
  if (dbus_message_is_method_call(msg,
'es.wetron.almacen_tapas.method.Status', 'GetFifo') <> 0) then
     reply_to_getfifo_call else
  if (dbus_message_is_method_call(msg,
'es.wetron.almacen_tapas.method.Simulation', 'Simulate') <> 0) then
     reply_to_simulate_call;
  // free the message
  dbus_message_unref(msg);
end;


not much help, I know, but it worked (btw: since I also controlled the
client, in hindsight it was a stupid decision: I could have used
something more cross-platform like a socket).

Bye


-- 
Luca Olivetti
Wetron Automation Technology http://www.wetron.es
Tel. +34 935883004  Fax +34 935883007



More information about the fpc-pascal mailing list