Index: glib/dbus-gobject.c =================================================================== RCS file: /cvs/dbus/dbus/glib/dbus-gobject.c,v retrieving revision 1.21 diff -u -r1.21 dbus-gobject.c --- glib/dbus-gobject.c 27 Feb 2005 17:38:12 -0000 1.21 +++ glib/dbus-gobject.c 29 Apr 2005 16:20:44 -0000 @@ -1048,6 +1048,19 @@ g_static_rw_lock_writer_unlock (&info_hash_lock); } +typedef struct { + DBusConnection *connection; + char* path; +} ObjectDeathData; + +static void +unregister_gobject(ObjectDeathData* data, GObject *dead) +{ + dbus_connection_unregister_object_path (data->connection, data->path); + g_free (data->path); + g_free (data); +} + /** * Registers a GObject at the given path. Properties, methods, and signals * of the object can then be accessed remotely. Methods are only available @@ -1066,6 +1079,8 @@ const char *at_path, GObject *object) { + ObjectDeathData *death; + g_return_if_fail (connection != NULL); g_return_if_fail (at_path != NULL); g_return_if_fail (G_IS_OBJECT (object)); @@ -1073,12 +1088,15 @@ if (!dbus_connection_register_object_path (DBUS_CONNECTION_FROM_G_CONNECTION (connection), at_path, &gobject_dbus_vtable, - object)) + object)) { g_error ("Failed to register GObject with DBusConnection"); + return; + } - /* FIXME set up memory management (so we break the - * registration if object or connection vanishes) - */ + death = g_new (ObjectDeathData, 1); + death->connection = DBUS_CONNECTION_FROM_G_CONNECTION (connection); + death->path = g_strdup (at_path); + g_object_weak_ref (object, (GWeakNotify)unregister_gobject, death); } /** @} */ /* end of public API */