eris  1.4.0
A WorldForge client library.
Eris::EventService Class Reference

Handles polling of the IO system as well as making sure that registered handlers are run on the main thread. More...

#include <EventService.h>

Inheritance diagram for Eris::EventService:
Collaboration diagram for Eris::EventService:

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ EventService()

Eris::EventService::EventService ( boost::asio::io_service &  io_service)
explicit

Ctor.

Parameters
io_serviceThe main io_service of the system.

Definition at line 27 of file EventService.cpp.

◆ ~EventService()

Eris::EventService::~EventService ( )

Dtor.

Definition at line 34 of file EventService.cpp.

References processAllHandlers().

Member Function Documentation

◆ processAllHandlers()

size_t Eris::EventService::processAllHandlers ( )

Processes all registered handlers.

See also
runOnMainThread
Returns
The number of handles that were run.

Definition at line 70 of file EventService.cpp.

Referenced by ~EventService().

◆ processOneHandler()

size_t Eris::EventService::processOneHandler ( )

Processes one handler, if possible.

See also
runOnMainThread
Returns
The number of handles that were run.

Definition at line 99 of file EventService.cpp.

◆ runOnMainThread()

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.

Parameters
handlerA function.
activeMarkerAn 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().

◆ 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.

Parameters
handlerA function.
durationThe duration to wait.
activeMarkerAn 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().


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