I'm messing around in the editor code. What I'm trying to do is something like this:
- Class A implements a signal "some_signal_called".
- Class B and C connect to the signal.
- Class A uses get_signal_connection_list("some_signal_called", &conn_list).
- It then iterates through the connections in a loop and invokes their Callables one by one, sequentially and synchronously.
- It gets some info back whether each callable successfully handled the signal or not.
- If the signal has been successfully handled, it exits the loop. It doesn't need to invoke any more Callables.
- If the signal has not been successfully handled by the end of the loop, some fallback code is used.
There might of course be a bunch of problems with this implementation.
- Signals are not intended to be invoked in this manner. Invoking the callable directly bypasses a ton of important code in Object::emit_signalp. I'm not even sure it would work.
- There is no reliable order for B and C to be called, and so there can be no priority of responsibility.
- Obviously signals don't return anything. I would need to pass a reference to an object with a flag for B or C to set if they have handled the signal. This would get messy.
Is there a better idea than this? Is there a better approach for the chain of responsibility pattern somewhere already in the engine? I would like to keep the kind of decoupling which signals provide, if possible. I'd also like to avoid adding a ton of boilerplate just to get this pattern to work.
Thanks!