SurgSim::Framework::Runtime Class Reference

This class contains all the information about the runtime environment of the simulation, all the running threads, the state, while it is de facto a singleton it should be passed around if needed. More...

`#include <SurgSim/Framework/Runtime.h>`

Inheritance diagram for SurgSim::Framework::Runtime:

## Public Member Functions

| Runtime ()
| Default constructor. More...
| Runtime (const std::string &configFilePath)
| Constructor, initializes the search path with paths from the given file. More...
| ~Runtime ()
| Destructor. More...
void | addManager (std::shared_ptr< ComponentManager > thread)
| Add a worker thread, this should probably only be possible if the system is not running. More...
std::vector< std::weak_ptr< ComponentManager > > | getManagers () const
template<class T >
std::shared_ptr< T > | getManager () const
std::shared_ptr< Scene > | getScene ()
std::shared_ptr< Scene > | getScene () const
bool | addSceneElement (std::shared_ptr< SceneElement > sceneElement)
| Adds a scene element. More...
bool | execute ()
| Start all the threads and block until one of them quits. More...
bool | start (bool paused=false)
| Start all the threads non returns after the startup as succeeded. More...
void | pause ()
| Pause all managers, this will set all managers to synchronous execution, they will all complete their updates and then wait for step() to proceed, call resume to go back to uninterupted execution. More...
void | resume ()
| Resume from pause, causes all managers to resume normal processing. More...
void | step ()
| Make all managers execute 1 update loop, afterwards they will wait for another step() call or resume() More...
bool | stop ()
| Stops the simulation. More...
bool | isRunning () const
| Query if this object is running. More...
bool | isPaused () const
| Query if this object is paused. More...
void | addComponent (const std::shared_ptr< Component > &component)
| Adds a component. More...
void | removeComponent (const std::shared_ptr< Component > &component)
| Removes the component described by component. More...
void | loadScene (const std::string &fileName)
| Loads the scene from the given file, clears all the elements in the scene, the old scene will be overwritten. More...
void | addSceneElements (const std::string &fileName)
| Adds the scene elements from the file to the current scene The file format should be just a list of sceneElements. More...
std::vector< std::shared_ptr< SceneElement > > | duplicateSceneElements (const std::string &fileName)
| Loads and duplicates the scene elements from the file, the elements will not have common ids with any other cloned elements, this lets you repeatedly load a set of elements to replicate this set. More...
void | saveScene (const std::string &fileName) const
| Write out the whole scene as a file. More...

## Static Public Member Functions

static std::shared_ptr< const ApplicationData > | getApplicationData ()
| Gets application data for the runtime. More...
static std::shared_ptr< ThreadPool > | getThreadPool ()
| Gets the thread pool for the runtime. More...

## Private Member Functions

void | preprocessSceneElements ()
| Preprocess scene elements. More...
void | addComponents (const std::vector< std::shared_ptr< SurgSim::Framework::Component >> &components)
| Adds the components. More...
void | initSearchPaths (const std::string &configFilePath)
| Initializes the search paths. More...
bool | tryConvertElements (const std::string &fileName, const YAML::Node &node, std::vector< std::shared_ptr< SceneElement >> *elements)
| Convert nodes to vector of elements. More...
std::shared_ptr< Runtime > | getSharedPtr ()
| Gets a shared pointer to the runtime. More...

## Private Attributes

bool | m_isRunning
std::vector< std::shared_ptr< ComponentManager > > | m_managers
std::shared_ptr< Scene > | m_scene
boost::mutex | m_sceneHandling
std::shared_ptr< Barrier > | m_barrier
bool | m_isPaused
bool | m_isStopped

## Static Private Attributes

static std::shared_ptr< ApplicationData > | m_applicationData

## Detailed Description

This class contains all the information about the runtime environment of the simulation, all the running threads, the state, while it is de facto a singleton it should be passed around if needed.

Needs to be created as a shared object.

## Constructor & Destructor Documentation

## Runtime() [1/2]

SurgSim::Framework::Runtime::Runtime | ( |  | ) |

Default constructor.

## Runtime() [2/2]

SurgSim::Framework::Runtime::Runtime | ( | const std::string & | configFilePath | ) |

explicit

