Manages simulation execution. More...
#include <simulation_manager.h>
Classes | |
struct | RequestResult |
Helper structure for storing request result and error messages. More... | |
Public Types | |
enum | SimState { SimState::Created, SimState::Initialized, SimState::Running, SimState::Stopped, SimState::Failed, SimState::NotSet } |
States the simulation can be in. More... | |
![]() | |
using | shared_ptr = std::shared_ptr< SimulationManager > |
using | const_shared_ptr = std::shared_ptr< const SimulationManager > |
using | unique_ptr = std::unique_ptr< SimulationManager > |
using | const_unique_ptr = std::unique_ptr< const SimulationManager > |
Public Member Functions | |
SimulationManager (const jsonSharedPtr &simulationConfig) | |
Constructor. More... | |
SimulationManager ()=delete | |
virtual | ~SimulationManager ()=default |
RequestResult | initializeSimulation () |
Initialize the simulation. More... | |
RequestResult | resetSimulation () |
Reset the currently running simulation. More... | |
RequestResult | stopSimulation () |
Request to stop the simulation if it was running, if it wasn't the call has no effect. More... | |
RequestResult | runSimulationUntilDoneOrTimeout () |
Runs the simulation until a separate thread stops it or simTimeout (defined in SimulationConfig) is reached. If simTimeout is zero or negative, ignore it. More... | |
virtual bool | hasSimulationTimedOut () const =0 |
RequestResult | runSimulation (unsigned numIterations) |
Run the Simulation for specified amount of timesteps. More... | |
RequestResult | shutdownSimulation () |
Shuts down the simulation. More... | |
SimState | currentState () |
returns the current state of the simulation More... | |
std::string | printSimState (const SimState &simState) |
returns a simulation state as a string More... | |
SimulationDataManager & | getSimulationDataManager () |
Static Public Member Functions | |
static void | validateConfig (jsonSharedPtr &config) |
Validates config against Simulation schema. More... | |
Protected Member Functions | |
virtual void | initializeCB ()=0 |
Initialize the simulation. More... | |
virtual bool | resetCB ()=0 |
Resets the simulation, returns true if the simulation was reset false otherwise. More... | |
virtual void | stopCB ()=0 |
Forward request to stop the simulation. More... | |
virtual bool | runUntilDoneOrTimeoutCB ()=0 |
Run the simulation. More... | |
virtual bool | runCB (unsigned numIterations)=0 |
Run the simulation. More... | |
virtual void | shutdownCB ()=0 |
Shutdown the simulation. More... | |
Protected Attributes | |
jsonSharedPtr | _simConfig |
Simulation Configuration. More... | |
SimulationDataManager | _simulationDataManager |
SimulationTime | _simTimeout = SimulationTime::zero() |
Manages simulation execution.
Maintain the current state of the simulation and process control requests according to this state.
Control request methods are processed sequentially guarded by a lock, with the exception of "stopSimulation", which can be processed in parallel.
Control requests are forwarded to Implementations of this interface via a set of callbacks. Exceptions occurring in these callbacks are handled by SimulationManager by transitioning the simulation to state "Failed", from which the only possible action is to shutdown the simulation.
Calling a control request from the wrong state triggers an exception
|
strong |
SimulationManager::SimulationManager | ( | const jsonSharedPtr & | simulationConfig | ) |
Constructor.
simulationConfig | Simulation configuration |
|
delete |
|
virtualdefault |
SimulationManager::SimState SimulationManager::currentState | ( | ) |
returns the current state of the simulation
SimulationDataManager & SimulationManager::getSimulationDataManager | ( | ) |
|
pure virtual |
Implemented in FTILoopSimManager, and EventLoopSimManager.
|
protectedpure virtual |
Initialize the simulation.
SimulationManager::RequestResult SimulationManager::initializeSimulation | ( | ) |
Initialize the simulation.
std::string SimulationManager::printSimState | ( | const SimState & | simState | ) |
returns a simulation state as a string
|
protectedpure virtual |
Resets the simulation, returns true if the simulation was reset false otherwise.
SimulationManager::RequestResult SimulationManager::resetSimulation | ( | ) |
Reset the currently running simulation.
|
protectedpure virtual |
Run the simulation.
SimulationManager::RequestResult SimulationManager::runSimulation | ( | unsigned | numIterations | ) |
Run the Simulation for specified amount of timesteps.
numIterations | Number of iterations (i.e timesteps) to run simulation |
SimulationManager::RequestResult SimulationManager::runSimulationUntilDoneOrTimeout | ( | ) |
Runs the simulation until a separate thread stops it or simTimeout (defined in SimulationConfig) is reached. If simTimeout is zero or negative, ignore it.
|
protectedpure virtual |
Run the simulation.
|
protectedpure virtual |
Shutdown the simulation.
SimulationManager::RequestResult SimulationManager::shutdownSimulation | ( | ) |
Shuts down the simulation.
|
protectedpure virtual |
Forward request to stop the simulation.
SimulationManager::RequestResult SimulationManager::stopSimulation | ( | ) |
Request to stop the simulation if it was running, if it wasn't the call has no effect.
It is not blocking, i.e. it is not guaranteed that the simulation is in state "Stopped" after the call returns. The simulation will stop after the the "runSimulation" request that started it returns.
|
static |
Validates config against Simulation schema.
config | Pointer to a config |
|
protected |
Simulation Configuration.
|
protected |
|
protected |