Peer to peer D-BUS / gLib

James Kent James.Kent at palmsource.com
Mon Feb 20 13:57:02 PST 2006


 

> -----Original Message-----
> From: John (J5) Palmieri [mailto:johnp at redhat.com] 
> Sent: Monday, February 20, 2006 2:24 PM
> To: James Kent
> Cc: dbus at lists.freedesktop.org
> Subject: Re: Peer to peer D-BUS / gLib
> 
> On Mon, 2006-02-20 at 14:17 -0500, John (J5) Palmieri wrote:
> 
> > 
> > > Second, I still had to use the internal macro 
> DBUS_G_CONNECTION_FROM_CONNECTION in one place, in the server 
> process's connection handler.  I'd like to suggest that the 
> signature of the function dbus_connection_setup_with_g_main 
> be changed from:
> > > 
> > > void            dbus_connection_setup_with_g_main 
> (DBusConnection  *connection,
> > >                                                    
> GMainContext    *context);
> > > 
> > > to:
> > > 
> > > DBusGConnection* dbus_connection_setup_with_g_main 
> (DBusConnection  *connection,
> > >                                                    
> GMainContext    *context);
> > > 
> > > That would have allowed me to access the DBusGConnection 
> pointer I needed.
> > > 
> > > If you would like to include the modified sample using 
> peer-to-peer direct connections in the glib/examples 
> distribution, let me know.
> > > 
> > 
> > You don't need to call dbus_connection_setup_with_g_main as it is 
> > called via dbus_g_bus_get and dbus_g_connection_open.

The problem I was having was that I'm using a DBusServer in my server
process's main() and register a connection handling callback so that the
server knows when a client process wants to connect.  

Here's the connection handling function I'm using:

static void
p2pServer_handle_connection (DBusServer *server,
			  DBusConnection *new_connection,
			  void *data)
{
  DBusGConnection *new_g_connection = NULL;

  dbus_connection_ref (new_connection);

  dbus_connection_setup_with_g_main (new_connection, NULL);

  new_g_connection = DBUS_G_CONNECTION_FROM_CONNECTION(new_connection);

  // in order to do the registration with
dbus_g_connection_register_g_object, 
  // I need a DBusGConnection
  dbus_g_connection_register_g_object (new_g_connection,
				       "/SomeObject", 
				       G_OBJECT (obj));
}

And the relevant parts of main():

int
main (int argc, char **argv)
{
  DBusServer* p2pServer;

  ... (stuff omitted)

  // set up this process to be the peer to peer server
  p2pServer = dbus_server_listen("unix:path=/tmp/a1b2c3", error);

  dbus_server_setup_with_g_main(p2pServer, NULL);

  // setup a connection function to handle new connection attempts
  dbus_server_set_new_connection_function (p2pServer, 
					   p2pServer_handle_connection, 
					   NULL, 
					   NULL);
  ... (more stuff omitted)
}

The problem is that the connection handling callback gets a
DBusConnection*, but I need a DBusGConnection* to call
dbus_g_connection_register_g_object, so I've hacked in the macro
DBUG_G_CONNECTION_FROM_CONNECTION to make it work.

Maybe there's another to do this?  If not, then the connection handling
function needs a public API to get the DBusGConnection from the
DBusConnection.

Jim


More information about the dbus mailing list