From ea4a3ee1df65b75169941af64f6f772737ff7ca4 Mon Sep 17 00:00:00 2001 From: ehofman Date: Mon, 7 Sep 2009 07:27:38 +0000 Subject: [PATCH] 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. --- src/Main/fg_init.cxx | 14 ++++------ src/Main/fg_io.cxx | 5 ++++ src/Main/fg_io.hxx | 1 + src/Main/globals.cxx | 2 -- src/Main/globals.hxx | 5 ---- src/Main/main.cxx | 3 -- src/Network/generic.cxx | 62 +++++++++++++++++++++++------------------ src/Network/generic.hxx | 4 +++ 8 files changed, 50 insertions(+), 46 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 7079f3d20..953e4a254 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -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. //////////////////////////////////////////////////////////////////// diff --git a/src/Main/fg_io.cxx b/src/Main/fg_io.cxx index 3ab62f82d..36ca64433 100644 --- a/src/Main/fg_io.cxx +++ b/src/Main/fg_io.cxx @@ -334,6 +334,11 @@ FGIO::init() } } +void +FGIO::reinit() +{ +} + // process any IO channel work void diff --git a/src/Main/fg_io.hxx b/src/Main/fg_io.hxx index ca6f0f78b..c4eff1b8b 100644 --- a/src/Main/fg_io.hxx +++ b/src/Main/fg_io.hxx @@ -40,6 +40,7 @@ public: ~FGIO(); void init(); + void reinit(); void bind(); void unbind(); void update( double dt ); diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 2d00791a2..262423c2a 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -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; diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index d962bae2c..a1c58797e 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -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; } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 89756f393..70e126983 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -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 diff --git a/src/Network/generic.cxx b/src/Network/generic.cxx index ad362e258..0e01985e3 100644 --- a/src/Network/generic.cxx +++ b/src/Network/generic.cxx @@ -61,37 +61,14 @@ FGGeneric::FGGeneric(vector 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) { diff --git a/src/Network/generic.hxx b/src/Network/generic.hxx index 4d4ec7e43..efb223867 100644 --- a/src/Network/generic.hxx +++ b/src/Network/generic.hxx @@ -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 ];