Eris  1.4.0
Public Member Functions | Friends | List of all members
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:

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
 

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.

Constructor & Destructor Documentation

◆ EventService()

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

Ctor.

Parameters
io_serviceThe main io_service of the system.

Member Function Documentation

◆ processAllHandlers()

size_t Eris::EventService::processAllHandlers ( )

Processes all registered handlers.

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

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.

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

Referenced by Eris::Meta::disconnect(), and runOnMainThreadDelayed().

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

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.

References runOnMainThread().


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