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.
29 # error This library requires C++
33 #include <simgear/compiler.h>
34 #include <simgear/timing/timestamp.hxx>
36 #include <Include/fg_callback.hxx>
38 #include <deque> // STL double ended queue
39 #include <list> // STL list
58 friend class fgEVENT_MGR;
60 fgEVENT() {} // Required by deque<>.
62 fgEVENT( const string& desc,
64 EventState evt_status,
71 // void PrintStats() const;
72 int PrintStats() const;
76 fgEVENT( const fgEVENT& evt );
77 fgEVENT& operator= ( const fgEVENT& evt );
83 // The callback object.
86 EventState status; // status flag
88 long interval; // interval in ms between each iteration of this event
94 long cum_time; // cumulative processor time of this event
95 long min_time; // time of quickest execution
96 long max_time; // time of slowest execution
97 long count; // number of times executed
104 typedef deque < fgEVENT* > EventContainer;
105 typedef EventContainer::iterator EventIterator;
106 typedef EventContainer::const_iterator ConstEventIterator;
108 EventContainer event_table;
111 typedef list < fgEVENT * > RunContainer;
113 RunContainer run_queue;
118 fgEVENT_MGR ( void );
120 // Initialize the scheduling subsystem
123 // Register an event with the scheduler
124 void Register( const string& desc, void (*event)( void ),
125 fgEVENT::EventState status, int interval) {
126 Register( desc, fgFunctionCallback(event), status, interval );
129 void Register( const string& desc,
130 const fgCallback& cb,
131 fgEVENT::EventState status,
134 // Update the scheduling parameters for an event
137 // Delete a scheduled event
140 // Temporarily suspend scheduling of an event
141 void Suspend( void );
143 // Resume scheduling and event
146 // Dump scheduling stats
147 void PrintStats( void );
149 // Add pending jobs to the run queue and run the job at the front
151 void Process( void );
154 ~fgEVENT_MGR ( void );
158 // Wrapper to dump scheduling stats
159 void fgEventPrintStats( void );
161 extern fgEVENT_MGR global_events;