Using D-BUS with GLib and no dbus-daemon

James Kent James.Kent at palmsource.com
Wed Feb 15 08:12:31 PST 2006


Thanks for the quick response.  I'm already calling dbus_server_setup_with_g_main, after which I'm able to create a DBusConnection and pass simple messages back and forth between my server process and a client process.

Here's the relevant part of my server process code that hopefully points out the problem better:

int 
main (int argc, char **argv)
{
  DBusServer* dbusServer;
  DBusConnection* bus;
  GError *error = NULL;
  GMainLoop *mainloop;

  g_type_init();

  mainloop = g_main_loop_new (NULL, FALSE);

  dbusServer = dbus_server_listen("unix:path=/tmp/a1b2c3", &error);
  dbus_server_setup_with_g_main(dbusServer, g_main_loop_get_context(mainloop));

  bus = dbus_connection_open("unix:path=/tmp/a1b2c3");

  // at this point I have a DBusConnection*, I'd like to call dbus_g_proxy_new_for_peer
  // but that requires a DBusGConnection*.  There's a macro DBUS_G_CONNECTION_FROM_CONNECTION
  // in glib/dbus-gutils.h, but its not part of the installed headers.

  ...
}

The problem is that in order to use the GLib Binding to handle communication with GObject's, I think I need to create a DBusGProxy*.  The call to do this I should call dbus_g_proxy_new_from_peer, but this requires a DBusGConnection*, not a DBusConnection*.  

In the installed headers, there's a function dbus_connection_from_g_connection() that wraps a call to the DBUS_CONNECTION_FROM_G_CONNECTION macro, but there's no corresponding dbus_g_connection_from_connection() call to go the other way.

It appears that there may be a hole in the exposed GLib binding APIs, or else I'm just missing something.

Jim

-----Original Message-----
From: John (J5) Palmieri [mailto:johnp at redhat.com]
Sent: Wed 2/15/2006 7:46 AM
To: James Kent
Cc: dbus at lists.freedesktop.org
Subject: Re: Using D-BUS with GLib and no dbus-daemon
 
A little further investigation reveals dbus_server_setup_with_g_main 

http://dbus.freedesktop.org/doc/api/html/group__DBusGLib.html#gfba6f40a9b45c60dabdc99e64f14c8b6

It is used in conjunction with a DBusServer which will allow you to
handle connection like you are a bus.

http://dbus.freedesktop.org/doc/api/html/group__DBusServer.html

Looks pretty straight forward.  You create a server and have it listen
on a socket and have the client open up a connection to that socket.
How the client finds out about the socket (whether it is well known or
you use the session bus to pass that information) is up to you.  I think
after that everything else is the same as if you were talking to one of
the standard busses. 

On Wed, 2006-02-15 at 10:32 -0500, John (J5) Palmieri wrote:
> I remember Colin telling me he had added support to the glib bindings to
> get a server connection (i.e. act as a standalone server).  I'm not
> totally sure how to do that and I am pretty sure there is no example
> code.  Not sure if that helps but perhaps it can direct you to a
> solution.
> 
> On Wed, 2006-02-15 at 07:16 -0800, James Kent wrote:
> > First, an introduction.  My name is Jim Kent.  I work for PalmSource and have been investigating various IPC technologies to use as part of an application framework we're developing.
> > 
> > One thing I've been investigating is using D-BUS with GLib for peer-to-peer communication between processes (i.e. with no dbus-daemon).
> > 
> > I've got code working that sets up the server and client connections using the D-BUS low-level public API calls.  In other words, each process has a DBusConnection*.  The problem I'm having is that in order to call dbus_g_proxy_new_for_peer, I need a DBusGConnection*, not a DBusConnection*.  I've poked around in the source and found the macro DBUS_CONNECTION_TO_G_CONNECTION that does this, so I can make this work, but the macro is not exposed in the installed headers, so its obviously not expected to be used to do this.
> > 
> > Is there some API I've missed that allows me to get a DBusGConnection* for my peer to peer client and server?
> > 
> > If someone has the D-BUS/GLib statemachine sample code modified to work with direct connections between the client and server, that would be ideal.  If not, any help is appreciated.
> > 
> > Thanks
> > Jim Kent
> > james.kent at palmsource.com
> > _______________________________________________
> > dbus mailing list
> > dbus at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/dbus

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




More information about the dbus mailing list