19#include <simgear/debug/ErrorReportingCallback.hxx>
20#include <simgear/props/props_io.hxx>
21#include <simgear/structure/exception.hxx>
22#include <simgear/structure/subsystem_mgr.hxx>
28using simgear::PropertyList;
48 SGPropertyNode_ptr apNode,
49 SGPropertyNode_ptr config );
53 void initFrom( SGPropertyNode_ptr rootNode,
const char * childName );
54 std::string _nodeName;
59 SGPropertyNode_ptr apNode,
60 SGPropertyNode_ptr config )
62 if( has_subsystem(
name) )
66 "NOT adding duplicate " << _nodeName <<
" name '" <<
name <<
"'");
73 double updateInterval = config->getDoubleValue(
"update-interval-secs", 0.0);
74 set_subsystem(
name, ap, updateInterval );
85 "CAN NOT remove unknown " << _nodeName <<
" '" <<
name <<
"'");
89 remove_subsystem(
name);
95 SGSubsystemGroup::unbind();
102 SGSubsystemGroup::bind();
116 initFrom(
fgGetNode(
"/sim/systems"), _nodeName.c_str());
117 SGSubsystemGroup::init();
121void FGXMLAutopilotGroupImplementation::initFrom( SGPropertyNode_ptr rootNode,
122 const char* childName )
127 for(
auto autopilotNode : rootNode->getChildren(childName) )
129 SGPropertyNode_ptr pathNode = autopilotNode->getNode(
"path");
136 "No configuration file specified for this " << childName <<
"!"
142 SGPropertyNode_ptr nameNode = autopilotNode->getNode(
"name" );
143 if( nameNode != NULL ) {
144 apName = nameNode->getStringValue();
146 std::ostringstream buf;
147 buf <<
"unnamed_autopilot_" << autopilotNode->getIndex();
153 std::string
name = apName;
154 for(
unsigned i = 0; get_subsystem( apName.c_str() ) != NULL;
i++ ) {
155 std::ostringstream buf;
156 buf <<
name <<
"_" <<
i;
164 "Duplicate " << childName <<
" configuration name " <<
name
165 <<
", renamed to " << apName
174 SGPropertyNode_ptr apNode,
175 const std::string& path )
177 SGPath config =
globals->resolve_maybe_aircraft_path(path);
178 if( config.isNull() )
180 simgear::reportFailure(simgear::LoadFailure::NotFound, simgear::ErrorCode::AircraftSystems,
181 std::string{
"Autopilot XML not found:"} + path, sg_location{path});
185 "Cannot find property-rule configuration file '" << path <<
"'.");
192 "Reading property-rule configuration from " << config
197 SGPropertyNode_ptr configNode =
new SGPropertyNode();
198 readProperties(config, configNode);
200 SG_LOG(SG_AUTOPILOT, SG_INFO,
"adding property-rule subsystem " <<
name);
203 catch (
const sg_exception& e)
209 "Failed to load property-rule configuration: " << config
210 <<
": " << e.getMessage()
212 simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::AircraftSystems,
213 std::string{
"Autopilot XML failed to load:"} + e.getFormattedMessage(), e.getLocation());
virtual void addAutopilot(const std::string &name, SGPropertyNode_ptr apNode, SGPropertyNode_ptr config)
virtual void removeAutopilot(const std::string &name)
FGXMLAutopilotGroupImplementation(const std::string &nodeName)
static const char * staticSubsystemClassId()
InitStatus incrementalInit() override
Model an autopilot system by implementing a SGSubsystemGroup.
static FGXMLAutopilotGroup * createInstance(const std::string &nodeName)
void addAutopilotFromFile(const std::string &name, SGPropertyNode_ptr apNode, const std::string &path)
virtual void addAutopilot(const std::string &name, SGPropertyNode_ptr apNode, SGPropertyNode_ptr config)=0
A SGSubsystemGroup implementation to serve as a collection of Components.
void set_name(const std::string &name)
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.