Shinya Kitaoka 810553
#pragma once
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
#ifndef TTIMER_INCLUDED
Toshihiro Shimizu 890ddd
#define TTIMER_INCLUDED
Toshihiro Shimizu 890ddd
Shinya Kitaoka 262a92
#include <memory></memory>
Shinya Kitaoka 262a92
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TAPPTOOLS_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TGenericTimerAction {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  virtual ~TGenericTimerAction() {}
Shinya Kitaoka 120a6e
  virtual void sendCommand(TUINT64 tick) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka d1f6c4
class TTimerAction final : public TGenericTimerAction {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef void (T::*Method)(TUINT64 tick);
Shinya Kitaoka 120a6e
  TTimerAction(T *target, Method method) : m_target(target), m_method(method) {}
Shinya Kitaoka 473e70
  void sendCommand(TUINT64 tick) override { (m_target->*m_method)(tick); }
Shinya Kitaoka 120a6e
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  T *m_target;
Shinya Kitaoka 120a6e
  Method m_method;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//! THis class is manages general time events.
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
                This class defines a timer,
Shinya Kitaoka 120a6e
                i.e a system which, at user defined time steps, sends events
Shinya Kitaoka 120a6e
   through a callback function.
Shinya Kitaoka 120a6e
        */
Shinya Kitaoka 120a6e
class DVAPI TTimer {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Specifies which is the type of timer of this object.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  enum Type {
Shinya Kitaoka 120a6e
    OneShot, /*!< This type of timer sends timer events only at a single time.
Shinya Kitaoka 120a6e
                */
Shinya Kitaoka 120a6e
    Periodic /*!< This type of timer sends timer events periodically. */
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Creates a timer with name \p name, resolution \p timerRes and type \p
Shinya Kitaoka 120a6e
     type.
Shinya Kitaoka 120a6e
          Resolution is expressed in milliseconds.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  TTimer(const std::string &name, UINT timerRes, Type type);
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Deletes the timer.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  ~TTimer();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Starts the timer after \p delay milliseconds.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  void start(UINT delay);  // delay expressed in milliseconds
Shinya Kitaoka 120a6e
                           /*!
Shinya Kitaoka 120a6e
Stops the timer immediately.
Shinya Kitaoka 120a6e
Doesn't delete the timer.
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  void stop();
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Returns \p true if the timer is started.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  bool isStarted() const;
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Returns the name of the timer.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  std::string getName() const;
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Asks the timer for number of events so far.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  TUINT64 getTicks() const;
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Returns the initial start delay of the timer.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  UINT getDelay() const;
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
          Sets the callback function, i.e. the function to be called every
Shinya Kitaoka 120a6e
     timer's shot.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  void setAction(TGenericTimerAction *action);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  class Imp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  std::unique_ptr<imp> m_imp;</imp>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TTimer(const TTimer &);
Shinya Kitaoka 120a6e
  void operator=(const TTimer &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif