]> git.mxchange.org Git - flightgear.git/blob - Time/event.hxx
Wrote access functions for current fgOPTIONS.
[flightgear.git] / Time / event.hxx
1 // event.hxx -- Flight Gear periodic event scheduler
2 //
3 // Written by Curtis Olson, started December 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22 // (Log is kept at end of this file)
23
24
25 #ifndef _EVENT_HXX
26 #define _EVENT_HXX
27
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33
34 #ifdef __sun__
35 extern "C" void *memmove(void *, const void *, size_t);
36 extern "C" void *memset(void *, int, size_t);
37 #endif
38
39
40 #include <deque>        // STL double ended queue
41 #include <list>         // STL list
42 #ifdef NEEDNAMESPACESTD
43 using namespace std;
44 #endif
45
46 #include "fg_time.hxx"
47
48
49 #define FG_EVENT_SUSP 0
50 #define FG_EVENT_READY 1
51 #define FG_EVENT_QUEUED 2
52
53
54 typedef struct {
55     char description[256];
56
57     void (*event)( void );  // pointer to function
58     int status;       // status flag
59
60     long interval;    // interval in ms between each iteration of this event
61
62     fg_timestamp last_run;
63     fg_timestamp current;
64     fg_timestamp next_run;
65
66     long cum_time;    // cumulative processor time of this event
67     long min_time;    // time of quickest execution
68     long max_time;    // time of slowest execution
69     long count;       // number of times executed
70 } fgEVENT;
71
72
73 class fgEVENT_MGR {
74
75     // Event table
76     deque < fgEVENT > event_table;
77
78     // Run Queue
79     list < fgEVENT * > run_queue;
80
81 public:
82
83     // Constructor
84     fgEVENT_MGR ( void );
85
86     // Initialize the scheduling subsystem
87     void Init( void );
88
89     // Register an event with the scheduler
90     void Register(char *desc, void (*event)( void ), int status, 
91                          int interval);
92
93     // Update the scheduling parameters for an event
94     void Update( void );
95
96     // Delete a scheduled event
97     void Delete( void );
98
99     // Temporarily suspend scheduling of an event
100     void Suspend( void );
101
102     // Resume scheduling and event
103     void Resume( void );
104
105     // Dump scheduling stats
106     void PrintStats( void );
107
108     // Add pending jobs to the run queue and run the job at the front
109     // of the queue
110     void Process( void );
111
112     // Destructor
113     ~fgEVENT_MGR ( void );
114 };
115
116
117 // Wrapper to dump scheduling stats
118 void fgEventPrintStats( void );
119
120 extern fgEVENT_MGR global_events;
121
122
123 #endif // _EVENT_HXX
124
125
126 // $Log$
127 // Revision 1.5  1998/07/13 21:02:07  curt
128 // Wrote access functions for current fgOPTIONS.
129 //
130 // Revision 1.4  1998/06/12 00:59:52  curt
131 // Build only static libraries.
132 // Declare memmove/memset for Sloaris.
133 // Rewrote fg_time.c routine to get LST start seconds to better handle
134 //   Solaris, and be easier to port, and understand the GMT vs. local
135 //   timezone issues.
136 //
137 // Revision 1.3  1998/06/03 00:48:12  curt
138 // No .h for STL includes.
139 //
140 // Revision 1.2  1998/05/22 21:14:54  curt
141 // Rewrote event.cxx in C++ as a class using STL for the internal event list
142 // and run queue this removes the arbitrary list sizes and makes things much
143 // more dynamic.  Because this is C++-classified we can now have multiple
144 // event_tables if we'd ever want them.
145 //
146 // Revision 1.1  1998/04/24 00:52:26  curt
147 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
148 // Fog color fixes.
149 // Separated out lighting calcs into their own file.
150 //
151 // Revision 1.4  1998/04/21 17:01:43  curt
152 // Fixed a problems where a pointer to a function was being passed around.  In
153 // one place this functions arguments were defined as ( void ) while in another
154 // place they were defined as ( int ).  The correct answer was ( int ).
155 //
156 // Prepairing for C++ integration.
157 //
158 // Revision 1.3  1998/01/22 02:59:43  curt
159 // Changed #ifdef FILE_H to #ifdef _FILE_H
160 //
161 // Revision 1.2  1998/01/19 18:40:39  curt
162 // Tons of little changes to clean up the code and to remove fatal errors
163 // when building with the c++ compiler.
164 //
165 // Revision 1.1  1997/12/30 04:19:22  curt
166 // Initial revision.
167