0

Short: Is there any way that I execute a code when a callback that connected using connect disconnected?

Long: I have a class with multiple callbacks that are expensive and I want to only generate callbacks for those that interested by user:

boost::signals2::connection bind_to_signal(signal_code code, signal_signature const& fn)
{
    start_callback(code);
    return signal_[code].connect(fn);
}

Now I want to execute stop_callback when all callbacks that bound to a signal disconnected.

BigBoss
  • 6,904
  • 2
  • 23
  • 38
  • Not only that you can't know when a slot disconnects, `signal` itself might not know that - until it attempts to invoke the slot. – Igor R. Feb 09 '13 at 12:00
  • ...by the way, your "long" description is unclear: if there are no connected slots, what is so expensive in "empty" signal invocation? – Igor R. Feb 09 '13 at 12:02
  • @IgorR. Invocation is not expensive, monitoring the original object that generate events is expensive! so I want to disable that monitoring. – BigBoss Feb 09 '13 at 12:09
  • I see. Then I'm afraid you've got only one way to go: provide your own `register`/`unregister` interface and fully hide `signal` as implementation detail (don't return `connection`, accept `function` as a callback but not `slot_type` - to prevent any possibility of disconnection other than through your `unregister` function). – Igor R. Feb 09 '13 at 12:17
  • @IgorR. thanks a lot, I am already doing this but I seek a way to accomplish with less code! and a cleaner design. If you want write it as an answer then I may accept it if no good answer received! – BigBoss Feb 09 '13 at 12:31

0 Answers0