[patch] add owner-changed signal to DBusGProxy

Colin Walters walters at verbum.org
Wed Jul 20 09:42:24 EST 2005


On Wed, 2005-07-13 at 13:42 -0400, Colin Walters wrote:
> Hi,
> 
> It seems people want to monitor when a service appears/disappears; I
> think it makes a lot of sense to have a signal on a name proxy instead
> of having people manually creating a proxy for the bus and watching
> NameOwnerChanged.

I realized later while trying to use this patch that it feels kind of
silly to create a name proxy for a service only to create a name owner
proxy in its "created" callback.

Maybe a better API would be to have a special proxy type for a bus,
e.g.:

{
  DBusGBus *bus = dbus_g_bus_get_proxy (DBUS_BUS_SESSION);
  MyApp *app = ...;

  g_signal_connect_object (bus, "name-owned", G_CALLBACK (my_create_proxy_cb), app, 0);
  ...
}

static void
my_create_proxy_cb (DBusGBus *bus, const char *name, gpointer data) 
{
  MyApp *app = data;

  if (!strcmp ("org.freedesktop.NetworkManagerInfo", name)) { 
    GError *error = NULL;

    app->nmi = dbus_g_proxy_new_for_name_owner (bus, name, "/org/freedesktop/NetworkManager", name, &error);
    if (!app->nmi) {
      ...
    }
    app->state = APP_STATE_AWAITING_INFO;
  }  
}

This would require creating a new object class DBusGBus; also note I'm
passing that to dbus_g_proxy_new_for_name_owner which assumes
DBusGConnection; maybe we make DBusGConnection a class and make DBusGBus
a subclass of it?  I guess we'd have to do a cast like 
DBUS_G_CONNECTION (bus) in the call above, but oh well.

This wouldn't involve an API/ABI change AFAICS, since DBusGConnection
was opaque before.

Or then again, maybe it's just not so bad to have a name proxy and
create a name owner proxy from it.

Thoughts?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/dbus/attachments/20050719/c5ecaccc/attachment.pgp


More information about the dbus mailing list