// timer.h // // by David Hershberger, 11-12-95 // // Timer class is intended to allow the users of it to register a // callback which will happen every nth time we get a timer interrupt, // where n is configurable. #ifndef TIMER_H #define TIMER_H #include struct Callback{ Callback *next; void (* function)(double elapsed_time); int tick_count; int num_ticks; }; // To derive a usable subclass from the abstract Timer class, override // only those items marked for overriding in the class definition // below. // For a sample derived class, see clemtime.h and clemtime.cpp. class Timer{ private: int changing_list; int doing_callback_list; Callback *doing_this_callback; Callback *callback_list; virtual void setup(); friend void timer_handler(); protected: double tick_interval; virtual void install_timer_handler(void(*)()) = 0; // override virtual void set_tick_interval() = 0; // override public: Timer(); virtual ~Timer(); virtual double read_tick_interval(); virtual void add_callback(void (* callback_fn)(double elapsed_time), int numticks, int offset); virtual void delete_callback(void (* callback_fn)(double elapsed_time), int numticks); virtual void close() = 0; // override. close() should uninstall the // timer handler }; // There is only one timer per computer, so declare it a global // constant. Define it not in timer.cpp, but in clemtimer.cpp or // whereever the computer-specific version is derived. extern Timer * const timer; #endif // TIMER_H