Quellcode durchsuchen

Fixed bad cin bug - if cin went bad the executive process would loop, rapidly generate UNKNOWN commands, and produce FAILURE outputs. This would happen when CGP was disabling the plugin (Specs say the plugin should get QUIT first, but it didn't). The fix creates a new Command::NOTGOOD that is produced by getCommand() if cin.good() becomes false. The executive process responds to Command::NOTGOOD by announcing the input has gone bad and then shutting down cleanly.

git-svn-id: https://svn.microneil.com/svn/SNF4CGP/trunk@33 59e8e3e7-56fa-483b-b4b4-fa6ab0af3dfc
master
madscientist vor 15 Jahren
Ursprung
Commit
67a3f85926
4 geänderte Dateien mit 34 neuen und 13 gelöschten Zeilen
  1. 1
    0
      SNF4CGP/Command.hpp
  2. 21
    7
      SNF4CGP/ExecutiveProcess.cpp
  3. 11
    5
      SNF4CGP/InputProcessor.cpp
  4. 1
    1
      SNF4CGP/main.cpp

+ 1
- 0
SNF4CGP/Command.hpp Datei anzeigen

@@ -15,6 +15,7 @@ class Command {
public:
enum CommandType { // Commands have these types:
NOTGOOD, // cin.good() has become false.
UNKNOWN, // We don't know this command.
QUIT, // It is time to stop the app.
WAKE, // Report the app is now awake.

+ 21
- 7
SNF4CGP/ExecutiveProcess.cpp Datei anzeigen

@@ -66,12 +66,24 @@ void ExecutiveProcess::doProcessing() {
dispatchWakeupCommand(); // First job is to announce ourselves.
for(;;) { // Then process all jobs but QUIT.
Command C = Input.getCommand();
if(Command::QUIT != C.Type) dispatchCommand(C);
else {
QuitJobNumber = C.Number;
cout << "* SNF4CGP[" << C.Number << "] Received QUIT, shutting down..." << endl;
cout.flush();
return;
switch(C.Type) {
case Command::QUIT: {
QuitJobNumber = C.Number;
cout << "* SNF4CGP[" << C.Number << "] Received QUIT, shutting down..." << endl;
cout.flush();
return;
}
case Command::NOTGOOD: {
cout << "* SNF4CGP Input stream has gone bad, shutting down..." << endl;
cout.flush();
return;
}
default: {
dispatchCommand(C);
}
}
}
}
@@ -81,6 +93,8 @@ void ExecutiveProcess::doShutdown() {
shutdownOutput();
shutdownJobPool();
cout << "* SNF4CGP Shutdown completed." << endl;
cout << QuitJobNumber << " OK" << endl;
if(0 < QuitJobNumber) {
cout << QuitJobNumber << " OK" << endl;
}
cout.flush();
}

+ 11
- 5
SNF4CGP/InputProcessor.cpp Datei anzeigen

@@ -43,16 +43,22 @@ Command& parseCommandData(istringstream& S, Command& C) {
}
Command InputProcessor::getCommand() { // How to get/parse a command
Command NewCommand;
string InputLine;
getline(cin, InputLine);
istringstream InputLineStream(InputLine);
Command NewCommand;
parseCommandNumber(InputLineStream, NewCommand); // First thing is always a number.
parseCommandType(InputLineStream, NewCommand); // Next is always a command name.
parseCommandData(InputLineStream, NewCommand); // The rest is data for the command.
if(cin.good()) {
parseCommandNumber(InputLineStream, NewCommand); // First thing is always a number.
parseCommandType(InputLineStream, NewCommand); // Next is always a command name.
parseCommandData(InputLineStream, NewCommand); // The rest is data for the command.
if(Command::UNKNOWN == NewCommand.Type) NewCommand.Data = InputLine; // Capture unknown inputs for later.
if(Command::UNKNOWN == NewCommand.Type) NewCommand.Data = InputLine; // Capture unknown inputs for later.
} else {
NewCommand.Type = Command::NOTGOOD;
}
return NewCommand;
}

+ 1
- 1
SNF4CGP/main.cpp Datei anzeigen

@@ -13,7 +13,7 @@
using namespace std; // Introduce standard namespace.
const string SNF4CGP_VERSION_INFO = "SNF4CGP Version 0.0.1 Build: " __DATE__ " " __TIME__;
const string SNF4CGP_VERSION_INFO = "SNF4CGP Version 0.0.2 Build: " __DATE__ " " __TIME__;
const int ConfigPathArgNumber = 1;
const int CorrectArgcNumber = 2;

Laden…
Abbrechen
Speichern