|
UCILoader 1.1.2
Small C++ library that allows user to connect to a chess engines via UCI protocol.
|
Base class for objects that emit engine events. More...
#include <EngineEvent.h>
Public Member Functions | |
| void | unlink (const EventReceiver *receiver) |
| Disconnect a specific receiver from future events. | |
| void | connect (std::shared_ptr< EventReceiver > receiver) |
| Connect a custom event receiver. | |
| void | connect (std::function< void(const EngineEvent *)> callback, uint32_t eventFilter) |
| Connect a callback function that receives the full event. | |
| void | connect (std::function< void()> callback, uint32_t eventFilter) |
| Connect a simple parameterless callback function. | |
Protected Member Functions | |
| virtual | ~EventEmitter () |
| Virtual destructor ensuring proper cleanup. | |
| void | emit (const EngineEvent *event) |
| Emit an event to all connected receivers. | |
Base class for objects that emit engine events.
EventEmitter manages a collection of EventReceiver instances and notifies them when events occur. Multiple receivers can be connected and will all be notified synchronously when an event is emitted.
Thread Safety: Emitter uses internal locking to protect receiver list during additions/removals. However, event delivery is synchronous - receivers are called from the thread that calls emit().
Usage Pattern:
| void UCILoader::EventEmitter::connect | ( | std::function< void()> | callback, |
| uint32_t | eventFilter | ||
| ) |
Connect a simple parameterless callback function.
| callback | Function invoked for each matching event (takes no parameters) |
| eventFilter | Bitmask of NamedEngineEvents constants indicating which events to trigger the callback |
Similar to the full event callback version, but for callbacks that don't need event details. Useful for simple notifications where you just need to know an event occurred.
Example:
| void UCILoader::EventEmitter::connect | ( | std::function< void(const EngineEvent *)> | callback, |
| uint32_t | eventFilter | ||
| ) |
Connect a callback function that receives the full event.
| callback | Function invoked for each matching event (receives const EngineEvent*) |
| eventFilter | Bitmask of NamedEngineEvents constants indicating which events to receive |
Wraps the callback in a FunctionCallbackEventReceiver and connects it. Useful for simple event handling without creating a custom EventReceiver class.
Example:
| void UCILoader::EventEmitter::connect | ( | std::shared_ptr< EventReceiver > | receiver | ) |
Connect a custom event receiver.
| receiver | Shared pointer to EventReceiver to connect |
Registers a custom EventReceiver to receive events. The emitter maintains a shared_ptr to the receiver, ensuring it remains alive as long as connected.
The first event sent will be EmitterConnected with no payload.
See EventReceiver documentation for implementing custom receivers.
|
protected |
Emit an event to all connected receivers.
| event | The EngineEvent to deliver |
Synchronously delivers the event to all receivers whose eventFilter() includes the event type. The delivery happens in the calling thread. Receivers are called in the order they were connected.
This method is typically called only by subclasses (e.g., EngineInstance).
| void UCILoader::EventEmitter::unlink | ( | const EventReceiver * | receiver | ) |
Disconnect a specific receiver from future events.
| receiver | Pointer to the EventReceiver to disconnect |
Safely removes the receiver from the emitter's receiver list. The receiver is not deleted (caller retains ownership). Safe to call even if receiver is not connected.