#include <UEventsHandler.h>
Public Member Functions | |
void | registerToEventsManager () |
void | unregisterFromEventsManager () |
Public Member Functions inherited from UEventsSender | |
UEventsSender () | |
virtual | ~UEventsSender () |
Protected Member Functions | |
virtual bool | handleEvent (UEvent *event)=0 |
UEventsHandler () | |
virtual | ~UEventsHandler () |
Protected Member Functions inherited from UEventsSender | |
void | post (UEvent *event, bool async=true) const |
Friends | |
class | UEventsManager |
The class UEventsHandler is an abstract class for handling events.
Inherited classes must implement handleEvent() function, which is called by the UEventsManager when an event is dispatched. Once the handler is created, it must be added to events manager with UEventsManager::addHandler() function. Note that it is not safe to automatically add the handler to UEventsManager in the handler's constructor.
Note for multi-threading: the handleEvent() method is called inside the UEventsManager thread. If the inherited class also inherits from UThreadNode, handleEvent() is done as well outside the thread's main loop, so be careful to protect private data of the thread used in its main loop.
Example for a useful combination of an UEventsHandler and a UThreadNode, with safe data modification while not blocking the handleEvent() call on a mutex:
The output is:
Definition at line 128 of file UEventsHandler.h.
|
inlineprotected |
UEventsHandler constructor.
Note : You can call EventsManager::addHandler(this) at the end of the constructor of the inherited class where the virtual method handleEvent(...) is defined. If so, the UEventsHandler doesn't need to be manually added to the EventsManager where the handler is instantiated. We decided to not include UEventsManager::addHandler(this) in this abstract class constructor because an event can be handled (calling the pure virtual method) while the concrete class is constructed.
Definition at line 172 of file UEventsHandler.h.
|
protectedvirtual |
UEventsHandler destructor.
By default, it removes the handler reference from the UEventsManager. To be thread-safe, the inherited class must remove itself from the UEventsManager before it is deleted because an event can be handled (calling the pure virtual method handleEvent()) after the concrete class is deleted.
Definition at line 23 of file UEventsHandler.cpp.
|
protectedpure virtual |
Method called by the UEventsManager to handle an event. Important : this method must do a minimum of work because the faster the dispatching loop is done; the faster the events are received. If a handling function takes too much time, the events list can grow faster than it is emptied. The event can be modified.
Implemented in RTABMapApp, rtabmap::CalibrationDialog, rtabmap::ProgressionStatus, rtabmap::OdometryViewer, rtabmap::DataRecorder, rtabmap::CameraViewer, rtabmap::LogHandler, rtabmap::OdometryThread, rtabmap::MainWindow, rtabmap::RtabmapThread, and rtabmap::ConsoleWidget.
void UEventsHandler::registerToEventsManager | ( | ) |
Definition at line 29 of file UEventsHandler.cpp.
void UEventsHandler::unregisterFromEventsManager | ( | ) |
Definition at line 33 of file UEventsHandler.cpp.
|
friend |
Only the UEventsManager has access to the handleEvent() method.
Definition at line 140 of file UEventsHandler.h.