#ifndef _TIMER_H_
#define _TIMER_H_

#include "CObjectBase.h"
#include "mmsystem.h"

#define TIMER_RESOLUTION  10

#define NO_TIMER -1

#ifdef SCOL
extern int (*mt_start)(int per,int param,int (*fun)(int i,int param));
extern int (*mt_del)(int i);
#endif

typedef struct SElement
{
	int ID;
#ifndef SCOL
	int frequency;
	CObjectBase *object;
#endif
	struct SElement *next;
} TimedElement;

#ifdef SCOL
// on est oblige de maintenir une liste des identifiants des timers demandes
// pour les detruire a la destruction de l'ObjTimer
typedef struct STimersList
{
	int id;
	struct STimersList *next;
} TimersList;
#endif


class CObjTimer
{
private:
	TimedElement *WatchedElements;
#ifndef SCOL
	static long IDcount;
	long ElementsCount;
	UINT timerID;
	DWORD lastTick;

	int StartTimer( UINT );
	int StopTimer( );
	TimedElement *AddEvent( TimedElement *, TimedElement *, DWORD, DWORD, int );
	TimedElement *RemoveEvent( TimedElement *, int, int );
	friend void CALLBACK CObjTimerCallback( UINT, UINT, DWORD, DWORD, DWORD );
#else
	TimersList *list;

	TimedElement *AddEvent( TimedElement *, TimedElement * );
	TimedElement *RemoveEvent( TimedElement *, int );
#endif
public:
	CObjTimer( );
	~CObjTimer( );

	int Register( int frequency, CObjectBase *object );
	int Unregister( int ID );
};
#endif
