After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 537146 - No way to disconnect dynamic GObject signals
No way to disconnect dynamic GObject signals
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.3.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-06-07 17:37 UTC by Jaap A. Haitsma
Modified: 2010-01-16 19:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
return gulong from signal.connect() (640 bytes, patch)
2010-01-15 22:44 UTC, Luca Bruno
none Details | Review

Description Jaap A. Haitsma 2008-06-07 17:37: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) {
Comment 1 Jürg Billeter 2008-06-09 21:44:44 UTC
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 ();
        }       
}
Comment 2 Jaap A. Haitsma 2008-06-11 05:56:19 UTC
Thanks Jürg,

One more question. How do I disconnect the hand_off signal? I need that in the on_photo callback.
Comment 3 Jürg Billeter 2008-06-11 16:01:18 UTC
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.
Comment 4 Jaap A. Haitsma 2008-06-11 21:54:50 UTC
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;


Comment 5 Jaap A. Haitsma 2008-06-15 19:33:24 UTC
Changing the description of this bug to: 'No way to disconnect signals that have been connected with  "+="'

and reopening
Comment 6 Jürg Billeter 2008-06-15 21:18:55 UTC
Confirming.
Comment 7 Luca Bruno 2010-01-15 22:44:49 UTC
Created attachment 151504 [details] [review]
return gulong from signal.connect()

This patch allows to get signal id from .connect().
Comment 8 Jürg Billeter 2010-01-16 19:13:52 UTC
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.