123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- // SNF4CGP/ExecutiveProcess.cpp
- // Copyright (C) 2009 ARM Research Labs, LLC.
- // See www.armresearch.com for more information.
-
- #include "ExecutiveProcess.hpp"
-
- #include "../CodeDweller/faults.hpp"
-
- #include <iostream>
- #include <string>
- #include <sstream>
-
- using namespace std;
-
- void ExecutiveProcess::initializeOutput() {
- Output.init(Jobs);
- }
-
- void ExecutiveProcess::initializeJobPool() {
- Jobs.init(VersionInfo, ConfigInfo, Output);
- }
-
- void ExecutiveProcess::initializeWorkerPool() {
- Workers.init();
- }
-
- void ExecutiveProcess::shutdownWorkerPool() {
- Workers.stop();
- }
-
- void ExecutiveProcess::shutdownJobPool() {
- Jobs.stop();
- }
-
- void ExecutiveProcess::shutdownOutput() {
- Output.stop();
- }
-
- void ExecutiveProcess::dispatchCommand(Command& C) { // Job + Worker + Command; go!
- Job& J = Jobs.grab();
- J.setCommand(C);
- Worker& W = Workers.grab();
- W.doJob(J);
- }
-
- ExecutiveProcess::ExecutiveProcess(const string& Version, const string& Config) : // Simple construction.
- VersionInfo(Version),
- ConfigInfo(Config),
- QuitJobNumber(0) {}
-
- ExecutiveProcess::~ExecutiveProcess() { // Deal with uncerimoneous shutdowns.
- }
-
- void ExecutiveProcess::doStartup() { // Startup happens in this sequence.
- initializeJobPool();
- initializeOutput();
- initializeWorkerPool();
- }
-
- void ExecutiveProcess::dispatchWakeupCommand() {
- Command C;
- C.Type = Command::WAKE; // Create the WAKE command to announce
- C.Data = VersionInfo; // that we are alive (and who we are)
- dispatchCommand(C); // and dispatch a job with it.
- }
-
- void ExecutiveProcess::notifyQUIT() {
- ostringstream O;
- O << "* SNF4CGP[" << QuitJobNumber << "] Received QUIT, shutting down..." << endl;
- Output.sendString(O.str());
- }
-
- void ExecutiveProcess::notifyNOTGOOD() {
- ostringstream O;
- O << "* SNF4CGP Input stream has gone bad, shutting down..." << endl;
- Output.sendString(O.str());
- }
-
- void ExecutiveProcess::doProcessing() { // Command processing happens here.
- dispatchWakeupCommand(); // First job is to announce ourselves.
- for(;;) { // Then process all jobs but QUIT.
- Command C = Input.getCommand();
- switch(C.Type) {
-
- case Command::QUIT: {
- QuitJobNumber = C.Number;
- notifyQUIT();
- return;
- }
-
- case Command::NOTGOOD: {
- notifyNOTGOOD();
- return;
- }
-
- default: {
- dispatchCommand(C);
- continue;
- }
- }
- }
- }
-
- void ExecutiveProcess::doShutdown() { // Shutdown happens in this sequence.
- shutdownWorkerPool();
- shutdownOutput();
- shutdownJobPool();
- cout << "* SNF4CGP Shutdown completed." << endl;
- if(0 < QuitJobNumber) { // If processing ended with QUIT
- cout << QuitJobNumber << " OK" << endl; // then respond appropriately.
- }
- cout.flush();
- }
|