MIRA
Public Member Functions | Public Attributes | List of all members
CyclicRunnable Class Reference

This class extends threads by the ability to execute an operation repeatedly in an defined interval. More...

#include <thread/CyclicRunnable.h>

Inheritance diagram for CyclicRunnable:
Inheritance graph
[legend]

Public Member Functions

 CyclicRunnable (boost::function< void()> fn, const std::string &name="")
 Constructs a CyclicRunnable with given functor. More...
 
 CyclicRunnable (boost::function< void()> fn, const Duration &interval, const std::string &name="")
 Constructs a CyclicRunnable with given functor and interval. More...
 
void operator() ()
 Bind this to a thread to execute the given functor in the specified interval. More...
 

Public Attributes

Duration cycleTime
 The cycle time, this cyclic runnable calls its assigned function. More...
 

Detailed Description

This class extends threads by the ability to execute an operation repeatedly in an defined interval.

By binding the operator() of this class to a boost thread the given functor is executed in the given interval.

// creates a cyclic runnable, that calls myCyclicFunction every 500 ms
CyclicRunnable cyclic(myCyclicFunction, Duration::milliseconds(500));
// launch the cyclic runnable in a separate thread
boost::thread t(boost::ref(cyclic));
// also boost::thread t(boost::bind(&CyclicRunnable::operator(), &cyclic)) can be used.
Note
If the operation that is processed repeatedly takes more time than the specified interval, the interval cannot be hold and the operation is called as fast as possible.

Constructor & Destructor Documentation

◆ CyclicRunnable() [1/2]

CyclicRunnable ( boost::function< void()>  fn,
const std::string &  name = "" 
)
inline

Constructs a CyclicRunnable with given functor.

This uses a default interval of 1 second

Parameters
[in]fnThe function to execute repeatedly.
[in]nameThe optional name of the thread that is registered in the Threadmanager.

◆ CyclicRunnable() [2/2]

CyclicRunnable ( boost::function< void()>  fn,
const Duration interval,
const std::string &  name = "" 
)
inline

Constructs a CyclicRunnable with given functor and interval.

Parameters
[in]fnThe function to execute repeatedly.
[in]intervalThe interval (cycle time) between each execution of fn.
[in]nameThe optional name of the thread that is registered in the Threadmanager.

Member Function Documentation

◆ operator()()

void operator() ( )
inline

Bind this to a thread to execute the given functor in the specified interval.

Member Data Documentation

◆ cycleTime

Duration cycleTime

The cycle time, this cyclic runnable calls its assigned function.


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