libqi-api
2.0.6.8
|
00001 #pragma once 00002 /* 00003 * Copyright (c) Aldebaran Robotics 2013 All Rights Reserved 00004 */ 00005 #ifndef _QI_PERIODICTASK_HPP_ 00006 #define _QI_PERIODICTASK_HPP_ 00007 00008 #include <string> 00009 00010 #include <boost/function.hpp> 00011 #include <boost/utility.hpp> 00012 00013 #include <qi/atomic.hpp> 00014 #include <qi/future.hpp> 00015 #include <qi/stats.hpp> 00016 #include <qi/trackable.hpp> 00017 00018 namespace qi 00019 { 00020 struct PeriodicTaskPrivate; 00023 class QI_API PeriodicTask: public boost::noncopyable 00024 { 00025 public: 00026 typedef boost::function<void()> Callback; 00027 00028 PeriodicTask(); 00029 00030 ~PeriodicTask(); 00031 00033 00037 void setCallback(const Callback& cb); 00038 #ifdef DOXYGEN 00039 template<typename T, typename ARG0> PeriodicTask& setCallback(const T& callable, ARG0 tracked, ...); 00040 #else 00041 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \ 00042 template<typename AF, typename ARG0 comma ATYPEDECL> \ 00043 inline void setCallback(const AF& fun, const ARG0& arg0 comma ADECL) \ 00044 { \ 00045 setCallback(::qi::bind<void()>(fun, arg0 comma AUSE)); \ 00046 } 00047 QI_GEN(genCall) 00048 #undef genCall 00049 #endif 00050 00059 void setUsPeriod(qi::int64_t usPeriod); 00060 00065 void start(bool immediate = true); 00066 00072 void stop(); 00073 00077 void asyncStop(); 00078 00082 void compensateCallbackTime(bool compensate); 00083 00085 void setName(const std::string& name); 00086 00088 bool isRunning() const; 00089 00094 bool isStopping() const; 00095 private: 00096 boost::shared_ptr<PeriodicTaskPrivate> _p; 00097 }; 00098 00099 } 00100 #endif