Constructor, initializes the search path with paths from the given file.

Parameters

  configFilePath | Full pathname of the configuration file that contains paths, one per line, to search for application data. If no config file is given "." will be used as default path.

## ~Runtime()

SurgSim::Framework::Runtime::~Runtime | ( |  | ) |

Destructor.

## Member Function Documentation

## addComponent()

void SurgSim::Framework::Runtime::addComponent | ( | const std::shared_ptr< Component > & | component | ) |

Adds a component.

Parameters

  component | The component.

## addComponents()

void SurgSim::Framework::Runtime::addComponents | ( | const std::vector< std::shared_ptr< SurgSim::Framework::Component >> & | components | ) |

private

Adds the components.

Parameters

  components | The components.

Returns
  true if it succeeds, false if it fails.

## addManager()

void SurgSim::Framework::Runtime::addManager | ( | std::shared_ptr< ComponentManager > | thread | ) |

Add a worker thread, this should probably only be possible if the system is not running.

## addSceneElement()

bool SurgSim::Framework::Runtime::addSceneElement | ( | std::shared_ptr< SceneElement > | sceneElement | ) |

Adds a scene element.

Parameters

  sceneElement | The scene element.

Returns
  true if it succeeds, false if it fails.

## addSceneElements()

void SurgSim::Framework::Runtime::addSceneElements | ( | const std::string & | fileName | ) |

Adds the scene elements from the file to the current scene The file format should be just a list of sceneElements.

- SurgSim::Framework::BasicSceneElement:
Name: element1
IsActive: true
Components:
- MockComponent:
Name: component1
Id: 792faa40-459b-40cf-981d-560a8f2bd1801
- SurgSim::Framework::BasicSceneElement:
Name: element2
IsActive: true
Components:
- MockComponent:
Name: component2
Id: 1de26315-82a7-46b2-ae38-324d25009629

Parameters

  fileName | the filename of the scene to be loaded, needs to be found

Exceptions

  If | the file cannot be found or is an invalid file

## duplicateSceneElements()

std::vector< std::shared_ptr< SceneElement > > SurgSim::Framework::Runtime::duplicateSceneElements | ( | const std::string & | fileName | ) |

Loads and duplicates the scene elements from the file, the elements will not have common ids with any other cloned elements, this lets you repeatedly load a set of elements to replicate this set.

The format is a list of scene elements

See also
  addSceneElements().

Parameters

  fileName | the filename of the scene to be loaded, needs to be found

Exceptions

  if | loading failed

Returns
  a vector of scene elements with the loaded elements

## execute()

bool SurgSim::Framework::Runtime::execute | ( |  | ) |

Start all the threads and block until one of them quits.

## getApplicationData()

std::shared_ptr< const ApplicationData > SurgSim::Framework::Runtime::getApplicationData | ( |  | ) |

static

Gets application data for the runtime.

Returns
  The application data.

## getManager()

template<class T >

std::shared_ptr< T > SurgSim::Framework::Runtime::getManager | ( |  | ) | const

Returns
  The first manager of type T that is found nullptr otherwise

## getManagers()

std::vector< std::weak_ptr< ComponentManager > > SurgSim::Framework::Runtime::getManagers | ( |  | ) | const

Returns
  All the managers from the runtime

## getScene() [1/2]

std::shared_ptr< Scene > SurgSim::Framework::Runtime::getScene | ( |  | ) |

Returns
  The scene to be used for this runtime. Use this for any kind of scene manipulation.

## getScene() [2/2]

std::shared_ptr<Scene> SurgSim::Framework::Runtime::getScene | ( |  | ) | const

Returns
  The current scene

## getSharedPtr()

std::shared_ptr< Runtime > SurgSim::Framework::Runtime::getSharedPtr | ( |  | ) |

private

Gets a shared pointer to the runtime.

Returns
  The shared pointer.

## getThreadPool()

std::shared_ptr< ThreadPool > SurgSim::Framework::Runtime::getThreadPool | ( |  | ) |

static

Gets the thread pool for the runtime.

Returns
  The thread pool.

## initSearchPaths()

void SurgSim::Framework::Runtime::initSearchPaths | ( | const std::string & | configFilePath | ) |

private

Initializes the search paths.

