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" ) {
FGRUL *rul = new FGRUL;
io = rul;
} else if ( protocol == "generic" ) {
size_t configToken;
if (tokens[1] == "socket") {
configToken = 7;
} else if (tokens[1] == "file") {
configToken = 5;
} else {
configToken = 6;
}
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" ) {
} else if ( protocol == "generic" ) {
FGGeneric *generic = new FGGeneric( tokens );
if (!generic->getInitOk())
{
// failed to initialize (i.e. invalid configuration)
delete generic;
return NULL;
}
io = generic;
} else if ( protocol == "multiplay" ) {
if ( tokens.size() != 5 ) {
SG_LOG( SG_IO, SG_ALERT, "Ignoring invalid --multiplay option "
"(4 arguments expected: --multiplay=dir,hz,hostname,port)" );

View file

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

View file

@ -57,6 +57,7 @@ public:
void setExitOnError(bool val) { exitOnError = val; }
bool getExitOnError() { return exitOnError; }
bool getInitOk(void) { return initOk; }
protected:
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);
void read_config(SGPropertyNode *root, vector<_serial_prot> &msg);
bool exitOnError;
bool initOk;
template<class T>
static void updateValue(_serial_prot& prot, const T& val)