1
0
Fork 0

FGIO uses new SGSubsystem shutdown() logic

This commit is contained in:
James Turner 2010-11-06 07:22:37 +00:00
parent 86be8fcb51
commit 0cb0c59bc9
3 changed files with 26 additions and 27 deletions

View file

@ -29,6 +29,7 @@
#include <cstdlib> // atoi() #include <cstdlib> // atoi()
#include <string> #include <string>
#include <algorithm>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/io/iochannel.hxx> #include <simgear/io/iochannel.hxx>
@ -76,15 +77,13 @@ FGIO::FGIO()
{ {
} }
#include <algorithm>
using std::for_each;
static void delete_ptr( FGProtocol* p ) { delete p; }
FGIO::~FGIO() FGIO::~FGIO()
{ {
shutdown_all();
for_each( io_channels.begin(), io_channels.end(), delete_ptr );
} }
@ -94,7 +93,7 @@ FGIO::parse_port_config( const string& config )
{ {
SG_LOG( SG_IO, SG_INFO, "Parse I/O channel request: " << config ); SG_LOG( SG_IO, SG_INFO, "Parse I/O channel request: " << config );
vector<string> tokens = simgear::strutils::split( config, "," ); string_list tokens = simgear::strutils::split( config, "," );
if (tokens.empty()) if (tokens.empty())
{ {
SG_LOG( SG_IO, SG_ALERT, SG_LOG( SG_IO, SG_ALERT,
@ -315,9 +314,8 @@ FGIO::init()
// parse the configuration strings and store the results in the // parse the configuration strings and store the results in the
// appropriate FGIOChannel structures // appropriate FGIOChannel structures
typedef vector<string> container; string_list::iterator i = globals->get_channel_options_list()->begin();
container::iterator i = globals->get_channel_options_list()->begin(); string_list::iterator end = globals->get_channel_options_list()->end();
container::iterator end = globals->get_channel_options_list()->end();
for (; i != end; ++i ) for (; i != end; ++i )
{ {
p = parse_port_config( *i ); p = parse_port_config( *i );
@ -339,7 +337,6 @@ FGIO::reinit()
{ {
} }
// process any IO channel work // process any IO channel work
void void
FGIO::update( double delta_time_sec ) FGIO::update( double delta_time_sec )
@ -347,9 +344,8 @@ FGIO::update( double delta_time_sec )
// cout << "processing I/O channels" << endl; // cout << "processing I/O channels" << endl;
// cout << " Elapsed time = " << delta_time_sec << endl; // cout << " Elapsed time = " << delta_time_sec << endl;
typedef vector< FGProtocol* > container; ProtocolVec::iterator i = io_channels.begin();
container::iterator i = io_channels.begin(); ProtocolVec::iterator end = io_channels.end();
container::iterator end = io_channels.end();
for (; i != end; ++i ) { for (; i != end; ++i ) {
FGProtocol* p = *i; FGProtocol* p = *i;
@ -369,24 +365,24 @@ FGIO::update( double delta_time_sec )
} }
} }
void void
FGIO::shutdown_all() { FGIO::shutdown()
{
FGProtocol *p; FGProtocol *p;
// cout << "shutting down all I/O channels" << endl; ProtocolVec::iterator i = io_channels.begin();
ProtocolVec::iterator end = io_channels.end();
typedef vector< FGProtocol* > container;
container::iterator i = io_channels.begin();
container::iterator end = io_channels.end();
for (; i != end; ++i ) for (; i != end; ++i )
{ {
p = *i; p = *i;
if ( p->is_enabled() ) {
p->close();
}
if ( p->is_enabled() ) { delete p;
p->close();
}
} }
io_channels.clear();
} }
void void

View file

@ -45,7 +45,7 @@ public:
void unbind(); void unbind();
void update( double dt ); void update( double dt );
void shutdown_all(); void shutdown();
private: private:
@ -55,7 +55,9 @@ private:
// define the global I/O channel list // define the global I/O channel list
//io_container global_io_list; //io_container global_io_list;
std::vector< FGProtocol* > io_channels;
typedef std::vector< FGProtocol* > ProtocolVec;
ProtocolVec io_channels;
}; };

View file

@ -172,6 +172,7 @@ FGGlobals::~FGGlobals()
delete ai; delete ai;
} }
subsystem_mgr->shutdown();
subsystem_mgr->unbind(); subsystem_mgr->unbind();
delete subsystem_mgr; delete subsystem_mgr;