Detecting connection to service

John (J5) Palmieri johnp at redhat.com
Fri Jun 9 10:12:41 PDT 2006


On Fri, 2006-06-09 at 20:51 +0400, Roman I Khimov wrote:
> Hi.
> 
> I'm trying to make a D-Bus service and recently have stumbled upon a 
> problem, I need to be able to detect when objects connect to my service and 
> perfrom some action on that event. From what can be found in D-Bus tutorial 
> and other places on the net there is a "Disconnect" signal in D-Bus 
> specification, but no symmetric "Connect" signal.
> 
> Is there any other possible way to detect incoming connection to a service?

You don't connect to a service, you connect and disconnect to a bus.
Disconnect only gets sent to the service which disconnects.  The bus
handles connections so there is no corresponding signal.  You can listen
to NameOwnerChanged.

So the question is how do I detect incoming connections to a service?
Well when you get a message you've got an incoming connection.  What I
suspect you want to do is create a lookup table and populate it with
unique names from the clients that send messages to you.  You then want
to listen for NameOwnerChanged on the unique names in your lookup (if
the name is already in the table you don't want to add another
listener).  When you handle a NameOwnerChanged signal and the name drops
off the bus (new_name == NULL) you want to take it out of your lookup
table.

-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list