eris 1.4.0
A WorldForge client library.
|
Handles polling of the IO system as well as making sure that registered handlers are run on the main thread. More...
#include <EventService.h>
Public Member Functions | |
EventService (boost::asio::io_service &io_service) | |
Ctor. More... | |
~EventService () | |
Dtor. More... | |
void | runOnMainThread (const std::function< void()> &handler, std::shared_ptr< bool > activeMarker=std::make_shared< bool >(true)) |
Adds a handler which will be run on the main thread. More... | |
void | runOnMainThreadDelayed (const std::function< void()> &handler, const std::chrono::steady_clock::duration &duration, std::shared_ptr< bool > activeMarker=std::make_shared< bool >(true)) |
size_t | processAllHandlers () |
Processes all registered handlers. More... | |
size_t | processOneHandler () |
Processes one handler, if possible. More... | |
Friends | |
class | TimedEvent |
Handles polling of the IO system as well as making sure that registered handlers are run on the main thread.
Call runEvents in your main loop. Use runOnMainThread to posts function from background threads.
Definition at line 42 of file EventService.h.
|
explicit |
Ctor.
io_service | The main io_service of the system. |
Definition at line 27 of file EventService.cpp.
Eris::EventService::~EventService | ( | ) |
size_t Eris::EventService::processAllHandlers | ( | ) |
Processes all registered handlers.
Definition at line 70 of file EventService.cpp.
Referenced by ~EventService().
size_t Eris::EventService::processOneHandler | ( | ) |
Processes one handler, if possible.
Definition at line 99 of file EventService.cpp.
void Eris::EventService::runOnMainThread | ( | const std::function< void()> & | handler, |
std::shared_ptr< bool > | activeMarker = std::make_shared<bool>(true) |
||
) |
Adds a handler which will be run on the main thread.
This method should mainly be called from background threads. The execution of the handler will be interleaved with the IO polling, making sure that at least one handler is executed each frame.
handler | A function. |
activeMarker | An active marker which is used for cancellation of tasks. If it evaluates to "false" the handler won't be invoked. Use ActiveMarker for convenience. |
Definition at line 47 of file EventService.cpp.
Referenced by runOnMainThreadDelayed().
void Eris::EventService::runOnMainThreadDelayed | ( | const std::function< void()> & | handler, |
const std::chrono::steady_clock::duration & | duration, | ||
std::shared_ptr< bool > | activeMarker = std::make_shared<bool>(true) |
||
) |
Runs a handler on the main thread after a certain delay.
handler | A function. |
duration | The duration to wait. |
activeMarker | An active marker which is used for cancellation of tasks. If it evaluates to "false" the handler won't be invoked. Use ActiveMarker for convenience. |
Definition at line 57 of file EventService.cpp.
References runOnMainThread().
|
friend |
Definition at line 100 of file EventService.h.