]> git.mxchange.org Git - flightgear.git/commitdiff
Broadcast suspend/resume/reinit through the manager and its groups.
authordavid <david>
Thu, 16 Jan 2003 15:11:04 +0000 (15:11 +0000)
committerdavid <david>
Thu, 16 Jan 2003 15:11:04 +0000 (15:11 +0000)
src/Main/fgfs.cxx
src/Main/fgfs.hxx

index 4569a4e5a9c8a00287e7cedbf179fff5cc0167e8..fda5ddf4ef2851a8a6a81cf81331a051ced0afec 100644 (file)
@@ -1,6 +1,7 @@
 #include "fgfs.hxx"
 
 #include <simgear/debug/logstream.hxx>
+#include <simgear/misc/exception.hxx>
 
 #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<string,FGSubsystem *>::iterator s =_subsystem_map.find(name);
+
+    if (s == _subsystem_map.end())
+        return 0;
+    else
+        return s->second;
+}
+
 // end of fgfs.cxx
index ea217c2f8c5dafc46bf386917668f061c20afd38..08a335a6267d9feeaa888581c9baca4a38d65eab 100644 (file)
@@ -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:
 
 \f
 /**
- * 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<string,FGSubsystem *> _subsystem_map;
 
 };