48 #ifndef _MIRA_DISPATCHERTHREAD_H_ 49 #define _MIRA_DISPATCHERTHREAD_H_ 55 #include <boost/function.hpp> 56 #include <boost/thread/condition_variable.hpp> 70 template<
typename T,
typename Sequence = std::vector<T>,
71 typename Compare = std::less<
typename Sequence::value_type> >
74 typedef std::priority_queue<T,Sequence,Compare> Base;
86 Base(x,
std::move(s)) {}
89 template<
typename InputIterator>
91 Base(first,last,x,s) {}
93 template<
typename InputIterator>
95 Base(first,last,x,
std::move(s)) {}
174 currentExpected += mPeriod;
220 Duration dt = current - currentExpected;
244 return currentExpected;
282 void setName(
const std::string& name);
304 template <
typename F>
307 addImmediateHandler(r);
320 template <
typename F>
323 addFinalizeHandler(r);
378 void start(
bool startThread =
true);
392 bool hasUnrecoverableFailure()
const;
401 bool isRunning()
const;
448 bool processImmediateHandlers();
449 bool processFinalizeHandlers();
454 bool isInterruptionRequested();
bool toBeRemoved
Definition: DispatcherThread.h:467
boost::mutex mConditionMutex
Definition: DispatcherThread.h:478
std::set< TimerPtr > mTimers
Definition: DispatcherThread.h:496
static Duration invalid()
Returns an invalid duration.
Definition: Time.h:252
Time currentExpected
time the current callback should be happening
Definition: DispatcherThread.h:253
Sequence::iterator iterator
Definition: DispatcherThread.h:78
bool mInterruptionRequested
Definition: DispatcherThread.h:506
boost::condition_variable mCondition
Definition: DispatcherThread.h:479
PropertyHint spin(const T &min, const T &max, const T &s)
Sets the attribute "type" to the value "spinbox" and sets the "minimum", "maximum" and "step" attribu...
Definition: PropertyHint.h:328
DispatcherThread::Timer Timer
Definition: DispatcherThread.h:514
DispatcherThread::TimerPtr TimerPtr
Definition: DispatcherThread.h:515
bool mUnrecoverableFailure
Definition: DispatcherThread.h:499
Class representing timers and tasks that can be registered and executed by the dispatcher thread...
Definition: DispatcherThread.h:147
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
boost::function< void(const Timer &)> TimerCallback
Signature of a timer/task callback function.
Definition: DispatcherThread.h:136
boost::mutex mFinalizeHandlerMutex
Definition: DispatcherThread.h:494
bool mIsRunning
Definition: DispatcherThread.h:500
IteratablePriorityQueue(const Compare &x, const Sequence &s)
Definition: DispatcherThread.h:82
Time and Duration wrapper class.
Runnable that wraps any function pointer.
Definition: Runnable.h:115
QueueItem(IRunnablePtr r, Time t)
Definition: DispatcherThread.h:462
Framework export macro declaration.
bool operator<(const QueueItem &other) const
Definition: DispatcherThread.h:469
IteratablePriorityQueue(InputIterator first, InputIterator last, const Compare &x, Sequence &&s)
Definition: DispatcherThread.h:94
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:421
IteratablePriorityQueue(InputIterator first, InputIterator last, const Compare &x, const Sequence &s)
Definition: DispatcherThread.h:90
IteratablePriorityQueue< QueueItem, std::deque< QueueItem > > Queue
Definition: DispatcherThread.h:472
boost::mutex mTimerMutex
Definition: DispatcherThread.h:497
void setTolerance(Duration tolerance)
Set the tolerance that is allowed to exceed the next invocation time before issuing a warning and res...
Definition: DispatcherThread.h:202
boost::shared_ptr< Timer > TimerPtr
Definition: DispatcherThread.h:270
std::list< IRunnablePtr > mImmediateHandlers
Definition: DispatcherThread.h:490
Base for all runnable classes that can be signaled when they need to run again.
Definition: Runnable.h:72
Auxiliary logging macros for special entities like exceptions, etc.
Includes, defines and functions for threads.
Definition: DispatcherThread.h:72
Duration getExceedance() const
Checks and returns the amount of time the timer has exceeded the expected invocation time...
Definition: DispatcherThread.h:216
DispatcherThread::TimerCallback TimerCallback
Definition: DispatcherThread.h:516
Time getNextInvocationTime() const
Return next time of execution.
Definition: DispatcherThread.h:243
void addFinalizeHandlerFunction(F &&fn, DiagnosticsModulePtr errorModule=NULL)
Adds a function that is executed once just before the thread terminates.
Definition: DispatcherThread.h:321
void setPeriod(Duration period)
Changes the period of the timer.
Definition: DispatcherThread.h:190
#define MIRA_FRAMEWORK_EXPORT
Definition: FrameworkExports.h:61
sec_type seconds() const
Returns normalized number of seconds (0..59)
Definition: Time.h:283
Time last
time the last callback happened
Definition: DispatcherThread.h:250
Use this class to represent time durations.
Definition: Time.h:104
iterator end()
Definition: DispatcherThread.h:100
boost::thread::id getThreadID() const
Returns the thread id of the thread that is used to process the dispatcher.
Definition: DispatcherThread.h:426
boost::shared_ptr< IRunnable > IRunnablePtr
a runnable pointer
Definition: Runnable.h:63
XXX.
Definition: DispatcherThread.h:459
Class that can be used whenever you want to have ONE thread where several handlers are assigned to...
Definition: DispatcherThread.h:131
boost::mutex mImmediateHandlerMutex
Definition: DispatcherThread.h:491
void updateInvocationTime()
Called by dispatcher when timer is rescheduled.
Definition: DispatcherThread.h:173
static Duration infinity()
Returns a special duration time representing positive infinity.
Definition: Time.h:245
Duration getTolerance() const
Get the tolerance for exceed the next invocation time.
Definition: DispatcherThread.h:208
bool isActive() const
Returns if the timer is active.
Definition: DispatcherThread.h:184
IteratablePriorityQueue(const Compare &x=Compare(), Sequence &&s=Sequence())
Definition: DispatcherThread.h:85
Duration getPeriod() const
Returns the current period of the timer.
Definition: DispatcherThread.h:195
QueueItem()
Definition: DispatcherThread.h:461
Sequence::const_iterator const_iterator
Definition: DispatcherThread.h:79
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:484
Time time
Definition: DispatcherThread.h:466
boost::thread mThread
Definition: DispatcherThread.h:508
std::set< IRunnablePtr > mPendingRunnables
Definition: DispatcherThread.h:476
Queue mQueue
Definition: DispatcherThread.h:475
bool mPendingSignal
Definition: DispatcherThread.h:510
IRunnablePtr runnable
Definition: DispatcherThread.h:465
std::string mName
Definition: DispatcherThread.h:488
Exception that can be thrown in every handler to indicate an unrecoverable failure.
Definition: DispatcherThread.h:398
const_iterator end() const
Definition: DispatcherThread.h:103
const_iterator begin() const
Definition: DispatcherThread.h:102
Include file for including all string algorithm headers.
boost::thread::id mThreadId
Definition: DispatcherThread.h:509
iterator begin()
Definition: DispatcherThread.h:99
Base class for modules that want to use diagnostics and set the current status.
Definition: Status.h:138
std::list< IRunnablePtr > mFinalizeHandlers
Definition: DispatcherThread.h:493
Status and status management classes used for diagnostics.
void addImmediateHandlerFunction(F &&fn, DiagnosticsModulePtr errorModule=NULL)
Adds a function that is executed once as soon as possible within the DispatcherThreads main thread...
Definition: DispatcherThread.h:305
Duration lastDuration
How long the last callback ran for.
Definition: DispatcherThread.h:259
Time current
time the current callback was actually called (Time::now() as of the beginning of the callback) ...
Definition: DispatcherThread.h:256