X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FSystems%2Fsystem_mgr.cxx;h=9d945a5849f3adeaed68acea0f3cfedcc25dbc86;hb=219be77f1e329b03a7dcf1d697ea2fdbf7f1a81a;hp=58d35bc4d8792f44c8ffb52bbe83ee8835b8adb8;hpb=7c057de4fe8680bc73e6f9c8086f1c6027c00229;p=flightgear.git diff --git a/src/Systems/system_mgr.cxx b/src/Systems/system_mgr.cxx index 58d35bc4d..9d945a584 100644 --- a/src/Systems/system_mgr.cxx +++ b/src/Systems/system_mgr.cxx @@ -3,52 +3,103 @@ // // This file is in the Public Domain and comes with no warranty. +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include + +#include
+#include
+#include
+ +#include +#include +#include #include "system_mgr.hxx" -#include "Vacuum/vacuum.hxx" +#include "electrical.hxx" +#include "pitot.hxx" +#include "static.hxx" +#include "vacuum.hxx" FGSystemMgr::FGSystemMgr () { - // NO-OP -} + config_props = new SGPropertyNode; -FGSystemMgr::~FGSystemMgr () -{ - for (int i = 0; i < _systems.size(); i++) { - delete _systems[i]; - _systems[i] = 0; - } -} + SGPropertyNode *path_n = fgGetNode("/sim/systems/path"); -void -FGSystemMgr::init () -{ - // TODO: replace with XML configuration - _systems.push_back(new VacuumSystem); + if (path_n) { + SGPath config( globals->get_fg_root() ); + config.append( path_n->getStringValue() ); - // Initialize the individual systems - for (int i = 0; i < _systems.size(); i++) - _systems[i]->init(); -} + SG_LOG( SG_ALL, SG_INFO, "Reading systems from " + << config.str() ); + try { + readProperties( config.str(), config_props ); -void -FGSystemMgr::bind () -{ - // NO-OP + if ( build() ) { + enabled = true; + } else { + SG_LOG( SG_ALL, SG_ALERT, + "Detected an internal inconsistency in the systems"); + SG_LOG( SG_ALL, SG_ALERT, + " system specification file. See earlier errors for" ); + SG_LOG( SG_ALL, SG_ALERT, + " details."); + exit(-1); + } + } catch (const sg_exception&) { + SG_LOG( SG_ALL, SG_ALERT, "Failed to load systems system model: " + << config.str() ); + } + + } else { + SG_LOG( SG_ALL, SG_WARN, + "No systems model specified for this model!"); + } + + delete config_props; } -void -FGSystemMgr::unbind () +FGSystemMgr::~FGSystemMgr () { - // NO-OP } -void -FGSystemMgr::update (double dt) +bool FGSystemMgr::build () { - for (int i = 0; i < _systems.size(); i++) - _systems[i]->update(dt); + SGPropertyNode *node; + int i; + + int count = config_props->nChildren(); + for ( i = 0; i < count; ++i ) { + node = config_props->getChild(i); + string name = node->getName(); + std::ostringstream temp; + temp << i; + if ( name == "electrical" ) { + set_subsystem( "electrical" + temp.str(), + new FGElectricalSystem( node ) ); + } else if ( name == "pitot" ) { + set_subsystem( "system" + temp.str(), + new PitotSystem( node ) ); + } else if ( name == "static" ) { + set_subsystem( "system" + temp.str(), + new StaticSystem( node ) ); + } else if ( name == "vacuum" ) { + set_subsystem( "system" + temp.str(), + new VacuumSystem( node ) ); + } else { + SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: " + << name ); + return false; + } + } + return true; } // end of system_manager.cxx