5 #include <simgear/compiler.h>
6 #include <simgear/debug/logstream.hxx>
8 #include <boost/bind.hpp>
10 #include "FGEventMgr.hxx"
12 FGEventMgr::FGEvent::FGEvent()
13 : status(FG_EVENT_SUSP),
23 FGEventMgr::FGEvent::FGEvent( const string& desc,
40 FGEventMgr::FGEvent::~FGEvent()
45 FGEventMgr::FGEvent::run()
47 SGTimeStamp start_time;
48 SGTimeStamp finish_time;
59 unsigned long duration = finish_time - start_time;
63 if ( duration < min_time ) {
67 if ( duration > max_time ) {
75 FGEventMgr::FGEvent::print_stats() const
77 SG_LOG( SG_EVENT, SG_INFO,
79 << " int=" << interval_ms / 1000.0
80 << " cum=" << cum_time
81 << " min=" << min_time
82 << " max=" << max_time
84 << " ave=" << cum_time / (double)count );
87 FGEventMgr::FGEventMgr()
91 FGEventMgr::~FGEventMgr()
98 SG_LOG( SG_EVENT, SG_INFO, "Initializing event manager" );
114 FGEventMgr::update( int dt )
116 // Scan all events. Execute any whose interval has expired.
117 event_container_type::iterator first = event_table.begin();
118 event_container_type::iterator last = event_table.end();
119 for(; first != last; ++first)
121 if (first->update( dt ))
129 FGEventMgr::Register( const string& desc,
134 FGEvent event( desc, cb, state, ms );
135 if (state == FG_EVENT_READY)
137 event_table.push_back( event );
139 SG_LOG( SG_EVENT, SG_INFO, "Registered event " << desc
140 << " to run every " << ms << "ms" );
144 FGEventMgr::print_stats() const
146 SG_LOG( SG_EVENT, SG_INFO, "" );
147 SG_LOG( SG_EVENT, SG_INFO, "Event Stats" );
148 SG_LOG( SG_EVENT, SG_INFO, "-----------" );
150 std::for_each( event_table.begin(), event_table.end(),
151 boost::bind( &FGEvent::print_stats, _1 ) );
153 SG_LOG( SG_EVENT, SG_INFO, "" );