122 template<
class Payload, u
int32_t EventCode>
147 virtual const void *
getPayload()
const override {
return &value; };
185 virtual const void*
getPayload()
const override {
return nullptr; };
190 namespace NamedEngineEvents {
193 const uint32_t EmitterConnected = 1u;
195 const uint32_t EmitterDestroyed = 2u;
197 const uint32_t EngineSynchronized = 4u;
199 const uint32_t SearchStarted = 8u;
201 const uint32_t SearchCompleted = 16u;
203 const uint32_t EngineCrashed = 32u;
205 const uint32_t InfoClampReceived = 64u;
207 const uint32_t InfoReceived = 128u;
216 using EmitterConnectedEvent = NoPayloadEvent;
224 using EmitterDestroyedEvent = NoPayloadEvent;
232 using EngineSynchronizedEvent = NoPayloadEvent;
240 using SearchStartedEvent = NoPayloadEvent;
249 using SearchCompletedEvent = NoPayloadEvent;
256 using EngineCrashedEvent = NoPayloadEvent;
277 static EngineSynchronizedEvent makeSynchronizedEvent() {
return NoPayloadEvent(EngineSynchronized); };
282 static SearchStartedEvent makeSearchStartedEvent() {
return NoPayloadEvent(SearchStarted); };
287 static SearchCompletedEvent makeSearchCompletedEvent() {
return NoPayloadEvent(SearchCompleted); };
292 static EngineCrashedEvent makeEngineCrashedEvent() {
return NoPayloadEvent(EngineCrashed); };
302 static ConcreteEvent<std::vector<Info<Move>>, InfoClampReceived> makeInfoClampEvent(
const std::vector<Info<Move>> & clamp) {
return ConcreteEvent<std::vector<Info<Move>>, InfoClampReceived>(clamp); };
312 static ConcreteEvent<Info<Move>, InfoReceived> makeInfoEvent(
const Info<Move> & i) {
return ConcreteEvent<Info<Move>, InfoReceived>(i); };
350 std::list<EventEmitter*> publishers;
432 uint32_t allowedEvents;
454 virtual void receiveEvent(
const EngineEvent* event)
override;
460 virtual uint32_t
eventFilter()
override {
return allowedEvents; };
495 mutable std::mutex lock;
496 std::list<std::shared_ptr<EventReceiver>> receivers;
510 int countActiveReceivers()
const;
549 void connect(std::shared_ptr<EventReceiver> receiver);
591 void connect(std::function<
void()> callback, uint32_t eventFilter);
Template for creating typed event objects with a payload.
Definition: EngineEvent.h:123
virtual const void * getPayload() const override
Get pointer to the stored payload.
Definition: EngineEvent.h:147
uint32_t getType() const override
Get the event type code.
Definition: EngineEvent.h:138
ConcreteEvent(const Payload &p)
Constructor that stores the payload.
Definition: EngineEvent.h:132
Base class for events emitted by an EngineInstance.
Definition: EngineEvent.h:42
virtual ~EngineEvent()
Virtual destructor for proper cleanup of derived classes.
Definition: EngineEvent.h:48
virtual uint32_t getType() const =0
Get the type code of this event.
virtual const void * getPayload() const =0
Get the payload data associated with this event.
Base class for objects that emit engine events.
Definition: EngineEvent.h:494
void connect(std::shared_ptr< EventReceiver > receiver)
Connect a custom event receiver.
Definition: EngineEvent.cpp:59
virtual ~EventEmitter()
Virtual destructor ensuring proper cleanup.
Definition: EngineEvent.cpp:15
void emit(const EngineEvent *event)
Emit an event to all connected receivers.
Definition: EngineEvent.cpp:25
void unlink(const EventReceiver *receiver)
Disconnect a specific receiver from future events.
Definition: EngineEvent.cpp:36
Base class for event observers that receive engine events.
Definition: EngineEvent.h:347
void unlinkAll()
Disconnect this receiver from all connected emitters.
Definition: EngineEvent.cpp:3
virtual void receiveEvent(const EngineEvent *event)=0
Handle an incoming event.
virtual ~EventReceiver()
Virtual destructor that disconnects from all connected emitters.
Definition: EngineEvent.h:356
virtual uint32_t eventFilter()=0
Get the event filter bitmask for this receiver.
Adapter class that wraps a callback function as an EventReceiver.
Definition: EngineEvent.h:430
FunctionCallbackEventReceiver(std::function< void(const EngineEvent *)> callback, uint32_t allowedEvents)
Constructor for callbacks that receive the full event.
Definition: EngineEvent.h:440
FunctionCallbackEventReceiver(std::function< void()> callback, uint32_t allowedEvents)
Constructor for simple parameterless callbacks.
Definition: EngineEvent.h:447
virtual uint32_t eventFilter() override
Get the event filter bitmask.
Definition: EngineEvent.h:460
virtual void receiveEvent(const EngineEvent *event) override
Handle the event by invoking the stored callback.
Definition: EngineEvent.cpp:11
Simple event type with no associated payload.
Definition: EngineEvent.h:161
virtual const void * getPayload() const override
Get the payload (always nullptr for NoPayloadEvent).
Definition: EngineEvent.h:185
NoPayloadEvent(uint32_t c)
Constructor that stores the event type code.
Definition: EngineEvent.h:169
uint32_t getType() const override
Get the event type code.
Definition: EngineEvent.h:176