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/fg_time.hxx>
36 #include <Include/fg_callback.hxx>
38 #include <deque> // STL double ended queue
39 #include <list> // STL list
42 #include "timestamp.hxx"
59 friend class fgEVENT_MGR;
61 fgEVENT() {} // Required by deque<>.
63 fgEVENT( const string& desc,
65 EventState evt_status,
72 // void PrintStats() const;
73 int PrintStats() const;
77 fgEVENT( const fgEVENT& evt );
78 fgEVENT& operator= ( const fgEVENT& evt );
84 // The callback object.
87 EventState status; // status flag
89 long interval; // interval in ms between each iteration of this event
95 long cum_time; // cumulative processor time of this event
96 long min_time; // time of quickest execution
97 long max_time; // time of slowest execution
98 long count; // number of times executed
105 typedef deque < fgEVENT* > EventContainer;
106 typedef EventContainer::iterator EventIterator;
107 typedef EventContainer::const_iterator ConstEventIterator;
109 EventContainer event_table;
112 typedef list < fgEVENT * > RunContainer;
114 RunContainer run_queue;
119 fgEVENT_MGR ( void );
121 // Initialize the scheduling subsystem
124 // Register an event with the scheduler
125 void Register( const string& desc, void (*event)( void ),
126 fgEVENT::EventState status, int interval) {
127 Register( desc, fgFunctionCallback(event), status, interval );
130 void Register( const string& desc,
131 const fgCallback& cb,
132 fgEVENT::EventState status,
135 // Update the scheduling parameters for an event
138 // Delete a scheduled event
141 // Temporarily suspend scheduling of an event
142 void Suspend( void );
144 // Resume scheduling and event
147 // Dump scheduling stats
148 void PrintStats( void );
150 // Add pending jobs to the run queue and run the job at the front
152 void Process( void );
155 ~fgEVENT_MGR ( void );
159 // Wrapper to dump scheduling stats
160 void fgEventPrintStats( void );
162 extern fgEVENT_MGR global_events;