Source

mana-core-gaudikernel / GaudiKernel / StateMachine.h

#ifndef GAUDIKERNEL_STATEMACHINE_H_
#define GAUDIKERNEL_STATEMACHINE_H_

#include "GaudiKernel/GaudiException.h"

namespace Gaudi {
namespace StateMachine {
/**
 * Allowed states for classes implementing the state machine (ApplicationMgr,
 * Algorithm, Service, AlgTool).
 */
enum State {
  OFFLINE,
  CONFIGURED,
  INITIALIZED,
  RUNNING//,
  //FINALIZED = CONFIGURED
};

/**
 * Allowed transitions between states.
 */
enum Transition {
  CONFIGURE,  // OFFLINE     -> CONFIGURED
  INITIALIZE, // CONFIGURED  -> INITIALIZED
  START,      // INITIALIZED -> RUNNING
  STOP,       // RUNNING     -> INITIALIZED
  FINALIZE,   // INITIALIZED -> CONFIGURED
  TERMINATE   // CONFIGURED  -> OFFLINE
};

/**
 * Function to get the new state according to the required transition, checking
 * if the transition is allowed.
 */
State GAUDI_API ChangeState(const Transition transition, const State state);

} // namespace Gaudi
} // namespace StateMachine

/// Pretty print of states.
inline std::ostream & operator << (std::ostream & s, const Gaudi::StateMachine::State &st) {
  switch (st) {
  case Gaudi::StateMachine::OFFLINE     : return s << "OFFLINE";
  case Gaudi::StateMachine::CONFIGURED  : return s << "CONFIGURED";
  case Gaudi::StateMachine::INITIALIZED : return s << "INITIALIZED";
  case Gaudi::StateMachine::RUNNING     : return s << "RUNNING";
  }
  return s; // cannot be reached, but make the compiler happy
}

/// Pretty print of transitions.
inline std::ostream & operator << (std::ostream & s, const Gaudi::StateMachine::Transition &t) {
  switch (t) {
  case Gaudi::StateMachine::CONFIGURE  : return s << "CONFIGURE";
  case Gaudi::StateMachine::INITIALIZE : return s << "INITIALIZE";
  case Gaudi::StateMachine::START      : return s << "START";
  case Gaudi::StateMachine::STOP       : return s << "STOP";
  case Gaudi::StateMachine::FINALIZE   : return s << "FINALIZE";
  case Gaudi::StateMachine::TERMINATE  : return s << "TERMINATE";
  }
  return s; // cannot be reached, but make the compiler happy
}

#endif /*GAUDIKERNEL_STATEMACHINE_H_*/
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.