#ifndef _COMMON_MMTIMER_HPP_
#define _COMMON_MMTIMER_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _COMMON_CALLBACK_HPP_
#include <common/callback.hpp>
#endif
#ifndef _COMMON_MMSYSTEM_HPP_
#include <common/mmsystem.hpp>
#endif

class MMTimer
{
public:
  MMTimer(void);
	MMTimer(WORD minResolution);
	virtual ~MMTimer();
	static DWORD getSystemTime(void);
	bool startTimer(UINT deltaTime);
	bool stopTimer(void);
	bool isRunning(void)const;
	void insertHandler(PureCallback *lpCallback);
  void removeHandler(void);
protected:
  virtual void timerStarted(void);
	virtual void timerStopped(void);
private:
	static void CALLBACK timerProc(UINT wTimerID,UINT mMsg,DWORD dwUser,DWORD dummyOne,DWORD dummyTwo);
  bool isFirstBreak(void)const;
  void isFirstBreak(bool isFirstBreak);

  TIMECAPS mTimerCapability;
	WORD mMinResolution;
	bool mIsOkay;
	bool mHasTimedEvent;
	bool mIsFirstBreak;
	UINT mTimerID;
  CallbackPointer mCallbackPointer;
};

inline
DWORD MMTimer::getSystemTime(void)
{
	return ::timeGetTime();
}

inline
bool MMTimer::isRunning(void)const
{
  return mHasTimedEvent;
}

inline
void MMTimer::insertHandler(PureCallback *lpCallback)
{
	mCallbackPointer=CallbackPointer(lpCallback);
}

inline
void MMTimer::removeHandler(void)
{
  mCallbackPointer=CallbackPointer();
}

inline
bool MMTimer::isFirstBreak(void)const
{
  return mIsFirstBreak;
}

inline
void MMTimer::isFirstBreak(bool isFirstBreak)
{
  mIsFirstBreak=isFirstBreak;
}
#endif
