#ifndef __KERNEL_TIMER_H
#define __KERNEL_TIMER_H

#include <cpp/Uncopyable.h>
#include <List.h>
#include <kernel/Spinlock.h>

namespace OS {
namespace Kernel {
	class Timer;
	class TimerQueue;

	typedef enum handlerReturn (*timerCallback)(Timer *timer, void *data, time_t now);

	// Timer struct
	class Timer : private Uncopyable {
	  public:
		Timer() : mQueueNode(this), mQueue(0) {}
		~Timer() { if (mQueueNode.IsInList()) Clear(); }

		time_t SetPeriodic(timerCallback callback, void *data, time_t period);
		time_t SetOneshot(timerCallback callback, void *data, time_t delay);
		status_t Clear();
		void Dump();

	  private:
		ListNode<Timer> mQueueNode;
		TimerQueue *mQueue;
		time_t mScheduledTime;
		time_t mPeriod;
		bool mPeriodic;
		timerCallback mCallback;
		void *mData;
		friend class TimerQueue;
	};
}} // namespace OS::Kernel

#endif
