00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __SUBSYSTEM_MGR_HXX
00023 #define __SUBSYSTEM_MGR_HXX 1
00024
00025
00026 #include <simgear/compiler.h>
00027
00028 #include <string>
00029 #include <map>
00030 #include <vector>
00031
00032 using std::map;
00033 using std::vector;
00034 using std::string;
00035
00036 #include <simgear/props/props.hxx>
00037 #include <simgear/timing/timestamp.hxx>
00038 #include "SGSmplstat.hxx"
00039
00040
00041 class TimingInfo
00042 {
00043 private:
00044 string eventName;
00045 SGTimeStamp time;
00046
00047 public:
00048 TimingInfo(const string& name, const SGTimeStamp &t) :
00049 eventName(name), time(t)
00050 { }
00051 const string& getName() const { return eventName; }
00052 const SGTimeStamp& getTime() const { return time; }
00053 };
00054
00055 typedef vector<TimingInfo> eventTimeVec;
00056 typedef vector<TimingInfo>::iterator eventTimeVecIterator;
00057
00058
00059
00128 class SGSubsystem : public SGReferenced
00129 {
00130 public:
00131
00135 SGSubsystem ();
00136
00140 virtual ~SGSubsystem ();
00141
00142
00152 virtual void init ();
00153
00154
00164 virtual void postinit ();
00165
00166
00173 virtual void reinit ();
00174
00175
00183 virtual void bind ();
00184
00185
00193 virtual void unbind ();
00194
00195
00205 virtual void update (double delta_time_sec) = 0;
00206
00207
00220 virtual void suspend ();
00221
00222
00229 virtual void suspend (bool suspended);
00230
00231
00240 virtual void resume ();
00241
00242
00248 virtual bool is_suspended () const;
00249
00250
00258 void updateExecutionTime(double time);
00259
00270 void printTimingInformation();
00271
00276 void stamp(const string& name);
00277
00278
00279
00280 protected:
00281
00282 bool _suspended;
00283
00284 eventTimeVec timingInfo;
00285
00286
00287 };
00288
00289
00290
00294 class SGSubsystemGroup : public SGSubsystem
00295 {
00296 public:
00297
00298 SGSubsystemGroup ();
00299 virtual ~SGSubsystemGroup ();
00300
00301 virtual void init ();
00302 virtual void postinit ();
00303 virtual void reinit ();
00304 virtual void bind ();
00305 virtual void unbind ();
00306 virtual void update (double delta_time_sec);
00307 virtual void suspend ();
00308 virtual void resume ();
00309 virtual bool is_suspended () const;
00310
00311 virtual void set_subsystem (const string &name,
00312 SGSubsystem * subsystem,
00313 double min_step_sec = 0);
00314 virtual SGSubsystem * get_subsystem (const string &name);
00315 virtual void remove_subsystem (const string &name);
00316 virtual bool has_subsystem (const string &name) const;
00317
00318 void collectDebugTiming(bool collect);
00319
00320 private:
00321
00322 class Member {
00323
00324 private:
00325 Member (const Member &member);
00326 public:
00327 Member ();
00328 virtual ~Member ();
00329
00330 virtual void update (double delta_time_sec);
00331 void printTimingInformation(double time);
00332 void printTimingStatistics();
00333 void updateExecutionTime(double time);
00334 double getTimeWarningThreshold();
00335 void collectDebugTiming (bool collect) { collectTimeStats = collect; };
00336
00337 SampleStatistic timeStat;
00338 string name;
00339 SGSubsystem * subsystem;
00340 double min_step_sec;
00341 double elapsed_sec;
00342 bool collectTimeStats;
00343 };
00344
00345 Member * get_member (const string &name, bool create = false);
00346
00347 vector<Member *> _members;
00348 };
00349
00350
00351
00369 class SGSubsystemMgr : public SGSubsystem
00370 {
00371 public:
00372
00376 enum GroupType {
00377 INIT = 0,
00378 GENERAL,
00379 MAX_GROUPS
00380 };
00381
00382 SGSubsystemMgr ();
00383 virtual ~SGSubsystemMgr ();
00384
00385 virtual void init ();
00386 virtual void postinit ();
00387 virtual void reinit ();
00388 virtual void bind ();
00389 virtual void unbind ();
00390 virtual void update (double delta_time_sec);
00391 virtual void suspend ();
00392 virtual void resume ();
00393 virtual bool is_suspended () const;
00394
00395 virtual void add (const char * name,
00396 SGSubsystem * subsystem,
00397 GroupType group = GENERAL,
00398 double min_time_sec = 0);
00399
00400 virtual SGSubsystemGroup * get_group (GroupType group);
00401
00402 virtual SGSubsystem * get_subsystem(const string &name);
00403
00404 void collectDebugTiming(bool collect);
00405
00406 private:
00407
00408 SGSubsystemGroup _groups[MAX_GROUPS];
00409 map<string,SGSubsystem *> _subsystem_map;
00410
00411 };
00412
00413
00414
00415 #endif // __SUBSYSTEM_MGR_HXX
00416