1 // event.hxx -- Flight Gear periodic event scheduler
3 // Written by Curtis Olson, started December 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 // (Log is kept at end of this file)
30 # error This library requires C++
34 #if defined ( __sun__ ) || defined ( __sgi )
35 extern "C" void *memmove(void *, const void *, size_t);
36 extern "C" void *memset(void *, int, size_t);
40 #include <deque> // STL double ended queue
41 #include <list> // STL list
44 #include "Include/fg_stl_config.h"
46 #ifdef _FG_NEED_AUTO_PTR
47 # include "Include/auto_ptr.hxx"
52 #include "Include/fg_callback.hxx"
54 #ifdef NEEDNAMESPACESTD
58 #include "fg_time.hxx"
71 fgEVENT() {} // Required by deque<>.
73 fgEVENT( const string& desc,
78 fgEVENT( const fgEVENT& evt );
84 // void PrintStats() const;
85 int PrintStats() const;
91 // The callback object.
92 // We wrap it in an auto_ptr<> because deque<> calls our copy ctor
93 // and dtor when inserting and removing.
94 auto_ptr<fgCallback> event_cb;
96 EventState status; // status flag
98 long interval; // interval in ms between each iteration of this event
100 fg_timestamp last_run;
101 fg_timestamp current;
102 fg_timestamp next_run;
104 long cum_time; // cumulative processor time of this event
105 long min_time; // time of quickest execution
106 long max_time; // time of slowest execution
107 long count; // number of times executed
114 deque < fgEVENT > event_table;
117 list < fgEVENT * > run_queue;
122 fgEVENT_MGR ( void );
124 // Initialize the scheduling subsystem
127 // Register an event with the scheduler
128 void Register( const string& desc, void (*event)( void ),
129 fgEVENT::EventState status, int interval) {
130 Register( desc, fgFunctionCallback(event), status, interval );
133 void Register( const string& desc,
134 const fgCallback& cb,
135 fgEVENT::EventState status,
138 // Update the scheduling parameters for an event
141 // Delete a scheduled event
144 // Temporarily suspend scheduling of an event
145 void Suspend( void );
147 // Resume scheduling and event
150 // Dump scheduling stats
151 void PrintStats( void );
153 // Add pending jobs to the run queue and run the job at the front
155 void Process( void );
158 ~fgEVENT_MGR ( void );
162 // Wrapper to dump scheduling stats
163 void fgEventPrintStats( void );
165 extern fgEVENT_MGR global_events;
172 // Revision 1.11 1998/09/15 02:09:30 curt
173 // Include/fg_callback.hxx
174 // Moved code inline to stop g++ 2.7 from complaining.
176 // Simulator/Time/event.[ch]xx
177 // Changed return type of fgEVENT::printStat(). void caused g++ 2.7 to
178 // complain bitterly.
180 // Minor bugfix and changes.
182 // Simulator/Main/GLUTmain.cxx
183 // Added missing type to idle_state definition - eliminates a warning.
185 // Simulator/Main/fg_init.cxx
186 // Changes to airport lookup.
188 // Simulator/Main/options.cxx
189 // Uses fg_gzifstream when loading config file.
191 // Revision 1.10 1998/09/08 21:41:06 curt
192 // Added constructor for fgEVENT.
194 // Revision 1.9 1998/09/02 14:37:45 curt
195 // Renamed struct -> class.
197 // Revision 1.8 1998/08/29 13:11:32 curt
198 // Bernie Bright writes:
199 // I've created some new classes to enable pointers-to-functions and
200 // pointers-to-class-methods to be treated like objects. These objects
201 // can be registered with fgEVENT_MGR.
203 // File "Include/fg_callback.hxx" contains the callback class defns.
205 // Modified fgEVENT and fgEVENT_MGR to use the callback classes. Also
206 // some minor tweaks to STL usage.
208 // Added file "Include/fg_stl_config.h" to deal with STL portability
209 // issues. I've added an initial config for egcs (and probably gcc-2.8.x).
210 // I don't have access to Visual C++ so I've left that for someone else.
211 // This file is influenced by the stl_config.h file delivered with egcs.
213 // Added "Include/auto_ptr.hxx" which contains an implementation of the
214 // STL auto_ptr class which is not provided in all STL implementations
215 // and is needed to use the callback classes.
217 // Deleted fgLightUpdate() which was just a wrapper to call
218 // fgLIGHT::Update().
220 // Modified fg_init.cxx to register two method callbacks in place of the
221 // old wrapper functions.
223 // Revision 1.7 1998/07/30 23:48:54 curt
227 // Revision 1.6 1998/07/24 21:42:25 curt
228 // Output message tweaks.
230 // Revision 1.5 1998/07/13 21:02:07 curt
231 // Wrote access functions for current fgOPTIONS.
233 // Revision 1.4 1998/06/12 00:59:52 curt
234 // Build only static libraries.
235 // Declare memmove/memset for Sloaris.
236 // Rewrote fg_time.c routine to get LST start seconds to better handle
237 // Solaris, and be easier to port, and understand the GMT vs. local
240 // Revision 1.3 1998/06/03 00:48:12 curt
241 // No .h for STL includes.
243 // Revision 1.2 1998/05/22 21:14:54 curt
244 // Rewrote event.cxx in C++ as a class using STL for the internal event list
245 // and run queue this removes the arbitrary list sizes and makes things much
246 // more dynamic. Because this is C++-classified we can now have multiple
247 // event_tables if we'd ever want them.
249 // Revision 1.1 1998/04/24 00:52:26 curt
250 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
252 // Separated out lighting calcs into their own file.
254 // Revision 1.4 1998/04/21 17:01:43 curt
255 // Fixed a problems where a pointer to a function was being passed around. In
256 // one place this functions arguments were defined as ( void ) while in another
257 // place they were defined as ( int ). The correct answer was ( int ).
259 // Prepairing for C++ integration.
261 // Revision 1.3 1998/01/22 02:59:43 curt
262 // Changed #ifdef FILE_H to #ifdef _FILE_H
264 // Revision 1.2 1998/01/19 18:40:39 curt
265 // Tons of little changes to clean up the code and to remove fatal errors
266 // when building with the c++ compiler.
268 // Revision 1.1 1997/12/30 04:19:22 curt