
#ifndef __WFX_KERNEL_TIMER_H__
#define __WFX_KERNEL_TIMER_H__

#include <WFX/WFXIncludes.h>

namespace WFX {

    namespace kernel {

        /**
         * TimerListener interface
         **/
        class TimerListener {
            public:
                /**
                 * Called whenever the Timer interval has passed
                 */
                virtual void timerEvent(int id) = 0;
        };

        
        /**
         * Timer class - once instanciated it calls any associated 
         * Timerlistener whenever the given amount of time has passed
         * This is not a very reliable method of time measurement, and gets
         * _very_ unreliable if the Interval is shorter than the time difference
         * between two frames
         */
        class Timer {
            public:
                /** 
                 * enum describing different Timer methods
                 */
                enum TimerMode {
                    TM_ONCE,                //fire event only once, stop() self after event occured
                    TM_CONTINUOUS           //fire events as long as not stop()'ed
                };
                
                /**
                 * Ctor
                 * @param: mode - Timer mode
                 * @param: time - Timer interval in Microseconds
                 * @param: l - the TimerListener
                 * @param: id - integer that is returned to the TimerListener
                 */
                Timer(TimerMode mode, ULong time, TimerListener* l, Int id);

                /**
                 * starts this timer
                 */
                void start();

                /**
                 * stops this Timer
                 */
                void stop();

            protected:
                /** Timer id */
                Int Id;
                /** Timer interval */
                ULong Interval; 
                /** Interval start */
                ULong Start;
                /** Mode */
                TimerMode Mode;
                /** Listener */
                TimerListener* Listener;
                
            private:
                friend class TimeTask;
                /**
                 * update method - called once each frame by TimeTask
                 */
                void update();
                

        };

    }

}


#endif //include guard


