Hi, if you want to use this, I'd suggest creating a class like this: class signal_blocker { public: signal_blocker(signal& s) : s(s) { s.block(); } ~signal_blocker() { s.unblock(); }
private: signal& s; };
This provides exception safety, just like the one you discovered in this cairo-related code: { signal_blocker s(whatever_signal); ... } // unblock is called automatically at the end of the scope
if you call block and unblock directly and an exception occurs in between these calls, unblock may never be called. This can lead to strange bugs. I don't know though whether it's good to use it or if there already is something like this in sigc++.
Regards, Markus
-----Ursprüngliche Nachricht----- Von: Martin Owens [mailto:doctormo@...400...] Gesendet: Sonntag, 9. März 2014 21:06 An: Inkscape Developer Mailing List Betreff: [Inkscape-devel] Blocking Signals
Hey Devs,
I was reviewing some of the ponyscape merge today and I noticed in the object's dialog Janeczko used signal.block() and signal.unblock() to deny signals and I suspect to prevent loops and such.
Is this a good pattern to use?
I've come across several places where looks are caused by update and refresh signals locking up. Everything from image.cpp's update to filters dialog reorder signal. And what I found interesting was how sp-use deals with this problem. It puts update signals on a glib callback and has a mass of code for preventing the problems that sp-image.cpp gets into a lot.
I'd love to hear from those more experienced with C++, GLib and signals about the best pattern to use.
Best Regards, Martin Owens
---------------------------------------------------------------------------- -- Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce. With Perforce, you get hassle-free workflows. Merge that actually works. Faster operations. Version large binaries. Built-in WAN optimization and the freedom to use Git, Perforce or both. Make the move to Perforce. http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.cl... _______________________________________________ Inkscape-devel mailing list Inkscape-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/inkscape-devel