| #pragma once |
| |
| #ifndef TTIMER_INCLUDED |
| #define TTIMER_INCLUDED |
| |
| #include <memory> |
| |
| #include "tcommon.h" |
| |
| #undef DVAPI |
| #undef DVVAR |
| #ifdef TAPPTOOLS_EXPORTS |
| #define DVAPI DV_EXPORT_API |
| #define DVVAR DV_EXPORT_VAR |
| #else |
| #define DVAPI DV_IMPORT_API |
| #define DVVAR DV_IMPORT_VAR |
| #endif |
| |
| |
| |
| class DVAPI TGenericTimerAction { |
| public: |
| virtual ~TGenericTimerAction() {} |
| virtual void sendCommand(TUINT64 tick) = 0; |
| }; |
| |
| |
| |
| template <class T> |
| class TTimerAction final : public TGenericTimerAction { |
| public: |
| typedef void (T::*Method)(TUINT64 tick); |
| TTimerAction(T *target, Method method) : m_target(target), m_method(method) {} |
| void sendCommand(TUINT64 tick) override { (m_target->*m_method)(tick); } |
| |
| private: |
| T *m_target; |
| Method m_method; |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| class DVAPI TTimer { |
| public: |
| |
| |
| |
| enum Type { |
| OneShot, |
| |
| Periodic |
| }; |
| |
| |
| |
| |
| |
| |
| TTimer(const std::string &name, UINT timerRes, Type type); |
| |
| |
| |
| ~TTimer(); |
| |
| |
| |
| |
| void start(UINT delay); |
| |
| |
| |
| |
| void stop(); |
| |
| |
| |
| bool isStarted() const; |
| |
| |
| |
| std::string getName() const; |
| |
| |
| |
| TUINT64 getTicks() const; |
| |
| |
| |
| UINT getDelay() const; |
| |
| |
| |
| |
| void setAction(TGenericTimerAction *action); |
| |
| class Imp; |
| |
| private: |
| std::unique_ptr<Imp> m_imp; |
| |
| TTimer(const TTimer &); |
| void operator=(const TTimer &); |
| }; |
| |
| #endif |