Make FGIO a proper subsystem and add a reinit method for the generic protocol. This should allow for easy runtime reloading of the configuration file.
This commit is contained in:
parent
f220feb684
commit
ea4a3ee1df
8 changed files with 50 additions and 46 deletions
|
@ -1531,13 +1531,17 @@ bool fgInitSubsystems() {
|
|||
globals->add_subsystem( "xml-autopilot", new FGXMLAutopilot );
|
||||
globals->add_subsystem( "route-manager", new FGRouteMgr );
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Initialize the view manager subsystem.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
fgInitView();
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Initialize the Input-Output subsystem
|
||||
////////////////////////////////////////////////////////////////////
|
||||
globals->add_subsystem( "io", new FGIO );
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Create and register the logger.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -1633,14 +1637,6 @@ bool fgInitSubsystems() {
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Initialize I/O subsystem.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
globals->get_io()->init();
|
||||
globals->get_io()->bind();
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Add a new 2D panel.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -334,6 +334,11 @@ FGIO::init()
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
FGIO::reinit()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// process any IO channel work
|
||||
void
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
~FGIO();
|
||||
|
||||
void init();
|
||||
void reinit();
|
||||
void bind();
|
||||
void unbind();
|
||||
void update( double dt );
|
||||
|
|
|
@ -95,7 +95,6 @@ FGGlobals::FGGlobals() :
|
|||
initial_waypoints( NULL ),
|
||||
scenery( NULL ),
|
||||
tile_mgr( NULL ),
|
||||
io( new FGIO ),
|
||||
fontcache ( new FGFontCache ),
|
||||
navlist( NULL ),
|
||||
loclist( NULL ),
|
||||
|
@ -150,7 +149,6 @@ FGGlobals::~FGGlobals()
|
|||
delete initial_waypoints;
|
||||
delete tile_mgr;
|
||||
delete scenery;
|
||||
delete io;
|
||||
delete fontcache;
|
||||
|
||||
delete navlist;
|
||||
|
|
|
@ -59,7 +59,6 @@ class FGATCMgr;
|
|||
class FGAircraftModel;
|
||||
class FGControls;
|
||||
class FGFlightPlanDispatcher;
|
||||
class FGIO;
|
||||
class FGNavList;
|
||||
class FGAirwayNetwork;
|
||||
class FGTACANList;
|
||||
|
@ -169,9 +168,6 @@ private:
|
|||
// Tile manager
|
||||
FGTileMgr *tile_mgr;
|
||||
|
||||
// Input/Ouput subsystem
|
||||
FGIO *io;
|
||||
|
||||
FGFontCache *fontcache;
|
||||
|
||||
// Navigational Aids
|
||||
|
@ -308,7 +304,6 @@ public:
|
|||
inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
|
||||
inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
|
||||
|
||||
inline FGIO* get_io() const { return io; }
|
||||
inline FGFontCache *get_fontcache() const { return fontcache; }
|
||||
|
||||
inline FGNavList *get_navlist() const { return navlist; }
|
||||
|
|
|
@ -484,9 +484,6 @@ static void fgMainLoop( void ) {
|
|||
// update the view angle as late as possible, but before sound calculations
|
||||
globals->get_viewmgr()->update(real_delta_time_sec);
|
||||
|
||||
// Do any I/O channel work that might need to be done (must come after viewmgr)
|
||||
globals->get_io()->update(real_delta_time_sec);
|
||||
|
||||
#ifdef ENABLE_AUDIO_SUPPORT
|
||||
// Right now we make a simplifying assumption that the primary
|
||||
// aircraft is the source of all sounds and that all sounds are
|
||||
|
|
|
@ -61,37 +61,14 @@ FGGeneric::FGGeneric(vector<string> tokens) : exitOnError(false)
|
|||
}
|
||||
|
||||
string config = tokens[ configToken ];
|
||||
string file = config+".xml";
|
||||
file_name = config+".xml";
|
||||
|
||||
SGPath path( globals->get_fg_root() );
|
||||
path.append("Protocol");
|
||||
path.append(file.c_str());
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "Reading communication protocol from "
|
||||
<< path.str());
|
||||
|
||||
SGPropertyNode root;
|
||||
try {
|
||||
readProperties(path.str(), &root);
|
||||
} catch (const sg_exception &) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT,
|
||||
"Unable to load the protocol configuration file");
|
||||
return;
|
||||
}
|
||||
|
||||
if (tokens[2] == "out") {
|
||||
SGPropertyNode *output = root.getNode("generic/output");
|
||||
if (output) {
|
||||
read_config(output, _out_message);
|
||||
}
|
||||
} else if (tokens[2] == "in") {
|
||||
SGPropertyNode *input = root.getNode("generic/input");
|
||||
if (input) {
|
||||
read_config(input, _in_message);
|
||||
}
|
||||
} else {
|
||||
if (tokens[2] != "in" && tokens[2] != "out") {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Unsuported protocol direction: "
|
||||
<< tokens[2]);
|
||||
}
|
||||
|
||||
reinit();
|
||||
}
|
||||
|
||||
FGGeneric::~FGGeneric() {
|
||||
|
@ -537,6 +514,37 @@ bool FGGeneric::close() {
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
FGGeneric::reinit()
|
||||
{
|
||||
SGPath path( globals->get_fg_root() );
|
||||
path.append("Protocol");
|
||||
path.append(file_name.c_str());
|
||||
|
||||
SG_LOG(SG_GENERAL, SG_INFO, "Reading communication protocol from "
|
||||
<< path.str());
|
||||
|
||||
SGPropertyNode root;
|
||||
try {
|
||||
readProperties(path.str(), &root);
|
||||
} catch (const sg_exception &) {
|
||||
SG_LOG(SG_GENERAL, SG_ALERT,
|
||||
"Unable to load the protocol configuration file");
|
||||
return;
|
||||
}
|
||||
|
||||
SGPropertyNode *output = root.getNode("generic/output");
|
||||
if (output) {
|
||||
read_config(output, _out_message);
|
||||
}
|
||||
|
||||
SGPropertyNode *input = root.getNode("generic/input");
|
||||
if (input) {
|
||||
read_config(input, _in_message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
|
||||
{
|
||||
|
|
|
@ -47,6 +47,8 @@ public:
|
|||
// open hailing frequencies
|
||||
bool open();
|
||||
|
||||
void reinit();
|
||||
|
||||
// process work for this port
|
||||
bool process();
|
||||
|
||||
|
@ -70,6 +72,8 @@ protected:
|
|||
|
||||
private:
|
||||
|
||||
string file_name;
|
||||
|
||||
int length;
|
||||
char buf[ FG_MAX_MSG_SIZE ];
|
||||
|
||||
|
|
Loading…
Reference in a new issue