Debian Codegraph @

src/Systems/system_mgr.cxx

raw symbols SCIP
1 /*
2 * SPDX-FileName: system_mgr.cxx
3 * SPDX-FileComment: manage aircraft systems
4 * SPDX-FileCopyrightText: Written by David Megginson, started 2002.
5 * SPDX-License-Identifier: This file is in the Public Domain and comes with no warranty.
6 */
7
8 #ifdef HAVE_CONFIG_H
9 # include <config.h>
10 #endif
11
12 #include <simgear/structure/exception.hxx>
13 #include <simgear/misc/sg_path.hxx>
14 #include <simgear/sg_inlines.h>
15 #include <simgear/props/props_io.hxx>
16
17 #include <Main/fg_props.hxx>
18 #include <Main/globals.hxx>
19 #include <Main/util.hxx>
20
21 #include <cstdlib>
22 #include <iostream>
23 #include <string>
24 #include <sstream>
25
26 #include "system_mgr.hxx"
27 #include "electrical.hxx"
28 #include "pitot.hxx"
29 #include "static.hxx"
30 #include "vacuum.hxx"
31
32
33 FGSystemMgr::FGSystemMgr ()
34 {
35 SGPropertyNode_ptr config_props = new SGPropertyNode;
36
37 SGPropertyNode *path_n = fgGetNode("/sim/systems/path");
38
39 if (path_n) {
40 SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
41 if (!config.exists()) {
42 SG_LOG( SG_SYSTEMS, SG_DEV_ALERT, "System model file not found:" << config);
43 return;
44 }
45
46 SG_LOG( SG_SYSTEMS, SG_INFO, "Reading systems from "
47 << config );
48 try
49 {
50 readProperties( config, config_props );
51 build(config_props);
52 }
53 catch( const sg_exception& )
54 {
55 SG_LOG( SG_SYSTEMS, SG_ALERT, "Failed to load systems system model: "
56 << config );
57 }
58
59 } else {
60 SG_LOG( SG_SYSTEMS, SG_WARN,
61 "No systems model specified for this model!");
62 }
63
64 }
65
66 FGSystemMgr::~FGSystemMgr ()
67 {
68 }
69
70 bool FGSystemMgr::build (SGPropertyNode* config_props)
71 {
72 SGPropertyNode *node;
73 int i;
74
75 int count = config_props->nChildren();
76 for ( i = 0; i < count; ++i ) {
77 node = config_props->getChild(i);
78 std::string name = node->getNameString();
79 std::ostringstream temp;
80 temp << i;
81 if ( name == "electrical" ) {
82 set_subsystem( "electrical" + temp.str(),
83 new FGElectricalSystem( node ) );
84 } else if ( name == "pitot" ) {
85 set_subsystem( "system" + temp.str(),
86 new PitotSystem( node ) );
87 } else if ( name == "static" ) {
88 set_subsystem( "system" + temp.str(),
89 new StaticSystem( node ) );
90 } else if ( name == "vacuum" ) {
91 set_subsystem( "system" + temp.str(),
92 new VacuumSystem( node ) );
93 } else {
94 SG_LOG(SG_SYSTEMS, SG_ALERT, "Ignoring unknown system: " << name);
95 }
96 }
97 return true;
98 }
99
100
101 // Register the subsystem.
102 SGSubsystemMgr::Registrant<FGSystemMgr> registrantFGSystemMgr(
103 SGSubsystemMgr::FDM);
104
105 // end of system_manager.cxx