1
0
Fork 0

Proper error checks for generic protocol.

Drop FGGeneric instances which failed to initialize to avoid run-time
issues.
This commit is contained in:
ThorstenB 2012-07-13 20:33:36 +02:00
parent 26aeb84399
commit 39a7caae15
3 changed files with 18 additions and 21 deletions

View file

@ -196,24 +196,16 @@ FGIO::parse_port_config( const string& config )
} else if ( protocol == "rul" ) { } else if ( protocol == "rul" ) {
FGRUL *rul = new FGRUL; FGRUL *rul = new FGRUL;
io = rul; io = rul;
} else if ( protocol == "generic" ) { } else if ( protocol == "generic" ) {
size_t configToken; FGGeneric *generic = new FGGeneric( tokens );
if (tokens[1] == "socket") { if (!generic->getInitOk())
configToken = 7; {
} else if (tokens[1] == "file") { // failed to initialize (i.e. invalid configuration)
configToken = 5; delete generic;
} else { return NULL;
configToken = 6; }
} io = generic;
} else if ( protocol == "multiplay" ) {
if (configToken >= tokens.size()) {
SG_LOG( SG_IO, SG_ALERT, "Not enough tokens passed for the generic protocol.");
return NULL;
}
FGGeneric *generic = new FGGeneric( tokens );
io = generic;
} else if ( protocol == "multiplay" ) {
if ( tokens.size() != 5 ) { if ( tokens.size() != 5 ) {
SG_LOG( SG_IO, SG_ALERT, "Ignoring invalid --multiplay option " SG_LOG( SG_IO, SG_ALERT, "Ignoring invalid --multiplay option "
"(4 arguments expected: --multiplay=dir,hz,hostname,port)" ); "(4 arguments expected: --multiplay=dir,hz,hostname,port)" );

View file

@ -42,7 +42,7 @@
#include <Main/util.hxx> #include <Main/util.hxx>
#include "generic.hxx" #include "generic.hxx"
FGGeneric::FGGeneric(vector<string> tokens) : exitOnError(false) FGGeneric::FGGeneric(vector<string> tokens) : exitOnError(false), initOk(false)
{ {
size_t configToken; size_t configToken;
if (tokens[1] == "socket") { if (tokens[1] == "socket") {
@ -53,9 +53,9 @@ FGGeneric::FGGeneric(vector<string> tokens) : exitOnError(false)
configToken = 6; configToken = 6;
} }
if (configToken >= tokens.size()) { if ((configToken >= tokens.size())||(tokens[ configToken ] == "")) {
SG_LOG(SG_NETWORK, SG_ALERT, SG_LOG(SG_NETWORK, SG_ALERT,
"Not enough tokens passed for generic protocol"); "Not enough tokens passed for generic '" << tokens[1] << "' protocol. ");
return; return;
} }
@ -66,6 +66,7 @@ FGGeneric::FGGeneric(vector<string> tokens) : exitOnError(false)
if (direction != "in" && direction != "out" && direction != "bi") { if (direction != "in" && direction != "out" && direction != "bi") {
SG_LOG(SG_NETWORK, SG_ALERT, "Unsuported protocol direction: " SG_LOG(SG_NETWORK, SG_ALERT, "Unsuported protocol direction: "
<< direction); << direction);
return;
} }
reinit(); reinit();
@ -557,6 +558,8 @@ FGGeneric::reinit()
} }
} }
} }
initOk = true;
} }

View file

@ -57,6 +57,7 @@ public:
void setExitOnError(bool val) { exitOnError = val; } void setExitOnError(bool val) { exitOnError = val; }
bool getExitOnError() { return exitOnError; } bool getExitOnError() { return exitOnError; }
bool getInitOk(void) { return initOk; }
protected: protected:
enum e_type { FG_BOOL=0, FG_INT, FG_FLOAT, FG_DOUBLE, FG_STRING, FG_FIXED }; enum e_type { FG_BOOL=0, FG_INT, FG_FLOAT, FG_DOUBLE, FG_STRING, FG_FIXED };
@ -102,6 +103,7 @@ private:
bool parse_message_binary(int length); bool parse_message_binary(int length);
void read_config(SGPropertyNode *root, vector<_serial_prot> &msg); void read_config(SGPropertyNode *root, vector<_serial_prot> &msg);
bool exitOnError; bool exitOnError;
bool initOk;
template<class T> template<class T>
static void updateValue(_serial_prot& prot, const T& val) static void updateValue(_serial_prot& prot, const T& val)