libqi-api  2.4.3.28
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Public Attributes | 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 ()
 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)
 
void post (const boost::function< void()> &callback)
 post a callback to be executed as soon as possible More...
 
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=0)
 Call given function once after given delay in microseconds. More...
 
Future< void > async (const boost::function< void()> &callback, uint64_t usDelay=0)
 
Future< void > async (const boost::function< void()> &callback, qi::Duration delay)
 call a callback asynchronously to be executed in delay More...
 
Future< void > async (const boost::function< void()> &callback, qi::SteadyClockTimePoint timepoint)
 call a callback asynchronously to be executed on tp More...
 
template<typename R >
boost::enable_if_c
<!boost::is_same< R, void >
::value, qi::Future< R >
>::type 
async (const boost::function< R()> &callback, qi::Duration delay)
 
template<typename R >
boost::enable_if_c
<!boost::is_same< R, void >
::value, qi::Future< R >
>::type 
async (const boost::function< R()> &callback, qi::SteadyClockTimePoint tp)
 
- Public Member Functions inherited from qi::ExecutionContext
virtual ~ExecutionContext ()
 
template<typename R >
boost::disable_if
< boost::is_same< R, void >
, qi::Future< R > >::type 
async (const boost::function< R()> &callback, qi::Duration delay=qi::Duration(0))
 call a callback asynchronously to be executed in delay More...
 
template<typename R >
boost::disable_if
< boost::is_same< R, void >
, qi::Future< R > >::type 
async (const boost::function< R()> &callback, qi::SteadyClockTimePoint tp)
 call a callback asynchronously to be executed on tp More...
 

Public Attributes

EventLoopPrivate * _p
 
std::string _name
 

Detailed Description

Class to handle eventloop. .

Definition at line 41 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 = 0 
)
inline

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 = 0 
)
Future<void> qi::EventLoop::async ( const boost::function< void()> &  callback,
qi::Duration  delay 
)
virtual

call a callback asynchronously to be executed in delay

Implements qi::ExecutionContext.

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

call a callback asynchronously to be executed on tp

Implements qi::ExecutionContext.

template<typename R >
boost::enable_if_c<!boost::is_same<R, void>::value, qi::Future<R> >::type qi::EventLoop::async ( const boost::function< R()> &  callback,
qi::Duration  delay 
)
inline

Definition at line 101 of file eventloop.hpp.

template<typename R >
boost::enable_if_c<!boost::is_same<R, void>::value, qi::Future<R> >::type qi::EventLoop::async ( const boost::function< R()> &  callback,
qi::SteadyClockTimePoint  tp 
)
inline

Definition at line 108 of file eventloop.hpp.

bool qi::EventLoop::isInThisContext ( )
virtual

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 
)

Similar to async() but without cancelation or notification.

Parameters
callbackCallback to be called.
usDelayDelay before call the callback in microsecond.
void qi::EventLoop::post ( const boost::function< void()> &  callback,
qi::Duration  delay 
)
void qi::EventLoop::post ( const boost::function< void()> &  callback,
qi::SteadyClockTimePoint  timepoint 
)
void qi::EventLoop::post ( const boost::function< void()> &  callback)
inlinevirtual

post a callback to be executed as soon as possible

Implements qi::ExecutionContext.

Definition at line 123 of file eventloop.hpp.

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.

Member Data Documentation

std::string qi::EventLoop::_name

Definition at line 139 of file eventloop.hpp.

EventLoopPrivate* qi::EventLoop::_p

Definition at line 138 of file eventloop.hpp.


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