瀏覽代碼

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 15 年之前
父節點
當前提交
67a3f85926
共有 4 個檔案被更改,包括 34 行新增13 行删除
  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 查看文件

@@ -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 查看文件

@@ -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 查看文件

@@ -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 查看文件

@@ -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;

Loading…
取消
儲存