git-svn-id: https://svn.microneil.com/svn/SNF4CGP/trunk@33 59e8e3e7-56fa-483b-b4b4-fa6ab0af3dfcmaster
@@ -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. |
@@ -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(); | |||
} |
@@ -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; | |||
} |
@@ -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; |