#include <simgear/compiler.h>
+#include <stdlib.h> // atoi()
+
#include STL_STRING
#include <simgear/debug/logstream.hxx>
#include <Network/protocol.hxx>
#include <Network/atlas.hxx>
#include <Network/garmin.hxx>
+#include <Network/httpd.hxx>
#include <Network/joyclient.hxx>
#include <Network/native.hxx>
#include <Network/native_ctrls.hxx>
// configure a port based on the config string
static FGProtocol *parse_port_config( const string& config )
{
+ bool short_circuit = false;
+
string::size_type begin, end;
begin = 0;
} else if ( protocol == "garmin" ) {
FGGarmin *garmin = new FGGarmin;
io = garmin;
+ } else if ( protocol == "httpd" ) {
+ // determine port
+ string port = config.substr(begin);
+ FGHttpd *httpd = new FGHttpd( atoi(port.c_str()) );
+ io = httpd;
+ short_circuit = true;
} else if ( protocol == "joyclient" ) {
FGJoyClient *joyclient = new FGJoyClient;
io = joyclient;
return NULL;
}
- // determine medium
- end = config.find(",", begin);
- if ( end == string::npos ) {
- return NULL; // dummy
- }
+ if ( ! short_circuit ) {
+ // determine medium
+ end = config.find(",", begin);
+ if ( end == string::npos ) {
+ return NULL; // dummy
+ }
- string medium = config.substr(begin, end - begin);
- begin = end + 1;
- SG_LOG( SG_IO, SG_INFO, " medium = " << medium );
-
- // determine direction
- end = config.find(",", begin);
- if ( end == string::npos ) {
- return NULL; // dummy
- }
+ string medium = config.substr(begin, end - begin);
+ begin = end + 1;
+ SG_LOG( SG_IO, SG_INFO, " medium = " << medium );
+
+ // determine direction
+ end = config.find(",", begin);
+ if ( end == string::npos ) {
+ return NULL; // dummy
+ }
- string direction = config.substr(begin, end - begin);
- begin = end + 1;
- io->set_direction( direction );
- SG_LOG( SG_IO, SG_INFO, " direction = " << direction );
-
- // determine hertz
- end = config.find(",", begin);
- if ( end == string::npos ) {
- return NULL; // dummy
- }
+ string direction = config.substr(begin, end - begin);
+ begin = end + 1;
+ io->set_direction( direction );
+ SG_LOG( SG_IO, SG_INFO, " direction = " << direction );
+
+ // determine hertz
+ end = config.find(",", begin);
+ if ( end == string::npos ) {
+ return NULL; // dummy
+ }
- string hertz_str = config.substr(begin, end - begin);
- begin = end + 1;
- double hertz = atof( hertz_str.c_str() );
- io->set_hz( hertz );
- SG_LOG( SG_IO, SG_INFO, " hertz = " << hertz );
-
- if ( medium == "serial" ) {
- // device name
- end = config.find(",", begin);
- if ( end == string::npos ) {
- return NULL;
- }
+ string hertz_str = config.substr(begin, end - begin);
+ begin = end + 1;
+ double hertz = atof( hertz_str.c_str() );
+ io->set_hz( hertz );
+ SG_LOG( SG_IO, SG_INFO, " hertz = " << hertz );
+
+ if ( medium == "serial" ) {
+ // device name
+ end = config.find(",", begin);
+ if ( end == string::npos ) {
+ return NULL;
+ }
- string device = config.substr(begin, end - begin);
- begin = end + 1;
- SG_LOG( SG_IO, SG_INFO, " device = " << device );
-
- // baud
- string baud = config.substr(begin);
- SG_LOG( SG_IO, SG_INFO, " baud = " << baud );
-
- SGSerial *ch = new SGSerial( device, baud );
- io->set_io_channel( ch );
- } else if ( medium == "file" ) {
- // file name
- string file = config.substr(begin);
- SG_LOG( SG_IO, SG_INFO, " file name = " << file );
-
- SGFile *ch = new SGFile( file );
- io->set_io_channel( ch );
- } else if ( medium == "socket" ) {
- // hostname
- end = config.find(",", begin);
- if ( end == string::npos ) {
- return NULL;
- }
+ string device = config.substr(begin, end - begin);
+ begin = end + 1;
+ SG_LOG( SG_IO, SG_INFO, " device = " << device );
+
+ // baud
+ string baud = config.substr(begin);
+ SG_LOG( SG_IO, SG_INFO, " baud = " << baud );
+
+ SGSerial *ch = new SGSerial( device, baud );
+ io->set_io_channel( ch );
+ } else if ( medium == "file" ) {
+ // file name
+ string file = config.substr(begin);
+ SG_LOG( SG_IO, SG_INFO, " file name = " << file );
+
+ SGFile *ch = new SGFile( file );
+ io->set_io_channel( ch );
+ } else if ( medium == "socket" ) {
+ // hostname
+ end = config.find(",", begin);
+ if ( end == string::npos ) {
+ return NULL;
+ }
- string hostname = config.substr(begin, end - begin);
- begin = end + 1;
- SG_LOG( SG_IO, SG_INFO, " hostname = " << hostname );
-
- // port string
- end = config.find(",", begin);
- if ( end == string::npos ) {
- return NULL;
- }
+ string hostname = config.substr(begin, end - begin);
+ begin = end + 1;
+ SG_LOG( SG_IO, SG_INFO, " hostname = " << hostname );
+
+ // port string
+ end = config.find(",", begin);
+ if ( end == string::npos ) {
+ return NULL;
+ }
- string port = config.substr(begin, end - begin);
- begin = end + 1;
- SG_LOG( SG_IO, SG_INFO, " port string = " << port );
-
- // socket style
- string style_str = config.substr(begin);
- SG_LOG( SG_IO, SG_INFO, " style string = " << style_str );
-
- SGSocket *ch = new SGSocket( hostname, port, style_str );
- io->set_io_channel( ch );
+ string port = config.substr(begin, end - begin);
+ begin = end + 1;
+ SG_LOG( SG_IO, SG_INFO, " port string = " << port );
+
+ // socket style
+ string style_str = config.substr(begin);
+ SG_LOG( SG_IO, SG_INFO, " style string = " << style_str );
+
+ SGSocket *ch = new SGSocket( hostname, port, style_str );
+ io->set_io_channel( ch );
+ }
}
return io;
// filename = file system file name
static bool
-parse_channel( const string& type, const string& channel_str ) {
+add_channel( const string& type, const string& channel_str ) {
// cout << "Channel string = " << channel_str << endl;
globals->get_channel_options_list()->push_back( type + "," + channel_str );
} else if ( arg == "--hud-culled" ) {
fgSetString("/sim/hud/frame-stat-type", "culled");
} else if ( arg.find( "--atlas=" ) == 0 ) {
- parse_channel( "atlas", arg.substr(8) );
+ add_channel( "atlas", arg.substr(8) );
+ } else if ( arg.find( "--httpd=" ) == 0 ) {
+ add_channel( "httpd", arg.substr(8) );
} else if ( arg.find( "--native=" ) == 0 ) {
- parse_channel( "native", arg.substr(9) );
+ add_channel( "native", arg.substr(9) );
} else if ( arg.find( "--native-ctrls=" ) == 0 ) {
- parse_channel( "native_ctrls", arg.substr(15) );
+ add_channel( "native_ctrls", arg.substr(15) );
} else if ( arg.find( "--garmin=" ) == 0 ) {
- parse_channel( "garmin", arg.substr(9) );
+ add_channel( "garmin", arg.substr(9) );
} else if ( arg.find( "--nmea=" ) == 0 ) {
- parse_channel( "nmea", arg.substr(7) );
+ add_channel( "nmea", arg.substr(7) );
} else if ( arg.find( "--props=" ) == 0 ) {
- parse_channel( "props", arg.substr(8) );
+ add_channel( "props", arg.substr(8) );
} else if ( arg.find( "--pve=" ) == 0 ) {
- parse_channel( "pve", arg.substr(6) );
+ add_channel( "pve", arg.substr(6) );
} else if ( arg.find( "--ray=" ) == 0 ) {
- parse_channel( "ray", arg.substr(6) );
+ add_channel( "ray", arg.substr(6) );
} else if ( arg.find( "--rul=" ) == 0 ) {
- parse_channel( "rul", arg.substr(6) );
+ add_channel( "rul", arg.substr(6) );
} else if ( arg.find( "--joyclient=" ) == 0 ) {
- parse_channel( "joyclient", arg.substr(12) );
+ add_channel( "joyclient", arg.substr(12) );
#ifdef FG_NETWORK_OLK
} else if ( arg == "--disable-network-olk" ) {
fgSetBool("/sim/networking/olk", false);