www.pudn.com > rDUNclientBeta1.zip > Timer.h


//Timer.h - Generic timing engine and basic time/date functions 
//Copyright (C) Robert Merrison 2001  
 
//This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License  
//as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 
//This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied  
//warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 
//You should have received a copy of the GNU General Public License along with this program; if not, write to the  
//Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 
#ifndef _TIMER_H_ 
#define _TIMER_H_ 
 
#include  
#include  
#include "debug.h" 
 
#define OS_WINDOWS 1 
#define OS_LINUX 2 
#define OS_OTHER 3 
 
/*Cross-platform stuff*/ 
#ifdef WIN32 
	#define OS 1	//Operating system is windows 
	#include  
#else 
	#ifdef linux 
		#define OS 2	//Operating system is linux 
		#include  
#else 
	#define OS 3	//Unknown/incompatible OS 
#endif 
#endif 
 
/*Simple struct for a time inteval*/ 
struct	time_period{ 
	short	seconds; 
	short	minutes; 
	short	hours; 
	short	days; 
}; 
 
/*Event to get in the list of events*/ 
struct	event{ 
	void	( *target )( void ); 
	short	repetitions; 
	int		interval; 
	int		counter; 
	event*	next_event; 
	event*	previous_event; 
}; 
 
/*Main timer engine class*/ 
class	time_engine{ 
public: 
	bool	init( debug_engine* debug = NULL ); 
	void	update(); 
	void	kill(); 
	bool	is_running(); 
	event*	create_timer( void (*target)(void), time_period interval, short repetitions );  
	bool	kill_timer( event* event_to_kill ); 
	bool	kill_all_timers(); 
	tm		get_current_time(); 
private: 
	void	log_timer_message( short msg_type, char* message, ... ); 
	void	update_timers(); 
	void	advance_timer_list( int number_of_seconds ); 
	void	decrease_timer( event* event_to_decrease, int number_of_seconds ); 
	void	reset_timer( event* event_to_reset ); 
	int		time_to_seconds( time_period time ); 
	 
	debug_engine*	dbg_engine; 
	bool	engine_running; 
	time_period	uptime; 
	event*	first_event; 
	event*	last_event; 
	int		event_count; 
 
	time_t	previous_time; 
 
}; 
 
#endif