]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
GDBus: Make sure signals are disconnected when unregistering an object
authorMichal Hruby <michal.mhr@gmail.com>
Wed, 3 Aug 2011 11:41:11 +0000 (13:41 +0200)
committerMichal Hruby <michal.mhr@gmail.com>
Wed, 3 Aug 2011 11:41:11 +0000 (13:41 +0200)
codegen/valagdbusservermodule.vala

index b29b91312c28023c95f6e0f32f3071d667dfe17c..c92a44474f397ce1c321c049086bf396df304658 100644 (file)
@@ -585,7 +585,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                return wrapper_name;
        }
 
-       void handle_signals (ObjectTypeSymbol sym) {
+       void handle_signals (ObjectTypeSymbol sym, bool connect) {
                string dbus_iface_name = get_dbus_name (sym);
                if (dbus_iface_name == null) {
                        return;
@@ -599,12 +599,21 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                                continue;
                        }
 
-                       var connect = new CCodeFunctionCall (new CCodeIdentifier ("g_signal_connect"));
-                       connect.add_argument (new CCodeIdentifier ("object"));
-                       connect.add_argument (get_signal_canonical_constant (sig));
-                       connect.add_argument (new CCodeCastExpression (new CCodeIdentifier (generate_dbus_signal_wrapper (sig, sym, dbus_iface_name)), "GCallback"));
-                       connect.add_argument (new CCodeIdentifier ("data"));
-                       ccode.add_expression (connect);
+                       if (connect) {
+                               var connect_call = new CCodeFunctionCall (new CCodeIdentifier ("g_signal_connect"));
+                               connect_call.add_argument (new CCodeIdentifier ("object"));
+                               connect_call.add_argument (get_signal_canonical_constant (sig));
+                               connect_call.add_argument (new CCodeCastExpression (new CCodeIdentifier (generate_dbus_signal_wrapper (sig, sym, dbus_iface_name)), "GCallback"));
+                               connect_call.add_argument (new CCodeIdentifier ("data"));
+                               ccode.add_expression (connect_call);
+                       } else {
+                               // disconnect the signals
+                               var disconnect_call = new CCodeFunctionCall (new CCodeIdentifier ("g_signal_handlers_disconnect_by_func"));
+                               disconnect_call.add_argument (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0")));
+                               disconnect_call.add_argument (new CCodeIdentifier ("_dbus_%s_%s".printf (get_ccode_lower_case_name (sym), get_ccode_name (sig))));
+                               disconnect_call.add_argument (new CCodeIdentifier ("data"));
+                               ccode.add_expression (disconnect_call);
+                       }
                }
        }
 
@@ -1261,7 +1270,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                ccode.add_return (new CCodeConstant ("0"));
                ccode.close ();
 
-               handle_signals (sym);
+               handle_signals (sym, true);
 
                ccode.add_return (new CCodeIdentifier ("result"));
 
@@ -1277,6 +1286,8 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
                ccode.add_declaration ("gpointer*", new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
 
+               handle_signals (sym, false);
+
                var unref_object = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_unref_function (sym)));
                unref_object.add_argument (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0")));
                ccode.add_expression (unref_object);