Parameters

  configFilePath | Full pathname of the configuration file, if path is empty "." will be used as default path.

## isPaused()

bool SurgSim::Framework::Runtime::isPaused | ( |  | ) | const

Query if this object is paused.

Returns
  true if paused, false if not.

## isRunning()

bool SurgSim::Framework::Runtime::isRunning | ( |  | ) | const

Query if this object is running.

Returns
  true if running, false if not.

## loadScene()

void SurgSim::Framework::Runtime::loadScene | ( | const std::string & | fileName | ) |

Loads the scene from the given file, clears all the elements in the scene, the old scene will be overwritten.

Parameters

  fileName | the filename of the scene to be loaded, needs to be found

Exceptions

  If | the file cannot be found or is an invalid YAML file

## pause()

void SurgSim::Framework::Runtime::pause | ( |  | ) |

Pause all managers, this will set all managers to synchronous execution, they will all complete their updates and then wait for step() to proceed, call resume to go back to uninterupted execution.

Note
  HS-2013-nov-01 this is mostly to be used as a facillity for testing and debugging, the threads are not executed at the correct rates against each other, this is an issue that can be resolved but is not necessary right now.

## preprocessSceneElements()

void SurgSim::Framework::Runtime::preprocessSceneElements | ( |  | ) |

private

Preprocess scene elements.

This is called during the startup sequence and installs all the Components of the SceneElements in the worker threads

## removeComponent()

void SurgSim::Framework::Runtime::removeComponent | ( | const std::shared_ptr< Component > & | component | ) |

Removes the component described by component.

Parameters

  component | The component.

## resume()

void SurgSim::Framework::Runtime::resume | ( |  | ) |

Resume from pause, causes all managers to resume normal processing.

Warning
  This function is not thread safe, if stop is called when there are threads that are not waiting, this call will hang indefinitely.

## saveScene()

void SurgSim::Framework::Runtime::saveScene | ( | const std::string & | fileName | ) | const

Write out the whole scene as a file.

Parameters

  fileName | the name of the scene-file if no path is given, uses the current path of the executable

## start()

bool SurgSim::Framework::Runtime::start | ( | bool | paused = `false` | ) |

Start all the threads non returns after the startup as succeeded.

Returns
  true if it succeeds, false if it fails.

## step()

void SurgSim::Framework::Runtime::step | ( |  | ) |

Make all managers execute 1 update loop, afterwards they will wait for another step() call or resume()

## stop()

bool SurgSim::Framework::Runtime::stop | ( |  | ) |

Stops the simulation.

The call will wait for all the threads to finish, except for any threads that have been detached.

Warning
  This function is not thread safe, if stop is called when there are threads that are not waiting, this call will hang indefinitely.

Returns
  true if it succeeds, false if it fails.

## tryConvertElements()

bool SurgSim::Framework::Runtime::tryConvertElements | ( | const std::string & | fileName,
|  | const YAML::Node & | node,
|  | std::vector< std::shared_ptr< SceneElement >> * | elements
| ) |  |

private

Convert nodes to vector of elements.

Parameters

  | fileName | the original filename for error reporting
  | node | the node to be converted
  [out] | elements | the pointer for the results

Returns
  true if the conversion was successful

## Member Data Documentation

## m_applicationData

std::shared_ptr< ApplicationData > SurgSim::Framework::Runtime::m_applicationData

static private

## m_barrier

std::shared_ptr<Barrier> SurgSim::Framework::Runtime::m_barrier

private

## m_isPaused

bool SurgSim::Framework::Runtime::m_isPaused

private

## m_isRunning

bool SurgSim::Framework::Runtime::m_isRunning

private

## m_isStopped

bool SurgSim::Framework::Runtime::m_isStopped

private

## m_managers

std::vector<std::shared_ptr<ComponentManager> > SurgSim::Framework::Runtime::m_managers

private

## m_scene

std::shared_ptr<Scene> SurgSim::Framework::Runtime::m_scene

private

## m_sceneHandling

boost::mutex SurgSim::Framework::Runtime::m_sceneHandling

private

The documentation for this class was generated from the following files:

- SurgSim/Framework/Runtime.h
- SurgSim/Framework/Runtime.cpp