Two way comms with dbus-glib

tim launchbury tim at tlaunchbury.ukfsn.org
Thu Apr 30 00:42:57 PDT 2009


Dear all

I am attempting to convert some software I have written to use dbus-glib
for
IPC. So far I have managed to get communications working in one
direction. but
not the other. I saw in a post from Havoc Pennington in the mailing list
that
there a programmes which work both as server and client, so I believe it
is
possible. Some details follow:

The setup is

1 programme acts as the dbus server initially. It can spawn up to 8
copies of another
programme, each of which acts as a dbus client initially.

This part works OK, with the clients talking to the server as expected.
However,
when I attemp to get them to change roles, they do not communicate in the
other
direction.

The pseudocode is as follows
Create objects containing the following

1) Server ( Program1 )

Get the connection with  dbus_g_bus_get ( DBUS_BUS_SESSION, &error )

Create a proxy with    dbus_g_proxy_new_for_name ( connection,
                                    DBUS_SERVICE_DBUS,
                                    DBUS_PATH_DBUS,
                                    DBUS_INTERFACE_DBUS );

Install the info  with        dbus_g_object_type_install_info
                              ( W_DBUS_TYPE, &object_info );


Register the created object with

      dbus_g_connection_register_g_object ( sdbus->priv->
                                            connection,
                                            "/com/me/myaddress/myprog1",
                                            G_OBJECT
                                            ( myobject ) );


Define methods.


2) Client ( Program2 )

Get the connection, as above

Create the  proxy with         dbus_g_proxy_new_for_name ( connection,
                                    "com.me.myaddress",
                                    "/com/me/myaddress/myprog1",
                                    "com.me.myaddress.myprog1" );



In an attempt to get comms working in the other direction, I created
objects in
the client and server where the above steps were swapped:


3) In Program2

Get the connection with  dbus_g_bus_get ( DBUS_BUS_SESSION, &error )

Create a proxy with    dbus_g_proxy_new_for_name ( connection,
                                    DBUS_SERVICE_DBUS,
                                    DBUS_PATH_DBUS,
                                    DBUS_INTERFACE_DBUS );

Install the info  with        dbus_g_object_type_install_info
                              ( W_DBUS_TYPE, &object_info );


Register the created object with

      dbus_g_connection_register_g_object ( sdbus->priv->
                                            connection,
                                            "/com/me/myaddress/myprog2",
                                            G_OBJECT
                                            ( myobject ) );


Define methods.

4)   In Program1

Get the connection, as above

Create the  proxy with         dbus_g_proxy_new_for_name ( connection,
                                    "com.me.myaddress",
                                    "/com/me/myaddress/myprog2",
                                    "com.me.myaddress.myprog2" );


These are done in the order above.


Then, when I try to send a message from Program1 to Program2 ( ie Program2
acting as the server ) using the proxy created in step 4), the request
times
out with a message that the method does not exist.

Using dbus-monitor, I can see that what is happening is that the message
from
Program1 is in fact being adressed by the dbus daemon to Program1, and
not as I
would expect, to Program2.

Does anybody have any suggestions as to what I am doing wrong?
Also, can you give me the names of some of the packages which use
bidirectional
dbus communications?


Regards

Tim


More information about the dbus mailing list