libqi-api  release-2.5.3-2016-11-18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
qi::EventLoop Class Reference

Class to handle eventloop. . More...

#include <eventloop.hpp>

Public Member Functions

 EventLoop (const std::string &name="eventloop")
 Create a new eventLoop. More...
 
 ~EventLoop ()
 Default destructor. More...
 
bool isInThisContext () override
 Check if current thread is the event loop thread. More...
 
void start (int nthreads=0)
 Start the eventloop in threaded mode. More...
 
void join ()
 Wait for run thread to terminate. More...
 
void stop ()
 Ask main loop to terminate. More...
 
void setEmergencyCallback (boost::function< void()> cb)
 Set callback to be called in case of a deadlock detection. More...
 
void setMaxThreads (unsigned int max)
 Set the maximum number of threads in the pool. More...
 
void * nativeHandle ()
 Internal function. More...
 
void post (const boost::function< void()> &callback, uint64_t usDelay)
 Similar to async() but without cancelation or notification. More...
 
void post (const boost::function< void()> &callback, qi::Duration delay)
 
void post (const boost::function< void()> &callback, qi::SteadyClockTimePoint timepoint)
 
Future< void > monitorEventLoop (EventLoop *helper, uint64_t maxUsDelay)
 Monitor event loop to detect deadlocks. More...
 
template<typename R >
Future< R > async (const boost::function< R()> &callback, uint64_t usDelay)
 Call given function once after given delay in microseconds. More...
 
Future< void > async (const boost::function< void()> &callback, uint64_t usDelay)
 
Future< void > async (const boost::function< void()> &callback, qi::Duration delay) override
 
Future< void > async (const boost::function< void()> &callback, qi::SteadyClockTimePoint timepoint) override
 
- Public Member Functions inherited from qi::ExecutionContext
virtual ~ExecutionContext ()
 
template<typename R >
boost::disable_if
< std::is_same< R, void >
, qi::Future< R > >::type 
async (const boost::function< R()> &callback, qi::Duration delay)
 
template<typename R >
boost::disable_if
< std::is_same< R, void >
, qi::Future< R > >::type 
async (const boost::function< R()> &callback, qi::SteadyClockTimePoint tp)
 
template<typename R >
qi::Future< R > async (const detail::Function< R()> &callback)
 
template<typename F >
void post (F &&callback)
 post a callback to be executed as soon as possible More...
 
template<typename F >
auto asyncAt (F &&callback, qi::SteadyClockTimePoint tp) -> qi::Future< typename std::decay< decltype(callback())>::type >
 call a callback asynchronously to be executed on tp More...
 
template<typename F >
auto asyncDelay (F &&callback, qi::Duration delay) -> qi::Future< typename std::decay< decltype(callback())>::type >
 call a callback asynchronously to be executed in delay More...
 
template<typename F >
auto async (F &&callback) -> decltype(asyncDelay(std::forward< F >(callback), qi::Duration(0)))
 

Additional Inherited Members

Detailed Description

Class to handle eventloop. .

Definition at line 42 of file eventloop.hpp.

Constructor & Destructor Documentation

qi::EventLoop::EventLoop ( const std::string &  name = "eventloop")

Create a new eventLoop.

Parameters
nameName of the event loop created.

You must then call either start(), run() or startThreadPool() to start event processing.

qi::EventLoop::~EventLoop ( )

Default destructor.

Member Function Documentation

template<typename R >
Future< R > qi::EventLoop::async ( const boost::function< R()> &  callback,
uint64_t  usDelay 
)

Call given function once after given delay in microseconds.

Parameters
callbackCallback to be called.
usDelayDelay before call the callback in microsecond.
Returns
A canceleable future.
Deprecated:
use qi::async with qi::Duration

Definition at line 21 of file eventloop.hxx.

Future<void> qi::EventLoop::async ( const boost::function< void()> &  callback,
uint64_t  usDelay 
)
inline

Definition at line 98 of file eventloop.hpp.

Future<void> qi::EventLoop::async ( const boost::function< void()> &  callback,
qi::Duration  delay 
)
inlineoverridevirtual

call a callback asynchronously to be executed in delay

Deprecated:
since 2.5

Implements qi::ExecutionContext.

Definition at line 103 of file eventloop.hpp.

Future<void> qi::EventLoop::async ( const boost::function< void()> &  callback,
qi::SteadyClockTimePoint  tp 
)
inlineoverridevirtual

call a callback asynchronously to be executed on tp

Deprecated:
since 2.5

Implements qi::ExecutionContext.

Definition at line 108 of file eventloop.hpp.

bool qi::EventLoop::isInThisContext ( )
overridevirtual

Check if current thread is the event loop thread.

Returns
true if current thread is the event loop thread.

Implements qi::ExecutionContext.

void qi::EventLoop::join ( )

Wait for run thread to terminate.

Future<void> qi::EventLoop::monitorEventLoop ( EventLoop helper,
uint64_t  maxUsDelay 
)

Monitor event loop to detect deadlocks.

Parameters
helperan other event loop used for monitoring.
maxUsDelaymaximum expected delay between an async() and its execution.
Returns
A canceleable future. Invoke cancel() to terminate monitoring. In case an async() call does not execute in time, the future's error will be set.
void* qi::EventLoop::nativeHandle ( )

Internal function.

void qi::EventLoop::post ( const boost::function< void()> &  callback,
uint64_t  usDelay 
)
inline

Similar to async() but without cancelation or notification.

Parameters
callbackCallback to be called.
usDelayDelay before call the callback in microsecond.

Definition at line 123 of file eventloop.hpp.

void qi::EventLoop::post ( const boost::function< void()> &  callback,
qi::Duration  delay 
)
inline

Definition at line 128 of file eventloop.hpp.

void qi::EventLoop::post ( const boost::function< void()> &  callback,
qi::SteadyClockTimePoint  timepoint 
)
void qi::EventLoop::setEmergencyCallback ( boost::function< void()>  cb)

Set callback to be called in case of a deadlock detection.

Parameters
cbCallback to be called.
void qi::EventLoop::setMaxThreads ( unsigned int  max)

Set the maximum number of threads in the pool.

Parameters
maxMaximum number of threads.
void qi::EventLoop::start ( int  nthreads = 0)

Start the eventloop in threaded mode.

Parameters
nthreadsNumbers of threads.
void qi::EventLoop::stop ( )

Ask main loop to terminate.


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