timer_driver.h

Go to the documentation of this file.
00001 #ifndef TIMER_DRIVER_CLASS
00002 #define TIMER_DRIVER_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : timer_driver                                                      *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2003-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "opsysdll.h"
00019 
00020 #include <basis/object_base.h>
00021 
00022 // forward.
00023 class driven_objects_list;
00024 class signalling_thread;
00025 class timed_object;
00026 
00028 
00035 class OPSYSTEM_CLASS_STYLE timer_driver : public virtual object_base
00036 {
00037 public:
00038   timer_driver();
00039   virtual ~timer_driver();
00040 
00041   IMPLEMENT_CLASS_NAME("timer_driver");
00042 
00044 
00045   // main methods for controlling timed_objects.
00046 
00047   bool set_timer(int duration, timed_object *to_invoke);
00049 
00052   bool zap_timer(timed_object *to_drop);
00054 
00057 
00058 
00059   // internal methods.
00060 
00061 #ifdef __WIN32__
00062   u_int *real_timer_id();
00064 #endif
00065 
00066   void handle_system_timer();
00068 
00069   static timer_driver &global_timer_driver();
00071 
00072 private:
00073   driven_objects_list *_timers;  
00074   mutex *_lock;  
00075 #ifdef __UNIX__
00076   signalling_thread *_prompter;  
00077 #endif
00078 #ifdef __WIN32__
00079   u_int *_real_timer_id;  
00080 #endif
00081   bool _in_timer;  
00082 
00083   // these do the low-level system magic required to get a function hooked
00084   // to a timer.
00085   void hookup_OS_timer(int duration);
00087   void reset_OS_timer(int next_hit);
00089 
00090   void unhook_OS_timer();
00092 };
00093 
00095 
00096 #define program_wide_timer() timer_driver::global_timer_driver()
00098 
00101 
00102 
00104 
00105 class OPSYSTEM_CLASS_STYLE timed_object
00106 {
00107 public:
00108   virtual ~timed_object();
00109   virtual void handle_timer_callback() = 0;
00111 };
00112 
00114 
00115 #endif
00116 

Generated on Fri Nov 21 04:29:56 2008 for HOOPLE Libraries by  doxygen 1.5.1