Eris
1.4.0
|
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. | |
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 boost::posix_time::time_duration &duration, std::shared_ptr< bool > activeMarker=std::make_shared< bool >(true)) |
Runs a handler on the main thread after a certain delay. More... | |
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.
|
explicit |
Ctor.
io_service | The main io_service of the system. |
size_t Eris::EventService::processAllHandlers | ( | ) |
Processes all registered handlers.
Referenced by ~EventService().
size_t Eris::EventService::processOneHandler | ( | ) |
Processes one handler, if possible.
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. |
Referenced by Eris::Meta::disconnect(), and runOnMainThreadDelayed().
void Eris::EventService::runOnMainThreadDelayed | ( | const std::function< void()> & | handler, |
const boost::posix_time::time_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. |
References runOnMainThread().