summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2005-05-03 17:45:30 +0000
committerColin Walters <walters@verbum.org>2005-05-03 17:45:30 +0000
commit18ada3395f7498e9028acdb061624c3743f51cf6 (patch)
treee3afe1a99a21ffb0c9122e5ce9cbbbb57898f3f5
parentac3b8d0a70f5fee2595ac37182354986f657d333 (diff)
2005-05-03 Ross Burton <ross@burtonini.com>
* glib/dbus-gobject.c (dbus_g_connection_register_g_object): Return if we get an error during registration. Set up a weak reference on object to unregister if object is destroyed. (unregister_gobject): New function.
-rw-r--r--ChangeLog7
-rw-r--r--glib/dbus-gobject.c18
2 files changed, 21 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 8d044389..e903e1bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-05-03 Ross Burton <ross@burtonini.com>
+
+ * glib/dbus-gobject.c (dbus_g_connection_register_g_object):
+ Return if we get an error during registration. Set up a
+ weak reference on object to unregister if object is destroyed.
+ (unregister_gobject): New function.
+
2005-05-01 John (J5) Palmieri <johnp@redhat.com>
* python/dbus_bindings.pyx.in:
diff --git a/glib/dbus-gobject.c b/glib/dbus-gobject.c
index 7ab4dd1b..09fc97fc 100644
--- a/glib/dbus-gobject.c
+++ b/glib/dbus-gobject.c
@@ -1048,6 +1048,15 @@ dbus_g_object_class_install_info (GObjectClass *object_class,
g_static_rw_lock_writer_unlock (&info_hash_lock);
}
+static void
+unregister_gobject (DBusGConnection *connection, GObject *dead)
+{
+ char *path;
+ path = g_object_steal_data (dead, "dbus_glib_object_path");
+ dbus_connection_unregister_object_path (DBUS_CONNECTION_FROM_G_CONNECTION (connection), path);
+ g_free (path);
+}
+
/**
* Registers a GObject at the given path. Properties, methods, and signals
* of the object can then be accessed remotely. Methods are only available
@@ -1073,12 +1082,13 @@ dbus_g_connection_register_g_object (DBusGConnection *connection,
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)
- */
+ g_object_set_data (object, "dbus_glib_object_path", g_strdup (at_path));
+ g_object_weak_ref (object, (GWeakNotify)unregister_gobject, connection);
}
/** @} */ /* end of public API */