UCILoader 1.1.2
Small C++ library that allows user to connect to a chess engines via UCI protocol.
Loading...
Searching...
No Matches
UCILoader::EventReceiver Class Referenceabstract

Base class for event observers that receive engine events. More...

#include <EngineEvent.h>

Inheritance diagram for UCILoader::EventReceiver:
UCILoader::FunctionCallbackEventReceiver

Public Member Functions

virtual ~EventReceiver ()
 Virtual destructor that disconnects from all connected emitters.
 
void unlinkAll ()
 Disconnect this receiver from all connected emitters.
 
virtual uint32_t eventFilter ()=0
 Get the event filter bitmask for this receiver.
 
virtual void receiveEvent (const EngineEvent *event)=0
 Handle an incoming event.
 

Detailed Description

Base class for event observers that receive engine events.

EventReceiver defines the interface for custom event handlers. To receive events from an EngineInstance:

  1. Derive from EventReceiver or use FunctionCallbackEventReceiver for simple cases
  2. Implement eventFilter() to specify which events to receive (bitmask of event codes)
  3. Implement receiveEvent() to handle each event
  4. Connect to an EventEmitter via connect()

Creating Custom Event Receivers:

class MyEventReceiver : public EventReceiver {
public:
uint32_t eventFilter() override {
return (NamedEngineEvents::SearchCompleted |
NamedEngineEvents::EngineCrashed);
}
void receiveEvent(const EngineEvent* event) override {
if (event->getType() == NamedEngineEvents::SearchCompleted) {
std::cout << "Search done!" << std::endl;
}
}
};
Base class for events emitted by an EngineInstance.
Definition: EngineEvent.h:42
virtual uint32_t getType() const =0
Get the type code of this event.
Base class for event observers that receive engine events.
Definition: EngineEvent.h:347
See also
FunctionCallbackEventReceiver for lambda/function callback approach
EventEmitter for connecting receivers

Member Function Documentation

◆ eventFilter()

virtual uint32_t UCILoader::EventReceiver::eventFilter ( )
pure virtual

Get the event filter bitmask for this receiver.

Returns
A bitmask of NamedEngineEvents constants indicating which events to receive

This method determines which events this receiver will be notified about. The returned value should be a bitwise OR of one or more event constants from NamedEngineEvents.

Example:

uint32_t eventFilter() override {
return (NamedEngineEvents::SearchCompleted |
NamedEngineEvents::EngineCrashed);
}
virtual uint32_t eventFilter()=0
Get the event filter bitmask for this receiver.

Guaranteed that receiveEvent() is only called with events matching this filter.

Implemented in UCILoader::FunctionCallbackEventReceiver.

◆ receiveEvent()

virtual void UCILoader::EventReceiver::receiveEvent ( const EngineEvent event)
pure virtual

Handle an incoming event.

Parameters
eventPointer to the EngineEvent to handle

This method is invoked by the event emitter when an event matching the receiver's eventFilter() is emitted. It's guaranteed that:

  • The event type matches the eventFilter() bitmask
  • The event pointer is valid (not nullptr)
  • The method is called from the context where emit() was called

Implementations should:

  • Keep processing time minimal to avoid blocking other receivers
  • Use thread-safe mechanisms if accessing shared state
  • Not delete the event pointer (it's owned by the emitter)
  • Not modify the event's state

Implemented in UCILoader::FunctionCallbackEventReceiver.

◆ unlinkAll()

void UCILoader::EventReceiver::unlinkAll ( )

Disconnect this receiver from all connected emitters.

Safely removes all connections and prevents further event delivery.


The documentation for this class was generated from the following files: