opensurgsim
Public Member Functions | Static Public Member Functions | List of all members
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 <Runtime.h>

Inheritance diagram for SurgSim::Framework::Runtime:

Public Member Functions

 Runtime ()
 Default constructor.
 
 Runtime (const std::string &configFilePath)
 Constructor, initializes the search path with paths from the given file. More...
 
 ~Runtime ()
 Destructor.
 
void addManager (std::shared_ptr< ComponentManager > thread)
 Add a worker thread, this should probably only be possible if the system is not running.
 
std::vector< std::weak_ptr< ComponentManager > > getManagers () const
 
template<class T >
std::shared_ptr< T > getManager () const
 
MessengergetMessenger ()
 
std::shared_ptr< ScenegetScene ()
 
std::shared_ptr< ScenegetScene () 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.
 
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()
 
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 ApplicationDatagetApplicationData ()
 Gets application data for the runtime. More...
 
static std::shared_ptr< ThreadPoolgetThreadPool ()
 Gets the thread pool for the runtime. More...
 

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()

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

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

Parameters
configFilePathFull 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.

Member Function Documentation

§ addComponent()

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

Adds a component.

Parameters
componentThe component.

§ addSceneElement()

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

Adds a scene element.

Parameters
sceneElementThe 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.

Name: element1
IsActive: true
Components:
Name: component1
Id: 792faa40-459b-40cf-981d-560a8f2bd1801
Name: element2
IsActive: true
Components:
Name: component2
Id: 1de26315-82a7-46b2-ae38-324d25009629
Parameters
fileNamethe filename of the scene to be loaded, needs to be found
Exceptions
Ifthe 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
fileNamethe filename of the scene to be loaded, needs to be found
Exceptions
ifloading failed
Returns
a vector of scene elements with the loaded elements

§ 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

§ getThreadPool()

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

Gets the thread pool for the runtime.

Returns
The thread pool.

§ 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
fileNamethe filename of the scene to be loaded, needs to be found
Exceptions
Ifthe 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.

§ removeComponent()

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

Removes the component described by component.

Parameters
componentThe 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
fileNamethe 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.

§ 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.

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