GNOME Bugzilla – Bug 537146
No way to disconnect dynamic GObject signals
Last modified: 2010-01-16 19:13:52 UTC
If you compile the program below --------------- using GLib, Gtk, Gst; public class GstVideo.App : Gtk.Window { Widget screen; construct { title = "Sample Window"; } public void start_pipeline () { var sink = ElementFactory.make ("fakesink", "sink"); Signal.connect (sink, "handoff", (GLib.Callback)on_photo_data, this); } void on_photo_data (Element element, Buffer buffer, Pad pad) { print ("on_photo_data\n"); } public static void main(string[] args) { Gtk.init (ref args); Gst.init (ref args); var app = new App (); app.start_pipeline (); Gtk.main (); } } ---------------- the on_photo_data is incorrect. It is connected to static void gst_video_app_on_photo_data (GstVideoApp* self, GstElement* element, GstBuffer* buffer, GstPad* pad) { while it should be connected to a function with the following prototyp static void gst_video_app_on_photo_data (GstElement* element, GstBuffer* buffer, GstPad* pad, GstVideoApp* self) {
If you explicitly cast delegates as in your example, it's impossible to guarantee that the method matches the delegate. If you want/need to use GLib.Signal.connect, you have to be very careful that the specified signal handler matches the signal, valac can't check this at compile-time. In your specific example, I'd recommend you to use dynamic signals, can you try something like the following: using GLib, Gtk, Gst; public class GstVideo.App : Gtk.Window { Widget screen; construct { title = "Sample Window"; } public void start_pipeline () { dynamic Element sink = ElementFactory.make ("fakesink", "sink"); sink.handoff += on_photo_data, this); } void on_photo_data (Element element, Buffer buffer, Pad pad) { print ("on_photo_data\n"); } public static void main(string[] args) { Gtk.init (ref args); Gst.init (ref args); var app = new App (); app.start_pipeline (); Gtk.main (); } }
Thanks Jürg, One more question. How do I disconnect the hand_off signal? I need that in the on_photo callback.
Use GLib.SignalHandler.disconnect to disconnect signal handlers. You can either store the signal handler id as returned by the connect method or use the GLib.SignalHandler.disconnect_matched method.
How do I get the "signal handler id" if I connect the signal like this? sink.handoff += on_photo_data; I've tried using GLib.SignalHandler.disconnect_matched and GLib.SignalHandler.disconnect_by_func but they don't work because for the func I put on_photo_data but the C code actually uses _gst_video_app_on_photo_data_dynamic_handoff0_ and not gst_video_on_photo_data as the signal handler BTW it would be nice to have support for disconnecting like this sink.handoff -= on_photo_data;
Changing the description of this bug to: 'No way to disconnect signals that have been connected with "+="' and reopening
Confirming.
Created attachment 151504 [details] [review] return gulong from signal.connect() This patch allows to get signal id from .connect().
commit 7ea3f6a40138c25cbf9c7296e59cbf008378877b Author: Luca Bruno <lethalman88@gmail.com> Date: Sat Jan 16 20:09:13 2010 +0100 Return handler id when connecting signal handlers Fixes bug 537146.