Problem with dbus_connection_try_register_object_path

dibo20 at wp.pl dibo20 at wp.pl
Mon Jan 17 03:00:25 PST 2011


Hi,

I'm writting dbus plugin for Pidgin instant messenger. I'm using Free 
Pascal for that. Free Pascal have low level API for dbus. But I have 
some strange problem.
If I use simple loop checking for signals then it works. But I can't use 
standard loop, because my application have GUI and I can't block user 
interface. So I found some "callback" functions in dbus like 
"dbus_connection_try_register_object_path" (VTable -> message_function) 
or "dbus_connection_set_wakeup_main_function" which should notify me 
when new signals are created by dbus.
Problem is that this working only on my computer (ubuntu 10.10 64 bit). 
When I send executable to my friend which have exactly this same OS (and 
this same laptop) then it doesn't work. "message_function" is never 
called. This same problem when I copy source to my 32 bit ubuntu 10.10 
and compile and run. "dbus_connection_try_register_object_path" return 
TRUE and no erorrs is set, but "message_function" is never called. All 
computers have this same version of libdbus and Pidgin. What block this 
on others computers? Firewall? Some librarys is missing? This is dbus 
header translated to Free Pascal:

function dbus_connection_try_register_object_path(connection: 
PDBusConnection;
   path: PChar; vtable: PDBusObjectPathVTable; user_data: Pointer;
   error: PDBusError): dbus_bool_t; cdecl; external LibDBus;

"LibDBus" is constant:

const
{$ifdef unix}
   LibDBus = 'libdbus-1';
{$endif}
{$ifdef windows}
   LibDBus = 'libdbus.dll';
{$endif}

And this is my code:

var
VTable: DBusObjectPathVTable;


function MessageHandler(connection: PDBusConnection; message_: PDBusMessage;
user_data: Pointer): DBusHandlerResult; cdecl;
begin
MemoLog.Lines.Add('New signal');

Result := DBUS_HANDLER_RESULT_HANDLED;
end;

function BusConnect: Boolean;
begin
Result := False;
dbus_error_init(@err);
MemoLog.Lines.Add('Listening for signals');
{ Connection }
conn := dbus_bus_get(DBUS_BUS_SESSION, @err);

if dbus_error_is_set(@err)<>  0 then
begin
WriteLn('Connection Error: ' + err.message);
dbus_error_free(@err);
Exit;
end;

{ Request the name of the bus }
ret := dbus_bus_request_name(conn, 'im.pidgin.purple.PurpleInterface',
DBUS_NAME_FLAG_REPLACE_EXISTING, @err);

if dbus_error_is_set(@err)<>  0 then
begin
MemoLog.Lines.Add('Name Error: ' + err.message);
dbus_error_free(@err);
Exit;
end;

// add a rule for which messages we want to see
dbus_bus_add_match(conn,
'type=''signal'',interface=''im.pidgin.purple.PurpleInterface''', @err);
// see signals from the given interface
dbus_connection_flush(conn);
if (dbus_error_is_set(@err)<>  0) then
begin
MemoLog.Lines.Add('Match Error (' + err.message + ')');
Exit;
end;
MemoLog.Lines.Add('Match rule sent');

VTable.message_function := @MessageHandler;
if dbus_connection_try_register_object_path(conn,
'/im/pidgin/purple/PurpleObject', @VTable, nil, @err)=0 then
MemoLog.Lines.Add('Cant register');
if (dbus_error_is_set(@err)<>  0) then
begin
MemoLog.Lines.Add('Error in register (' + err.message + ')');
Exit;
end;

Result := True;
end;


Regards.


More information about the dbus mailing list