[clutter] script: Use a weak ref to remove the signal emission hook



commit d9c1a2ebbbf395aa4d255b2a31f17ce8d0e2377a
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Sun Jun 12 11:27:34 2011 +0100

    script: Use a weak ref to remove the signal emission hook
    
    When an object goes away we should remove the emission hook for the
    state transitions, to avoid leaving hooks around.

 clutter/clutter-script.c |   27 ++++++++++++++++++++++-----
 1 files changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/clutter/clutter-script.c b/clutter/clutter-script.c
index 65ec23e..97fa04d 100644
--- a/clutter/clutter-script.c
+++ b/clutter/clutter-script.c
@@ -948,6 +948,8 @@ typedef struct {
   ClutterState *state;
   GObject *emitter;
   gchar *target;
+  gulong signal_id;
+  gulong hook_id;
 } HookData;
 
 typedef struct {
@@ -986,6 +988,16 @@ clutter_script_state_change_hook (GSignalInvocationHint *ihint,
 }
 
 static void
+clutter_script_remove_state_change_hook (gpointer  user_data,
+                                         GObject  *object_p)
+{
+  HookData *hook_data = user_data;
+
+  g_signal_remove_emission_hook (hook_data->signal_id,
+                                 hook_data->hook_id);
+}
+
+static void
 connect_each_object (gpointer key,
                      gpointer value,
                      gpointer data)
@@ -1071,11 +1083,16 @@ connect_each_object (gpointer key,
           hook_data->emitter = object;
           hook_data->state = CLUTTER_STATE (state_object);
           hook_data->target = g_strdup (sinfo->target);
-
-          g_signal_add_emission_hook (signal_id, signal_quark,
-                                      clutter_script_state_change_hook,
-                                      hook_data,
-                                      hook_data_free);
+          hook_data->signal_id = signal_id;
+          hook_data->hook_id =
+            g_signal_add_emission_hook (signal_id, signal_quark,
+                                        clutter_script_state_change_hook,
+                                        hook_data,
+                                        hook_data_free);
+
+          g_object_weak_ref (hook_data->emitter,
+                             clutter_script_remove_state_change_hook,
+                             hook_data);
         }
 
       signal_info_free (sinfo);



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