Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ExecutiveProcess.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SNF4CGP/ExecutiveProcess.cpp
  2. // Copyright (C) 2009 ARM Research Labs, LLC.
  3. // See www.armresearch.com for more information.
  4. #include "ExecutiveProcess.hpp"
  5. #include "../SNF4CGP/CodeDweller/faults.hpp"
  6. #include <iostream>
  7. using namespace std;
  8. RuntimeCheck CheckOutputProccessorWasConstructed("ExecutiveProcess::initializeOutput() Check(0 != Output)");
  9. RuntimeCheck CheckOutputProcessorWasStarted("ExecutiveProcess::initializeOutput() Check(Output->isRunning())");
  10. void ExecutiveProcess::initializeOutput() {
  11. try { Output = new OutputProcessor(*Jobs); } catch(...) {}
  12. CheckOutputProcessorWasConstructed(0 != Output);
  13. try { Output->start() } catch(...) {}
  14. CheckOutputProcessorWasStarted(Output->isRunning());
  15. }
  16. void ExecutiveProcess::initializeJobPool() {
  17. }
  18. void ExecutiveProcess::initializeWorkerPool() {
  19. }
  20. void ExecutiveProcess::shutdownWorkerPool() {
  21. }
  22. void ExecutiveProcess::shutdownJobPool() {
  23. }
  24. void ExecutiveProcess::shutdownOutput() {
  25. }
  26. void ExecutiveProcess::dispatchCommand(Command& C) { // Job + Worker + Command; go!
  27. }
  28. ExecutiveProcess::ExecutiveProcess(string& Version, string& Config) : // Simple construction.
  29. VersionInfo(Version),
  30. ConfigInfo(Config),
  31. Jobs(0),
  32. Workers(0),
  33. Input(0),
  34. Output(0),
  35. QuitJobNumber(0) {}
  36. ~ExecutiveProcess::ExecutiveProcess() { // Deal with uncerimoneous shutdowns.
  37. }
  38. void ExecutiveProcess::doStartup() { // Startup happens in this sequence.
  39. initializeJobPool();
  40. initializeOutput();
  41. initializeWorkerPool();
  42. }
  43. void ExecutiveProcess::doProcessing() { // Command processing happens here.
  44. Command C;
  45. C.CommandType = WAKE; // Create the WAKE command to announce
  46. C.Data = VersionInfo; // that we are alive (and who we are)
  47. dispatchCommand(C); // and dispatch a job with it.
  48. // Then process all incoming commands:
  49. InputProcessor& I = *Input; // Convenient handle for input processor.
  50. for(;0 == QuitJobNumber;) { // Loop until we have a QUIT job.
  51. C = I.getCommand(); // Get a command from the input.
  52. if(QUIT == C.CommandType) QuitJobNumber = C.Number; // QUIT command means it's time to stop.
  53. else dispatchCommand(C); // Dispatch a job for all other commands.
  54. }
  55. }
  56. void ExecutiveProcess::doShutdown() { // Shutdown happens in this sequence.
  57. shutdownWorkerPool();
  58. shutdownOutput();
  59. shutdownJobPool();
  60. cout << QuitJobNumber << " OK" << endl;
  61. }