1 // FGEventMgr.hxx -- Flight Gear periodic event scheduler
3 // Written by Curtis Olson, started December 1997.
4 // Modified by Bernie Bright, April 2002.
6 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #ifndef FG_EVENT_MGR_H_INCLUDED
25 #define FG_EVENT_MGR_H_INCLUDED 1
27 #include <boost/function.hpp>
29 #include <simgear/compiler.h>
30 #include <simgear/timing/timestamp.hxx>
32 #include <Main/fgfs.hxx>
42 class FGEventMgr : public FGSubsystem
55 typedef boost::function<void> callback_type;
56 typedef int interval_type;
71 FGEvent( const string& desc,
86 status = FG_EVENT_READY;
87 ms_to_go = interval_ms;
91 * Execute this event's callback.
96 * Display event statistics.
98 void print_stats() const;
101 * Update the elapsed time for this event.
102 * @param dt_ms elapsed time in milliseconds.
103 * @return true if elapsed time has expired.
105 bool update( int dt_ms )
107 if (status != FG_EVENT_READY)
111 return ms_to_go <= 0;
116 callback_type callback;
118 interval_type interval_ms;
121 unsigned long cum_time; // cumulative processor time of this event
122 unsigned long min_time; // time of quickest execution
123 unsigned long max_time; // time of slowest execution
124 unsigned long count; // number of times executed
132 * Initialize the scheduling subsystem.
141 * Update the elapsed time for all events.
142 * @param dt elapsed time in milliseconds.
144 void update( int dt );
147 * Register a function to be executed every 'interval' milliseconds.
148 * @param desc A brief description of this callback for logging.
149 * @param cb The callback function to be executed.
151 * @param interval Callback repetition rate in milliseconds.
153 void Register( const string& desc,
156 interval_type interval_ms );
161 void Register( const string& desc,
163 interval_type interval_ms )
165 this->Register( desc, cb, FG_EVENT_READY, interval_ms );
169 * Display statistics for all registered events.
171 void print_stats() const;
175 typedef vector< FGEvent > event_container_type;
177 // Registered events.
178 event_container_type event_table;
181 extern FGEventMgr global_events;
183 #endif //FG_ EVENT_MGR_H_INCLUDED