From: david Date: Thu, 16 Jan 2003 15:11:04 +0000 (+0000) Subject: Broadcast suspend/resume/reinit through the manager and its groups. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b2518a0056e01a10e5fb69e04129f266a545dae3;p=flightgear.git Broadcast suspend/resume/reinit through the manager and its groups. --- diff --git a/src/Main/fgfs.cxx b/src/Main/fgfs.cxx index 4569a4e5a..fda5ddf4e 100644 --- a/src/Main/fgfs.cxx +++ b/src/Main/fgfs.cxx @@ -1,6 +1,7 @@ #include "fgfs.hxx" #include +#include #include "globals.hxx" #include "fg_props.hxx" @@ -90,6 +91,13 @@ FGSubsystemGroup::init () _members[i]->subsystem->init(); } +void +FGSubsystemGroup::reinit () +{ + for (int i = 0; i < _members.size(); i++) + _members[i]->subsystem->reinit(); +} + void FGSubsystemGroup::bind () { @@ -113,6 +121,28 @@ FGSubsystemGroup::update (double delta_time_sec) } } +void +FGSubsystemGroup::suspend () +{ + FGSubsystem::suspend(); + for (int i = 0; i < _members.size(); i++) + _members[i]->subsystem->suspend(); +} + +void +FGSubsystemGroup::resume () +{ + FGSubsystem::resume(); + for (int i = 0; i < _members.size(); i++) + _members[i]->subsystem->resume(); +} + +bool +FGSubsystemGroup::is_suspended () const +{ + return FGSubsystem::is_suspended(); +} + void FGSubsystemGroup::set_subsystem (const string &name, FGSubsystem * subsystem, double min_step_sec) @@ -226,6 +256,13 @@ FGSubsystemMgr::init () _groups[i].init(); } +void +FGSubsystemMgr::reinit () +{ + for (int i = 0; i < MAX_GROUPS; i++) + _groups[i].reinit(); +} + void FGSubsystemMgr::bind () { @@ -249,12 +286,40 @@ FGSubsystemMgr::update (double delta_time_sec) } } +void +FGSubsystemMgr::suspend () +{ + FGSubsystem::suspend(); + for (int i = 0; i < MAX_GROUPS; i++) + _groups[i].suspend(); +} + +void +FGSubsystemMgr::resume () +{ + FGSubsystem::resume(); + for (int i = 0; i < MAX_GROUPS; i++) + _groups[i].resume(); +} + +bool +FGSubsystemMgr::is_suspended () const +{ + return FGSubsystem::is_suspended(); +} + void FGSubsystemMgr::add (GroupType group, const string &name, FGSubsystem * subsystem, double min_time_sec) { SG_LOG(SG_GENERAL, SG_INFO, "Adding subsystem " << name); get_group(group)->set_subsystem(name, subsystem, min_time_sec); + + if (_subsystem_map.find(name) != _subsystem_map.end()) { + SG_LOG(SG_GENERAL, SG_ALERT, "Adding duplicate subsystem " << name); + throw sg_exception("duplicate subsystem"); + } + _subsystem_map[name] = subsystem; } FGSubsystemGroup * @@ -263,4 +328,15 @@ FGSubsystemMgr::get_group (GroupType group) return &(_groups[group]); } +FGSubsystem * +FGSubsystemMgr::get_subsystem (const string &name) +{ + map::iterator s =_subsystem_map.find(name); + + if (s == _subsystem_map.end()) + return 0; + else + return s->second; +} + // end of fgfs.cxx diff --git a/src/Main/fgfs.hxx b/src/Main/fgfs.hxx index ea217c2f8..08a335a62 100644 --- a/src/Main/fgfs.hxx +++ b/src/Main/fgfs.hxx @@ -252,9 +252,13 @@ public: virtual ~FGSubsystemGroup (); virtual void init (); + virtual void reinit (); virtual void bind (); virtual void unbind (); virtual void update (double delta_time_sec); + virtual void suspend (); + virtual void resume (); + virtual bool is_suspended () const; virtual void set_subsystem (const string &name, FGSubsystem * subsystem, @@ -287,12 +291,29 @@ private: /** - * Manage subsystems for the application. + * Manage subsystems for FlightGear. + * + * This top-level subsystem will eventually manage all of the + * subsystems in FlightGear: it broadcasts its life-cycle events + * (init, bind, etc.) to all of the subsystems it manages. Subsystems + * are grouped to guarantee order of initialization and execution -- + * currently, the only two groups are INIT and GENERAL, but others + * will appear in the future. + * + * All subsystems are named as well as grouped, and subsystems can be + * looked up by name and cast to the appropriate subtype when another + * subsystem needs to invoke specialized methods. + * + * The subsystem manager owns the pointers to all the subsystems in + * it. */ class FGSubsystemMgr : public FGSubsystem { public: + /** + * Types of subsystem groups. + */ enum GroupType { INIT = 0, GENERAL, @@ -303,9 +324,13 @@ public: virtual ~FGSubsystemMgr (); virtual void init (); + virtual void reinit (); virtual void bind (); virtual void unbind (); virtual void update (double delta_time_sec); + virtual void suspend (); + virtual void resume (); + virtual bool is_suspended () const; virtual void add (GroupType group, const string &name, FGSubsystem * subsystem, @@ -313,9 +338,12 @@ public: virtual FGSubsystemGroup * get_group (GroupType group); + virtual FGSubsystem * get_subsystem(const string &name); + private: FGSubsystemGroup _groups[MAX_GROUPS]; + map _subsystem_map; };