PeriodicTask.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #ifndef COIL_PERIODICTASK_H
00021 #define COIL_PERIODICTASK_H
00022 
00023 #include <map>
00024 #include <string>
00025 #include <vector>
00026 #include <algorithm>
00027 
00028 #include <coil/Mutex.h>
00029 #include <coil/Guard.h>
00030 #include <coil/Condition.h>
00031 #include <coil/TimeValue.h>
00032 #include <coil/TimeMeasure.h>
00033 #include <coil/PeriodicTaskBase.h>
00034 
00035 namespace coil
00036 {
00061   class PeriodicTask
00062     : public coil::PeriodicTaskBase
00063   {
00064   public:
00065     typedef coil::Guard<coil::Mutex> Guard;
00066 
00082     PeriodicTask();
00083     
00099     virtual ~PeriodicTask();
00100     
00123     virtual void activate();
00124 
00138     virtual void finalize();
00139 
00153     virtual int suspend(void);
00154 
00168     virtual int resume(void);
00169 
00183     virtual void signal();
00184 
00198     virtual bool setTask(TaskFuncBase* func, bool delete_in_dtor = true);
00199 
00217     template <class O, class F>
00218     bool setTask(O* obj, F fun)
00219     {
00220       return this->setTask(new TaskFunc<O, F>(obj, fun));
00221     }
00222 
00236     virtual void setPeriod(double period);
00237 
00251     virtual void setPeriod(TimeValue& period);
00252 
00260     virtual void executionMeasure(bool value);
00261     
00269     virtual void executionMeasureCount(int n);
00270     
00278     virtual void periodicMeasure(bool value);
00279     
00287     virtual void periodicMeasureCount(int n);
00288     
00296     virtual TimeMeasure::Statistics getExecStat();
00297     
00305     virtual TimeMeasure::Statistics getPeriodStat();
00306     
00307   protected:
00315     virtual int svc();
00316 
00324     virtual void sleep();
00325 
00333     virtual void updateExecStat();
00334 
00342     virtual void updatePeriodStat();
00343 
00344   protected:
00352     coil::TimeValue m_period;
00353 
00361     bool m_nowait;
00362 
00370     TaskFuncBase* m_func;
00371 
00379     bool m_deleteInDtor;
00380 
00390     class alive_t
00391     {
00392     public:
00393       alive_t(bool val) : value(val) {}
00394       bool value;
00395       coil::Mutex mutex;
00396     };
00397 
00405     alive_t m_alive;
00406 
00414     struct suspend_t
00415     {
00416       suspend_t(bool sus) : suspend(sus), mutex(), cond(mutex) {}
00417       bool suspend;
00418       coil::Mutex mutex;
00419       coil::Condition<coil::Mutex> cond;
00420     };
00421 
00429     suspend_t m_suspend;
00430       
00438     struct statistics_t
00439     {
00440       coil::TimeMeasure::Statistics stat;
00441       coil::Mutex mutex;
00442     };
00443 
00451     bool              m_execMeasure;
00452 
00460     unsigned int      m_execCount;
00461 
00469     unsigned int      m_execCountMax;
00470 
00478     statistics_t      m_execStat;
00479 
00487     coil::TimeMeasure m_execTime;
00488 
00496     bool              m_periodMeasure;
00497 
00505     unsigned int      m_periodCount;
00506 
00514     unsigned int      m_periodCountMax;
00515 
00523     statistics_t      m_periodStat;
00524 
00532     coil::TimeMeasure m_periodTime;
00533 
00534   };
00535 
00536 }; // namespace coil
00537 
00538 #endif // COIL_PERIODICTASK_H


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:05