|
With *event handler* here we mean anything that can continuously read from an event queue and process the received events.
|
|
With _event handler_ here we mean anything that can continuously read from an event queue and process the received events.
|
|
|
|
|
|
## EventHandlerBase
|
|
## EventHandlerBase
|
|
|
|
|
... | @@ -22,7 +22,7 @@ In fact an EventHandler is a special ActiveObject that periodically checks a syn |
... | @@ -22,7 +22,7 @@ In fact an EventHandler is a special ActiveObject that periodically checks a syn |
|
### Methods
|
|
### Methods
|
|
EventHadler offers two main methods:
|
|
EventHadler offers two main methods:
|
|
- **virtual void postEvent(const Event& ev)**: overridden from EventHandlerBase, it enqueues the event passed as a parameters.
|
|
- **virtual void postEvent(const Event& ev)**: overridden from EventHandlerBase, it enqueues the event passed as a parameters.
|
|
- **virtual void handleEvent(const Event& ev)**: protected method that is periodically called in the active objects thread. In fact in the *run()* method, whenever an event is present in the queue, it gets removed and the *handleEvent* method is called. The *handleEvent* method has to be overridden and implemented by any class that extends EventHandler.
|
|
- **virtual void handleEvent(const Event& ev)**: protected method that is periodically called in the active objects thread. In fact in the _run()_ method, whenever an event is present in the queue, it gets removed and the _handleEvent_ method is called. The _handleEvent_ method has to be overridden and implemented by any class that extends EventHandler.
|
|
|
|
|
|
You can find the complete implementation of EventHandler in `src/shared/events/EventHandler.h`.
|
|
You can find the complete implementation of EventHandler in `src/shared/events/EventHandler.h`.
|
|
|
|
|
... | @@ -45,7 +45,7 @@ enum ExampleEvents : uint8_t |
... | @@ -45,7 +45,7 @@ enum ExampleEvents : uint8_t |
|
};
|
|
};
|
|
```
|
|
```
|
|
Then, we can define a class that extends EventHandler.
|
|
Then, we can define a class that extends EventHandler.
|
|
We need at least to override the *handleEvent()* method, which processes incoming events.
|
|
We need at least to override the _handleEvent()_ method, which processes incoming events.
|
|
In this example we simply produce some output strings and keep track of the last event that has been recevied.
|
|
In this example we simply produce some output strings and keep track of the last event that has been recevied.
|
|
```cpp
|
|
```cpp
|
|
class MyEventHandler : public EventHandler
|
|
class MyEventHandler : public EventHandler
|
... | | ... | |