[vala] D-Bus: Unregister path on object destruction



commit 7e43af186264fb92994c363a31dcd03b89e25b6d
Author: Sebastian Pölsterl <sebp k-d-w org>
Date:   Sun Mar 29 08:50:22 2009 +0200

    D-Bus: Unregister path on object destruction
    
    Fixes bug 576874.
---
 gobject/valaccodebasemodule.vala  |   31 +++++++++++++++++++++++++++++++
 gobject/valadbusservermodule.vala |    6 ++++++
 2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala
index 822c841..0b05134 100644
--- a/gobject/valaccodebasemodule.vala
+++ b/gobject/valaccodebasemodule.vala
@@ -444,6 +444,37 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 			block.add_statement (new CCodeIfStatement (new CCodeIdentifier ("vtable"), ifblock, elseblock));
 
 			source_type_member_definition.append (cfunc);
+
+			// unregister function
+			cfunc = new CCodeFunction ("_vala_dbus_unregister_object", "void");
+			cfunc.add_parameter (new CCodeFormalParameter ("connection", "gpointer"));
+			cfunc.add_parameter (new CCodeFormalParameter ("object", "GObject*"));
+
+			cfunc.modifiers |= CCodeModifiers.STATIC;
+			source_declarations.add_type_member_declaration (cfunc.copy ());
+
+			block = new CCodeBlock ();
+			cfunc.block = block;
+
+			cdecl = new CCodeDeclaration ("char*");
+			cdecl.add_declarator (new CCodeVariableDeclarator ("path"));
+			block.add_statement (cdecl);
+
+			var path = new CCodeFunctionCall (new CCodeIdentifier ("g_object_steal_data"));
+			path.add_argument (new CCodeCastExpression (new CCodeIdentifier ("object"), "GObject*"));
+			path.add_argument (new CCodeConstant ("\"dbus_object_path\""));
+			block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("path"), path)));
+
+			var unregister_call = new CCodeFunctionCall (new CCodeIdentifier ("dbus_connection_unregister_object_path"));
+			unregister_call.add_argument (new CCodeIdentifier ("connection"));
+			unregister_call.add_argument (new CCodeIdentifier ("path"));
+			block.add_statement (new CCodeExpressionStatement (unregister_call));
+
+			var path_free = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
+			path_free.add_argument (new CCodeIdentifier ("path"));
+			block.add_statement (new CCodeExpressionStatement (path_free));
+
+			source_type_member_definition.append (cfunc);
 		}
 
 		CCodeComment comment = null;
diff --git a/gobject/valadbusservermodule.vala b/gobject/valadbusservermodule.vala
index d13e8e1..26d032b 100644
--- a/gobject/valadbusservermodule.vala
+++ b/gobject/valadbusservermodule.vala
@@ -359,6 +359,12 @@ internal class Vala.DBusServerModule : DBusClientModule {
 		cregister.add_argument (new CCodeIdentifier ("object"));
 		register_block.add_statement (new CCodeExpressionStatement (cregister));
 
+		var weak_unregister = new CCodeFunctionCall (new CCodeIdentifier ("g_object_weak_ref"));
+		weak_unregister.add_argument (new CCodeIdentifier ("object"));
+		weak_unregister.add_argument (new CCodeIdentifier ("_vala_dbus_unregister_object"));
+		weak_unregister.add_argument (new CCodeIdentifier ("connection"));
+		register_block.add_statement (new CCodeExpressionStatement (weak_unregister));
+
 		block.add_statement (new CCodeIfStatement (register_check, register_block));
 
 		handle_signals (object_type.type_symbol, block);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]