#include "fgfs.hxx"
#include <simgear/debug/logstream.hxx>
+#include <simgear/misc/exception.hxx>
#include "globals.hxx"
#include "fg_props.hxx"
_members[i]->subsystem->init();
}
+void
+FGSubsystemGroup::reinit ()
+{
+ for (int i = 0; i < _members.size(); i++)
+ _members[i]->subsystem->reinit();
+}
+
void
FGSubsystemGroup::bind ()
{
}
}
+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)
_groups[i].init();
}
+void
+FGSubsystemMgr::reinit ()
+{
+ for (int i = 0; i < MAX_GROUPS; i++)
+ _groups[i].reinit();
+}
+
void
FGSubsystemMgr::bind ()
{
}
}
+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 *
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
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,
\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,
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,
virtual FGSubsystemGroup * get_group (GroupType group);
+ virtual FGSubsystem * get_subsystem(const string &name);
+
private:
FGSubsystemGroup _groups[MAX_GROUPS];
+ map<string,FGSubsystem *> _subsystem_map;
};