} 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)" );
#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") {
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;
}
if (direction != "in" && direction != "out" && direction != "bi") {
SG_LOG(SG_NETWORK, SG_ALERT, "Unsuported protocol direction: "
<< direction);
+ return;
}
reinit();
}
}
}
+
+ initOk = true;
}
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 };
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)