Object path values - which service do they belong to?

Ross Burton ross at burtonini.com
Wed May 18 10:09:45 PDT 2005

On Wed, 2005-05-18 at 11:20 -0400, Havoc Pennington wrote:
> > What I'm doing in the GLib bindings now is mapping it on the client end
> > to DBUS_TYPE_G_PROXY, and on the server end mapping it to G_TYPE_OBJECT.
> > This feels pretty natural I think, but it is based on the assumption
> > that an object path always refers to an object on the same service as
> > the method.
> I feel like you might be making the glib bindings too "thick," but I
> haven't looked at the details enough to convert that into a constructive
> comment about where I would put the balance... it's just a vague
> feeling.

Colin pointed out that as I'm using the object path bindings in an
application, I should say something here.

I have a factory object which is at a known location on the bus and
implements the BookFactory interface.  The implementation of this with
the latest iteration of the bindings is really nice (most names shortend
to save space)

        impl_getBook(BookFactory *object, const char *IN_source, GObject **OUT_book, GError **error)
          char *path = make_path_name (IN_source);
          Book *book = g_hash_table_lookup (hash, path);
          if (book == NULL) {
            book = book_new (IN_source);
            g_hash_table_insert (hash, path, book);
            dbus_g_connection_register_g_object (connection, path, G_OBJECT (book));
            g_object_weak_ref (G_OBJECT (book), (GWeakNotify)my_remove, g_strdup (path));
          } else {
            g_object_ref (book);
          *OUT_book = g_object_ref (book);
          return TRUE;

The client has nice simple code thanks to the bindings too:

        BookFactory_get_book(factory_proxy, source, &proxy, &error);

(where factory_proxy has already been created obviously)

The only non-clean bit of this is that the returned proxy is based on
the proxy used to make the call, and in this example the interface is
BookFactory.  However, the returned object implements the Book interface
so I have to reset the interface:

        dbus_g_proxy_set_interface (proxy, "Book");

Eh voila, it all just works.  Personally I love the "thick" object path
API. :)

Ross Burton                                 mail: ross at burtonini.com
                                          jabber: ross at burtonini.com
                                     www: http://www.burtonini.com./
 PGP Fingerprint: 1A21 F5B0 D8D0 CFE3 81D4 E25A 2D09 E447 D0B4 33DF

More information about the dbus mailing list