Browse Source

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 years ago
parent
commit
67a3f85926
4 changed files with 34 additions and 13 deletions
  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 View File

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

+ 21
- 7
SNF4CGP/ExecutiveProcess.cpp View File

dispatchWakeupCommand(); // First job is to announce ourselves. dispatchWakeupCommand(); // First job is to announce ourselves.
for(;;) { // Then process all jobs but QUIT. for(;;) { // Then process all jobs but QUIT.
Command C = Input.getCommand(); 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);
}
} }
} }
} }
shutdownOutput(); shutdownOutput();
shutdownJobPool(); shutdownJobPool();
cout << "* SNF4CGP Shutdown completed." << endl; cout << "* SNF4CGP Shutdown completed." << endl;
cout << QuitJobNumber << " OK" << endl;
if(0 < QuitJobNumber) {
cout << QuitJobNumber << " OK" << endl;
}
cout.flush(); cout.flush();
} }

+ 11
- 5
SNF4CGP/InputProcessor.cpp View File

} }
Command InputProcessor::getCommand() { // How to get/parse a command Command InputProcessor::getCommand() { // How to get/parse a command
Command NewCommand;
string InputLine; string InputLine;
getline(cin, InputLine); getline(cin, InputLine);
istringstream InputLineStream(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; return NewCommand;
} }

+ 1
- 1
SNF4CGP/main.cpp View File

using namespace std; // Introduce standard namespace. 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 ConfigPathArgNumber = 1;
const int CorrectArgcNumber = 2; const int CorrectArgcNumber = 2;

Loading…
Cancel
Save