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
Toshihiro Shimizu 890ddd
class DVAPI TGenericTimerAction
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	virtual ~TGenericTimerAction() {}
Toshihiro Shimizu 890ddd
	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>
Toshihiro Shimizu 890ddd
class TTimerAction : public TGenericTimerAction
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef void (T::*Method)(TUINT64 tick);
Toshihiro Shimizu 890ddd
	TTimerAction(T *target, Method method) : m_target(target), m_method(method) {}
Toshihiro Shimizu 890ddd
	void sendCommand(TUINT64 tick) { (m_target->*m_method)(tick); }
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	T *m_target;
Toshihiro Shimizu 890ddd
	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
/*!
Toshihiro Shimizu 890ddd
		This class defines a timer, 
Toshihiro Shimizu 890ddd
		i.e a system which, at user defined time steps, sends events through a callback function.
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
class DVAPI TTimer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
		Specifies which is the type of timer of this object.
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
	enum Type {
Toshihiro Shimizu 890ddd
		OneShot, /*!< This type of timer sends timer events only at a single time. */
Toshihiro Shimizu 890ddd
		Periodic /*!< This type of timer sends timer events periodically. */
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
		Creates a timer with name \p name, resolution \p timerRes and type \p type.
Toshihiro Shimizu 890ddd
		Resolution is expressed in milliseconds.
Toshihiro Shimizu 890ddd
	*/
Shinya Kitaoka 3bfa54
	TTimer(const std::string &name, UINT timerRes, Type type);
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
		Deletes the timer.
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
	~TTimer();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
		Starts the timer after \p delay milliseconds.
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
	void start(UINT delay); // delay expressed in milliseconds
Toshihiro Shimizu 890ddd
							/*!
Toshihiro Shimizu 890ddd
		Stops the timer immediately. 
Toshihiro Shimizu 890ddd
		Doesn't delete the timer.
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
	void stop();
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
		Returns \p true if the timer is started.
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
	bool isStarted() const;
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
		Returns the name of the timer.
Toshihiro Shimizu 890ddd
	*/
Shinya Kitaoka 3bfa54
	std::string getName() const;
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
		Asks the timer for number of events so far.
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
	TUINT64 getTicks() const;
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
		Returns the initial start delay of the timer. 
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
	UINT getDelay() const;
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
		Sets the callback function, i.e. the function to be called every timer's shot.
Toshihiro Shimizu 890ddd
	*/
Toshihiro Shimizu 890ddd
	void setAction(TGenericTimerAction *action);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	class Imp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 262a92
	std::unique_ptr<imp> m_imp;</imp>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TTimer(const TTimer &);
Toshihiro Shimizu 890ddd
	void operator=(const TTimer &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif