All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | 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 <SurgSim/Framework/Runtime.h>

Inheritance diagram for SurgSim::Framework::Runtime:
Inheritance graph
[legend]
Collaboration diagram for SurgSim::Framework::Runtime:
Collaboration graph
[legend]

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

Static Public Member Functions

static std::shared_ptr< const
ApplicationData
getApplicationData ()
 Gets application data 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...
 
std::shared_ptr< RuntimegetSharedPtr ()
 Gets a shared pointer to the runtime. More...
 

Private Attributes

bool m_isRunning
 
std::vector< std::shared_ptr
< ComponentManager > > 
m_managers
 
std::shared_ptr< Scenem_scene
 
boost::mutex m_mutex
 
std::shared_ptr< Barrierm_barrier
 
bool m_isPaused
 

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

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

Default constructor.

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.
SurgSim::Framework::Runtime::~Runtime ( )

Destructor.

Member Function Documentation

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

Adds a component.

Parameters
componentThe component.
void SurgSim::Framework::Runtime::addComponents ( const std::vector< std::shared_ptr< SurgSim::Framework::Component >> &  components)
private

Adds the components.

Parameters
componentsThe components.
Returns
true if it succeeds, false if it fails.
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.

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.
bool SurgSim::Framework::Runtime::execute ( )

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

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

Gets application data for the runtime.

Returns
The application data.
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.
std::shared_ptr<Scene> SurgSim::Framework::Runtime::getScene ( ) const
Returns
The current scene
std::shared_ptr< Runtime > SurgSim::Framework::Runtime::getSharedPtr ( )
private

Gets a shared pointer to the runtime.

Returns
The shared pointer.
void SurgSim::Framework::Runtime::initSearchPaths ( const std::string &  configFilePath)
private

Initializes the search paths.

Parameters
configFilePathFull pathname of the configuration file, if path is empty "." will be used as default path.
bool SurgSim::Framework::Runtime::isPaused ( ) const

Query if this object is paused.

Returns
true if paused, false if not.
bool SurgSim::Framework::Runtime::isRunning ( ) const

Query if this object is running.

Returns
true if running, false if not.
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.
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

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

Removes the component described by component.

Parameters
componentThe component.
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.
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.
void SurgSim::Framework::Runtime::step ( )

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

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.

Member Data Documentation

std::shared_ptr< ApplicationData > SurgSim::Framework::Runtime::m_applicationData
staticprivate
std::shared_ptr<Barrier> SurgSim::Framework::Runtime::m_barrier
private
bool SurgSim::Framework::Runtime::m_isPaused
private
bool SurgSim::Framework::Runtime::m_isRunning
private
std::vector< std::shared_ptr<ComponentManager> > SurgSim::Framework::Runtime::m_managers
private
boost::mutex SurgSim::Framework::Runtime::m_mutex
private
std::shared_ptr<Scene> SurgSim::Framework::Runtime::m_scene
private

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