#include <Network/opengc.hxx>
#include <Network/nmea.hxx>
#include <Network/props.hxx>
-#include <Network/telnet.hxx>
#include <Network/pve.hxx>
#include <Network/ray.hxx>
#include <Network/rul.hxx>
#include "globals.hxx"
+#include "fg_io.hxx"
-SG_USING_NAMESPACE(std);
SG_USING_STD(string);
-// define the global I/O channel list
-io_container global_io_list;
+FGIO::FGIO()
+{
+}
+
+#include STL_ALGORITHM
+SG_USING_STD(for_each);
+
+static void delete_ptr( FGProtocol* p ) { delete p; }
+
+FGIO::~FGIO()
+{
+ shutdown_all();
+ for_each( io_channels.begin(), io_channels.end(), delete_ptr );
+}
// configure a port based on the config string
-static FGProtocol *parse_port_config( const string& config )
+FGProtocol*
+FGIO::parse_port_config( const string& config )
{
SG_LOG( SG_IO, SG_INFO, "Parse I/O channel request: " << config );
try
{
if ( protocol == "atc610x" ) {
- return new FGATC610x;
+ FGATC610x *atc610x = new FGATC610x;
+ atc610x->set_hz( 30 );
+ return atc610x;
} else if ( protocol == "atlas" ) {
FGAtlas *atlas = new FGAtlas;
io = atlas;
} else if ( protocol == "nmea" ) {
FGNMEA *nmea = new FGNMEA;
io = nmea;
- } else if ( protocol == "props" ) {
- io = new FGProps();
- } else if ( protocol == "telnet" ) {
- io = new FGTelnet( tokens );
+ } else if ( protocol == "props" || protocol == "telnet" ) {
+ io = new FGProps( tokens );
return io;
} else if ( protocol == "pve" ) {
FGPVE *pve = new FGPVE;
// step through the port config streams (from fgOPTIONS) and setup
// serial port channels for each
-void fgIOInit() {
+void
+FGIO::init()
+{
// SG_LOG( SG_IO, SG_INFO, "I/O Channel initialization, " <<
// globals->get_channel_options_list()->size() << " requests." );
FGProtocol *p;
- string_list *channel_options_list = globals->get_channel_options_list();
// we could almost do this in a single step except pushing a valid
// port onto the port list copies the structure and destroys the
// parse the configuration strings and store the results in the
// appropriate FGIOChannel structures
- for ( int i = 0; i < (int)channel_options_list->size(); ++i ) {
- p = parse_port_config( (*channel_options_list)[i] );
+ typedef vector<string> container;
+ container::iterator i = globals->get_channel_options_list()->begin();
+ container::iterator end = globals->get_channel_options_list()->end();
+ for (; i != end; ++i )
+ {
+ p = parse_port_config( *i );
if ( p != NULL ) {
p->open();
- global_io_list.push_back( p );
+ io_channels.push_back( p );
if ( !p->is_enabled() ) {
SG_LOG( SG_IO, SG_ALERT, "I/O Channel config failed." );
exit(-1);
// process any serial port work
-void fgIOProcess() {
+void
+FGIO::update( double delta_time_sec )
+{
// cout << "processing I/O channels" << endl;
static int inited = 0;
last = current;
}
- for ( unsigned int i = 0; i < global_io_list.size(); ++i ) {
- // cout << " channel = " << i << endl;
- FGProtocol* p = global_io_list[i];
+ typedef vector< FGProtocol* > container;
+ container::iterator i = io_channels.begin();
+ container::iterator end = io_channels.end();
+ for (; i != end; ++i )
+ {
+ FGProtocol* p = *i;
if ( p->is_enabled() ) {
p->dec_count_down( interval );
}
-// shutdown all I/O connections
-void fgIOShutdownAll() {
+void
+FGIO::shutdown_all() {
FGProtocol *p;
// cout << "processing I/O channels" << endl;
- for ( int i = 0; i < (int)global_io_list.size(); ++i ) {
- // cout << " channel = " << i << endl;
- p = global_io_list[i];
+ typedef vector< FGProtocol* > container;
+ container::iterator i = io_channels.begin();
+ container::iterator end = io_channels.end();
+ for (; i != end; ++i )
+ {
+ p = *i;
if ( p->is_enabled() ) {
p->close();
}
}
}
+
+void
+FGIO::bind()
+{
+}
+
+void
+FGIO::unbind()
+{
+}
+