2012-09-30 15:34:51 +00:00
|
|
|
// subsystemFactory.cxx - factory for subsystems
|
|
|
|
//
|
|
|
|
// Copyright (C) 2012 James Turner zakalawe@mac.com
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "subsystemFactory.hxx"
|
|
|
|
|
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
|
|
|
#include <simgear/structure/exception.hxx>
|
|
|
|
#include <simgear/debug/logstream.hxx>
|
|
|
|
#include <simgear/structure/commands.hxx>
|
|
|
|
#include <simgear/structure/event_mgr.hxx>
|
|
|
|
|
|
|
|
#include <Main/globals.hxx>
|
|
|
|
#include <Sound/soundmanager.hxx>
|
|
|
|
|
|
|
|
// subsystem includes
|
|
|
|
#include <Aircraft/controls.hxx>
|
2014-07-11 23:17:35 +00:00
|
|
|
#include <Aircraft/FlightHistory.hxx>
|
2012-09-30 15:34:51 +00:00
|
|
|
#include <Main/fg_props.hxx>
|
2013-03-16 15:43:55 +00:00
|
|
|
#include <Main/FGInterpolator.hxx>
|
2012-09-30 15:34:51 +00:00
|
|
|
#include <Main/fg_io.hxx>
|
|
|
|
#include <FDM/fdm_shell.hxx>
|
|
|
|
#include <Environment/environment_mgr.hxx>
|
|
|
|
#include <Environment/ephemeris.hxx>
|
|
|
|
#include <Instrumentation/instrument_mgr.hxx>
|
|
|
|
#include <Instrumentation/HUD/HUD.hxx>
|
|
|
|
#include <Systems/system_mgr.hxx>
|
|
|
|
#include <Autopilot/route_mgr.hxx>
|
|
|
|
#include <Autopilot/autopilotgroup.hxx>
|
|
|
|
#include <Traffic/TrafficMgr.hxx>
|
2014-07-11 23:17:35 +00:00
|
|
|
#include <Network/fgcom.hxx>
|
2012-11-19 23:03:08 +00:00
|
|
|
#include <Network/HTTPClient.hxx>
|
|
|
|
#include <Cockpit/cockpitDisplayManager.hxx>
|
|
|
|
#include <GUI/new_gui.hxx>
|
|
|
|
#include <Main/logger.hxx>
|
|
|
|
#include <ATC/atc_mgr.hxx>
|
|
|
|
#include <AIModel/AIManager.hxx>
|
|
|
|
#include <MultiPlayer/multiplaymgr.hxx>
|
|
|
|
#include <AIModel/submodel.hxx>
|
|
|
|
#include <Aircraft/controls.hxx>
|
|
|
|
#include <Input/input.hxx>
|
|
|
|
#include <Aircraft/replay.hxx>
|
|
|
|
#include <Sound/voice.hxx>
|
|
|
|
#include <Canvas/canvas_mgr.hxx>
|
|
|
|
#include <Canvas/gui_mgr.hxx>
|
|
|
|
#include <Time/light.hxx>
|
2012-11-20 13:33:20 +00:00
|
|
|
#include <Viewer/viewmgr.hxx>
|
2014-07-11 23:17:35 +00:00
|
|
|
#include <Model/acmodel.hxx>
|
2012-11-20 13:33:20 +00:00
|
|
|
#include <Model/modelmgr.hxx>
|
2012-09-30 15:34:51 +00:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
namespace flightgear
|
|
|
|
{
|
|
|
|
|
|
|
|
SGSubsystem* createSubsystemByName(const std::string& name)
|
|
|
|
{
|
|
|
|
#define MAKE_SUB(cl, n) \
|
|
|
|
if (name == n) return new cl;
|
2014-07-11 23:17:35 +00:00
|
|
|
|
2012-09-30 15:34:51 +00:00
|
|
|
MAKE_SUB(FGSoundManager, "sound");
|
2013-03-16 15:43:55 +00:00
|
|
|
MAKE_SUB(FGInterpolator, "prop-interpolator")
|
2012-09-30 15:34:51 +00:00
|
|
|
MAKE_SUB(FGProperties, "properties");
|
2014-07-11 23:17:35 +00:00
|
|
|
MAKE_SUB(FGHTTPClient, "http");
|
2014-07-11 17:25:26 +00:00
|
|
|
MAKE_SUB(FDMShell, "flight");
|
2012-09-30 15:34:51 +00:00
|
|
|
MAKE_SUB(FGEnvironmentMgr, "environment");
|
|
|
|
MAKE_SUB(Ephemeris, "ephemeris");
|
2014-07-11 23:17:35 +00:00
|
|
|
MAKE_SUB(FGSystemMgr, "systems");
|
|
|
|
MAKE_SUB(FGInstrumentMgr, "instrumentation");
|
2012-09-30 15:34:51 +00:00
|
|
|
MAKE_SUB(HUD, "hud");
|
2012-11-19 23:03:08 +00:00
|
|
|
MAKE_SUB(flightgear::CockpitDisplayManager, "cockpit-displays");
|
2012-09-30 15:34:51 +00:00
|
|
|
MAKE_SUB(FGRouteMgr, "route-manager");
|
2014-07-11 23:17:35 +00:00
|
|
|
MAKE_SUB(FGIO, "io");
|
2012-11-19 23:03:08 +00:00
|
|
|
MAKE_SUB(FGLogger, "logger");
|
|
|
|
MAKE_SUB(NewGUI, "gui");
|
2014-07-11 23:17:35 +00:00
|
|
|
MAKE_SUB(CanvasMgr, "Canvas");
|
|
|
|
MAKE_SUB(GUIMgr, "CanvasGUI");
|
|
|
|
MAKE_SUB(FGATCManager, "ATC");
|
2012-11-19 23:03:08 +00:00
|
|
|
MAKE_SUB(FGMultiplayMgr, "mp");
|
2014-07-11 23:17:35 +00:00
|
|
|
MAKE_SUB(FGAIManager, "ai-model");
|
|
|
|
MAKE_SUB(FGSubmodelMgr, "submodel-mgr");
|
2012-09-30 15:34:51 +00:00
|
|
|
MAKE_SUB(FGTrafficManager, "traffic-manager");
|
2012-11-19 23:03:08 +00:00
|
|
|
MAKE_SUB(FGControls, "controls");
|
|
|
|
MAKE_SUB(FGInput, "input");
|
|
|
|
MAKE_SUB(FGReplay, "replay");
|
2014-07-11 23:17:35 +00:00
|
|
|
MAKE_SUB(FGFlightHistory, "history");
|
|
|
|
#ifdef ENABLE_AUDIO_SUPPORT
|
2012-11-19 23:03:08 +00:00
|
|
|
MAKE_SUB(FGVoiceMgr, "voice");
|
2014-07-11 23:17:35 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_IAX
|
|
|
|
MAKE_SUB(FGCom, "fgcom");
|
|
|
|
#endif
|
2012-11-19 23:03:08 +00:00
|
|
|
MAKE_SUB(FGLight, "lighting");
|
2014-07-11 23:17:35 +00:00
|
|
|
MAKE_SUB(FGAircraftModel, "aircraft-model");
|
2012-11-20 13:33:20 +00:00
|
|
|
MAKE_SUB(FGModelMgr, "model-manager");
|
2014-07-11 23:17:35 +00:00
|
|
|
MAKE_SUB(FGViewMgr, "view-manager");
|
2012-09-30 15:34:51 +00:00
|
|
|
#undef MAKE_SUB
|
2014-07-11 23:17:35 +00:00
|
|
|
|
2012-09-30 15:34:51 +00:00
|
|
|
throw sg_range_exception("unknown subsystem:" + name);
|
|
|
|
}
|
|
|
|
|
|
|
|
SGSubsystemMgr::GroupType mapGroupNameToType(const std::string& s)
|
|
|
|
{
|
|
|
|
if (s == "init") return SGSubsystemMgr::INIT;
|
|
|
|
if (s == "general") return SGSubsystemMgr::GENERAL;
|
|
|
|
if (s == "fdm") return SGSubsystemMgr::FDM;
|
|
|
|
if (s == "post-fdm") return SGSubsystemMgr::POST_FDM;
|
|
|
|
if (s == "display") return SGSubsystemMgr::DISPLAY;
|
|
|
|
if (s == "sound") return SGSubsystemMgr::SOUND;
|
|
|
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "unrecognized subsystem group:" << s);
|
|
|
|
return SGSubsystemMgr::GENERAL;
|
|
|
|
}
|
|
|
|
|
2014-07-11 23:17:35 +00:00
|
|
|
static SGSubsystem* getSubsystem(const SGPropertyNode* arg, bool create)
|
|
|
|
{
|
|
|
|
std::string subsystem(arg->getStringValue("subsystem"));
|
|
|
|
std::string name = arg->getStringValue("name");
|
|
|
|
|
|
|
|
if (name.empty()) {
|
|
|
|
// default name is simply the subsytem's name
|
|
|
|
name = subsystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
SGSubsystem* sys = globals->get_subsystem_mgr()->get_subsystem(name);
|
|
|
|
if (!create)
|
|
|
|
return sys;
|
|
|
|
|
|
|
|
if( subsystem.empty() ) {
|
|
|
|
SG_LOG( SG_GENERAL,
|
|
|
|
SG_ALERT,
|
|
|
|
"do_add_subsystem: no subsystem/name supplied" );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sys) {
|
|
|
|
SG_LOG( SG_GENERAL,
|
|
|
|
SG_ALERT,
|
|
|
|
"do_add_subsystem: duplicate subsystem name:" << name );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string groupname = arg->getStringValue("group");
|
|
|
|
SGSubsystemMgr::GroupType group = SGSubsystemMgr::GENERAL;
|
|
|
|
if (!groupname.empty()) {
|
|
|
|
group = mapGroupNameToType(groupname);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
sys = createSubsystemByName(subsystem);
|
|
|
|
} catch (sg_exception& e) {
|
|
|
|
SG_LOG( SG_GENERAL,
|
|
|
|
SG_ALERT,
|
|
|
|
"subsystem creation failed:" << name
|
|
|
|
<< ":" << e.getFormattedMessage() );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool doInit = arg->getBoolValue("do-bind-init", false);
|
|
|
|
if (doInit) {
|
|
|
|
sys->bind();
|
|
|
|
sys->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
double minTime = arg->getDoubleValue("min-time-sec", 0.0);
|
|
|
|
globals->get_subsystem_mgr()
|
|
|
|
->add(name.c_str(), sys, group, minTime);
|
|
|
|
|
|
|
|
return sys;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2017-07-04 23:23:24 +00:00
|
|
|
do_check_subsystem_running(const SGPropertyNode * arg, SGPropertyNode * root)
|
2014-07-11 23:17:35 +00:00
|
|
|
{
|
|
|
|
return getSubsystem(arg, false) != 0;
|
|
|
|
}
|
|
|
|
|
2012-09-30 15:34:51 +00:00
|
|
|
static bool
|
2017-07-04 23:23:24 +00:00
|
|
|
do_add_subsystem (const SGPropertyNode * arg, SGPropertyNode * root)
|
2012-09-30 15:34:51 +00:00
|
|
|
{
|
2014-07-11 23:17:35 +00:00
|
|
|
return getSubsystem(arg, true) != 0;
|
2012-09-30 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2017-07-04 23:23:24 +00:00
|
|
|
static bool do_remove_subsystem(const SGPropertyNode * arg, SGPropertyNode * root)
|
2012-09-30 15:34:51 +00:00
|
|
|
{
|
|
|
|
std::string name = arg->getStringValue("subsystem");
|
2015-11-19 22:17:58 +00:00
|
|
|
|
2012-09-30 15:34:51 +00:00
|
|
|
SGSubsystem* instance = globals->get_subsystem_mgr()->get_subsystem(name);
|
|
|
|
if (!instance) {
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "do_remove_subsystem: unknown subsytem:" << name);
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-19 22:17:58 +00:00
|
|
|
|
2012-09-30 15:34:51 +00:00
|
|
|
// is it safe to always call these? let's assume so!
|
|
|
|
instance->shutdown();
|
|
|
|
instance->unbind();
|
|
|
|
|
2015-11-19 22:17:58 +00:00
|
|
|
// unplug from the manager (this also deletes the instance!)
|
2012-09-30 15:34:51 +00:00
|
|
|
globals->get_subsystem_mgr()->remove(name.c_str());
|
2015-11-19 22:17:58 +00:00
|
|
|
|
2012-09-30 15:34:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Built-in command: reinitialize one or more subsystems.
|
|
|
|
*
|
|
|
|
* subsystem[*]: the name(s) of the subsystem(s) to reinitialize; if
|
|
|
|
* none is specified, reinitialize all of them.
|
|
|
|
*/
|
|
|
|
static bool
|
2017-07-04 23:23:24 +00:00
|
|
|
do_reinit (const SGPropertyNode * arg, SGPropertyNode * root)
|
2012-09-30 15:34:51 +00:00
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
|
|
|
|
vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
|
2013-03-22 02:42:22 +00:00
|
|
|
if (subsystems.empty()) {
|
2012-09-30 15:34:51 +00:00
|
|
|
globals->get_subsystem_mgr()->reinit();
|
|
|
|
} else {
|
|
|
|
for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
|
|
|
|
const char * name = subsystems[i]->getStringValue();
|
|
|
|
SGSubsystem * subsystem = globals->get_subsystem(name);
|
|
|
|
if (subsystem == 0) {
|
|
|
|
result = false;
|
|
|
|
SG_LOG( SG_GENERAL, SG_ALERT,
|
|
|
|
"Subsystem " << name << " not found" );
|
|
|
|
} else {
|
|
|
|
subsystem->reinit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
globals->get_event_mgr()->reinit();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Built-in command: suspend one or more subsystems.
|
|
|
|
*
|
|
|
|
* subsystem[*] - the name(s) of the subsystem(s) to suspend.
|
|
|
|
*/
|
|
|
|
static bool
|
2017-07-04 23:23:24 +00:00
|
|
|
do_suspend (const SGPropertyNode * arg, SGPropertyNode * root)
|
2012-09-30 15:34:51 +00:00
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
|
|
|
|
vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
|
|
|
|
for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
|
|
|
|
const char * name = subsystems[i]->getStringValue();
|
|
|
|
SGSubsystem * subsystem = globals->get_subsystem(name);
|
|
|
|
if (subsystem == 0) {
|
|
|
|
result = false;
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found");
|
|
|
|
} else {
|
|
|
|
subsystem->suspend();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Built-in command: suspend one or more subsystems.
|
|
|
|
*
|
|
|
|
* subsystem[*] - the name(s) of the subsystem(s) to suspend.
|
|
|
|
*/
|
|
|
|
static bool
|
2017-07-04 23:23:24 +00:00
|
|
|
do_resume (const SGPropertyNode * arg, SGPropertyNode * root)
|
2012-09-30 15:34:51 +00:00
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
|
|
|
|
vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
|
|
|
|
for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
|
|
|
|
const char * name = subsystems[i]->getStringValue();
|
|
|
|
SGSubsystem * subsystem = globals->get_subsystem(name);
|
|
|
|
if (subsystem == 0) {
|
|
|
|
result = false;
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found");
|
|
|
|
} else {
|
|
|
|
subsystem->resume();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
const char * name;
|
|
|
|
SGCommandMgr::command_t command;
|
|
|
|
} built_ins [] = {
|
|
|
|
{ "add-subsystem", do_add_subsystem },
|
|
|
|
{ "remove-subsystem", do_remove_subsystem },
|
2014-07-11 23:17:35 +00:00
|
|
|
{ "subsystem-running", do_check_subsystem_running },
|
2012-09-30 15:34:51 +00:00
|
|
|
{ "reinit", do_reinit },
|
|
|
|
{ "suspend", do_suspend },
|
|
|
|
{ "resume", do_resume },
|
|
|
|
{ 0, 0 } // zero-terminated
|
|
|
|
};
|
|
|
|
|
|
|
|
void registerSubsystemCommands(SGCommandMgr* cmdMgr)
|
|
|
|
{
|
|
|
|
for (int i = 0; built_ins[i].name != 0; i++) {
|
|
|
|
cmdMgr->addCommand(built_ins[i].name, built_ins[i].command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // of namepace flightgear
|