try to make ascii reader a little bit more robust to failure - mainly ignore messages after a reader has disabled itself

This commit is contained in:
Bernhard Amann 2012-02-22 08:56:45 -08:00
parent d5b413c4e7
commit 531189b5fd
3 changed files with 31 additions and 4 deletions

View file

@ -203,6 +203,9 @@ bool ReaderBackend::Init(string arg_source, int mode, bool arg_autostart)
}
bool ReaderBackend::StartReading() {
if ( disabled )
return false;
int success = DoStartReading();
if ( success == false ) {
@ -215,6 +218,9 @@ bool ReaderBackend::StartReading() {
bool ReaderBackend::AddFilter(int id, int arg_num_fields,
const Field* const * arg_fields)
{
if ( disabled )
return false;
bool success = DoAddFilter(id, arg_num_fields, arg_fields);
if ( success && autostart) {
autostart = false;
@ -225,6 +231,9 @@ bool ReaderBackend::AddFilter(int id, int arg_num_fields,
bool ReaderBackend::RemoveFilter(int id)
{
if ( disabled )
return false;
bool success = DoRemoveFilter(id);
SendOut(new FilterRemovedMessage(frontend, id));
return success; // yes, I know, noone reads this.
@ -240,11 +249,20 @@ void ReaderBackend::Finish()
bool ReaderBackend::Update()
{
return DoUpdate();
if ( disabled )
return false;
bool success = DoUpdate();
if ( !success ) {
DisableFrontend();
}
return success;
}
void ReaderBackend::DisableFrontend()
{
disabled = true; // we also set disabled here, because there still may be other messages queued and we will dutifully ignore these from now
SendOut(new DisableMessage(frontend));
}

View file

@ -177,7 +177,12 @@ protected:
*
* A reader implementation must override this method but it can just ignore
* calls, if a forced update does not fit the input source or the current input
* reading mode
* reading mode.
*
* If it returns false, it will be assumed that a fatal error has occured
* that prevents the reader from further operation; it will then be
* disabled and eventually deleted. When returning false, an implementation
* should also call Error to indicate what happened.
*/
virtual bool DoUpdate() = 0;

View file

@ -458,7 +458,10 @@ bool Ascii::DoUpdate() {
if ( file && file->is_open() ) {
if ( mode == STREAM ) {
file->clear(); // remove end of file evil bits
ReadHeader(true); // in case filters changed
if ( !ReadHeader(true) ) // in case filters changed
{
return false; // header reading failed
}
break;
}
file->close();
@ -522,6 +525,7 @@ bool Ascii::DoUpdate() {
Value* val = EntryToVal(stringfields[(*fit).position], *fit);
if ( val == 0 ) {
Error("Could not convert String value to Val");
return false;
}
@ -580,7 +584,7 @@ bool Ascii::DoHeartbeat(double network_time, double current_time)
break;
case REREAD:
case STREAM:
DoUpdate();
Update(); // call update and not DoUpdate, because update actually checks disabled.
break;
default:
assert(false);