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( "xml-autopilot", new FGXMLAutopilot );
|
||||||
globals->add_subsystem( "route-manager", new FGRouteMgr );
|
globals->add_subsystem( "route-manager", new FGRouteMgr );
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Initialize the view manager subsystem.
|
// Initialize the view manager subsystem.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
fgInitView();
|
fgInitView();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Initialize the Input-Output subsystem
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
globals->add_subsystem( "io", new FGIO );
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Create and register the logger.
|
// 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.
|
// Add a new 2D panel.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -334,6 +334,11 @@ FGIO::init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FGIO::reinit()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// process any IO channel work
|
// process any IO channel work
|
||||||
void
|
void
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
~FGIO();
|
~FGIO();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
void reinit();
|
||||||
void bind();
|
void bind();
|
||||||
void unbind();
|
void unbind();
|
||||||
void update( double dt );
|
void update( double dt );
|
||||||
|
|
|
@ -95,7 +95,6 @@ FGGlobals::FGGlobals() :
|
||||||
initial_waypoints( NULL ),
|
initial_waypoints( NULL ),
|
||||||
scenery( NULL ),
|
scenery( NULL ),
|
||||||
tile_mgr( NULL ),
|
tile_mgr( NULL ),
|
||||||
io( new FGIO ),
|
|
||||||
fontcache ( new FGFontCache ),
|
fontcache ( new FGFontCache ),
|
||||||
navlist( NULL ),
|
navlist( NULL ),
|
||||||
loclist( NULL ),
|
loclist( NULL ),
|
||||||
|
@ -150,7 +149,6 @@ FGGlobals::~FGGlobals()
|
||||||
delete initial_waypoints;
|
delete initial_waypoints;
|
||||||
delete tile_mgr;
|
delete tile_mgr;
|
||||||
delete scenery;
|
delete scenery;
|
||||||
delete io;
|
|
||||||
delete fontcache;
|
delete fontcache;
|
||||||
|
|
||||||
delete navlist;
|
delete navlist;
|
||||||
|
|
|
@ -59,7 +59,6 @@ class FGATCMgr;
|
||||||
class FGAircraftModel;
|
class FGAircraftModel;
|
||||||
class FGControls;
|
class FGControls;
|
||||||
class FGFlightPlanDispatcher;
|
class FGFlightPlanDispatcher;
|
||||||
class FGIO;
|
|
||||||
class FGNavList;
|
class FGNavList;
|
||||||
class FGAirwayNetwork;
|
class FGAirwayNetwork;
|
||||||
class FGTACANList;
|
class FGTACANList;
|
||||||
|
@ -169,9 +168,6 @@ private:
|
||||||
// Tile manager
|
// Tile manager
|
||||||
FGTileMgr *tile_mgr;
|
FGTileMgr *tile_mgr;
|
||||||
|
|
||||||
// Input/Ouput subsystem
|
|
||||||
FGIO *io;
|
|
||||||
|
|
||||||
FGFontCache *fontcache;
|
FGFontCache *fontcache;
|
||||||
|
|
||||||
// Navigational Aids
|
// Navigational Aids
|
||||||
|
@ -308,7 +304,6 @@ public:
|
||||||
inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
|
inline FGTileMgr * get_tile_mgr () const { return tile_mgr; }
|
||||||
inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; }
|
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 FGFontCache *get_fontcache() const { return fontcache; }
|
||||||
|
|
||||||
inline FGNavList *get_navlist() const { return navlist; }
|
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
|
// update the view angle as late as possible, but before sound calculations
|
||||||
globals->get_viewmgr()->update(real_delta_time_sec);
|
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
|
#ifdef ENABLE_AUDIO_SUPPORT
|
||||||
// Right now we make a simplifying assumption that the primary
|
// Right now we make a simplifying assumption that the primary
|
||||||
// aircraft is the source of all sounds and that all sounds are
|
// 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 config = tokens[ configToken ];
|
||||||
string file = config+".xml";
|
file_name = config+".xml";
|
||||||
|
|
||||||
SGPath path( globals->get_fg_root() );
|
if (tokens[2] != "in" && tokens[2] != "out") {
|
||||||
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 {
|
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Unsuported protocol direction: "
|
SG_LOG(SG_GENERAL, SG_ALERT, "Unsuported protocol direction: "
|
||||||
<< tokens[2]);
|
<< tokens[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
FGGeneric::~FGGeneric() {
|
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
|
void
|
||||||
FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
|
FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,6 +47,8 @@ public:
|
||||||
// open hailing frequencies
|
// open hailing frequencies
|
||||||
bool open();
|
bool open();
|
||||||
|
|
||||||
|
void reinit();
|
||||||
|
|
||||||
// process work for this port
|
// process work for this port
|
||||||
bool process();
|
bool process();
|
||||||
|
|
||||||
|
@ -70,6 +72,8 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
string file_name;
|
||||||
|
|
||||||
int length;
|
int length;
|
||||||
char buf[ FG_MAX_MSG_SIZE ];
|
char buf[ FG_MAX_MSG_SIZE ];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue