All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
SurgSim::Framework::ComponentManager Class Referenceabstract

Base Component Manager class. More...

#include <SurgSim/Framework/ComponentManager.h>

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

Public Member Functions

 ComponentManager (const std::string &name="Unknown Component Manager")
 
virtual ~ComponentManager ()
 
bool enqueueAddComponent (const std::shared_ptr< Component > &component)
 Queues a component to be added later. More...
 
bool enqueueRemoveComponent (const std::shared_ptr< Component > &component)
 Queues a component to be removed. More...
 
std::shared_ptr< RuntimegetRuntime () const
 
void setRuntime (std::shared_ptr< Runtime > val)
 
- Public Member Functions inherited from SurgSim::Framework::BasicThread
 BasicThread (const std::string &name="Unknown Thread")
 
virtual ~BasicThread () noexcept(false)
 C++11 introduced noexcept. More...
 
void start (std::shared_ptr< Barrier > startupBarrier=nullptr, bool isSynchronous=false)
 C++11 introduced noexcept. More...
 
void stop ()
 Stopping the execution, blocks until the running thread has actually stopped,. More...
 
void setIdle (bool isIdle)
 Set/Unset the thread in an idle state (doUpdate() called or not in the update() method) More...
 
bool isIdle ()
 Query if this thread is in idle state or not. More...
 
bool isInitialized ()
 Query if this object is initialized. More...
 
bool isRunning () const
 Query if this object is running. More...
 
void operator() ()
 This is what boost::thread executes on thread creation. More...
 
boost::thread & getThread ()
 
std::string getName () const
 
void setRate (double val)
 Set the update rate of the thread. More...
 
bool setSynchronous (bool val)
 Sets the thread to synchronized execution in concert with the startup barrier, the startup barrier has to exist for this call to succeed. More...
 
bool isSynchronous ()
 Query if this object is synchronized. More...
 

Protected Member Functions

template<class T >
std::shared_ptr< T > tryAddComponent (std::shared_ptr< SurgSim::Framework::Component > component, std::vector< std::shared_ptr< T >> *container)
 Template version of the addComponent method. More...
 
template<class T >
bool tryRemoveComponent (std::shared_ptr< SurgSim::Framework::Component > component, std::vector< std::shared_ptr< T >> *container)
 Template version of the removeComponent method. More...
 
void processComponents ()
 Processes all the components that are scheduled for addition or removal, this needs to be called inside the doUpdate() function. More...
 
void processBehaviors (const double dt)
 Processes behaviors This needs to be called inside doUpdate() function in each 'sub' manager. More...
 
virtual int getType () const =0
 Returns the type of Manager. More...
 
void copyScheduledComponents (std::vector< std::shared_ptr< Component >> *inflightAdditions, std::vector< std::shared_ptr< Component >> *inflightRemovals)
 Helper, blocks access to the additions and removal queue and copies the components from there to the intermediate inflight queues, after this call, the incoming queues will be empty. More...
 
std::shared_ptr
< SurgSim::Framework::Logger
getLogger () const
 Returns this manager's logger. More...
 
- Protected Member Functions inherited from SurgSim::Framework::BasicThread
bool initialize ()
 Trigger the initialization of this object, this will be called before all other threads doStartup() are called. More...
 
bool startUp ()
 Trigger the startup of this object, this will be called after all other threads doInit() was called the thread will only enter the run loop triggering upated() if all threads doInit() and doStartup() returned true. More...
 
bool waitForBarrier (bool success)
 

Protected Attributes

boost::mutex m_componentMutex
 Blocks protects addition and removal queues. More...
 
std::shared_ptr
< SurgSim::Framework::Logger
m_logger
 Logger for this class. More...
 
std::vector< std::shared_ptr
< SurgSim::Framework::Behavior > > 
m_behaviors
 Collection of behaviors. More...
 
std::vector< std::shared_ptr
< Component > > 
m_componentAdditions
 
std::vector< std::shared_ptr
< Component > > 
m_componentRemovals
 

Private Member Functions

virtual bool executeAdditions (const std::shared_ptr< Component > &component)=0
 Adds a component. More...
 
virtual bool executeRemovals (const std::shared_ptr< Component > &component)=0
 Handle representations, override for each thread. More...
 
virtual bool executeInitialization () override
 Overridden from BasicThread, extends the initialization to contain component initialization including waiting for the other threads to conclude their component initialization and wakeup. More...
 
void removeComponents (const std::vector< std::shared_ptr< Component >>::const_iterator &beginIt, const std::vector< std::shared_ptr< Component >>::const_iterator &endIt)
 Delegates to doRemoveComponent to remove all the components in the indicated array. More...
 
void addComponents (const std::vector< std::shared_ptr< Component >>::const_iterator &beginIt, const std::vector< std::shared_ptr< Component >>::const_iterator &endIt, std::vector< std::shared_ptr< Component >> *actualAdditions)
 Delegates to doAddComponent and calls initialize on all the components. More...
 
void wakeUpComponents (const std::vector< std::shared_ptr< Component >>::const_iterator &beginIt, const std::vector< std::shared_ptr< Component >>::const_iterator &endIt)
 Wake all the components up, only the components that were successfully initialized get the wakeup call, check for isAwake because there to catch multiple versions of the same component from being awoken more than once. More...
 

Private Attributes

std::weak_ptr< Runtimem_runtime
 

Detailed Description

Base Component Manager class.

Component Managers manage a collection of components. The runtime will present each new component to the manager, and it is up to the manger to decide whether to handle a component of a given type or not. Adding and removing components is thread-safe, when the [add|remove]Component call is made, the component is added to an intermediary data structure, each ComponentManager implementation must call processComponents() to trigger the actual addition and removal. Each ComponentManager subclass needs to implement doAddComponent() and doRemoveComponent() to the actual addition and removal of components. ComponentManager implements a custom executeInitialization() method that lets the runtime schedule initialization of components that exist at the start of the simulation

Constructor & Destructor Documentation

SurgSim::Framework::ComponentManager::ComponentManager ( const std::string &  name = "Unknown Component Manager")
explicit
SurgSim::Framework::ComponentManager::~ComponentManager ( )
virtual

Member Function Documentation

void SurgSim::Framework::ComponentManager::addComponents ( const std::vector< std::shared_ptr< Component >>::const_iterator &  beginIt,
const std::vector< std::shared_ptr< Component >>::const_iterator &  endIt,
std::vector< std::shared_ptr< Component >> *  actualAdditions 
)
private

Delegates to doAddComponent and calls initialize on all the components.

Parameters
beginItThe begin iterator.
endItThe end iterator.
[out]actualAdditionsList of components actually added
void SurgSim::Framework::ComponentManager::copyScheduledComponents ( std::vector< std::shared_ptr< Component >> *  inflightAdditions,
std::vector< std::shared_ptr< Component >> *  inflightRemovals 
)
protected

Helper, blocks access to the additions and removal queue and copies the components from there to the intermediate inflight queues, after this call, the incoming queues will be empty.

bool SurgSim::Framework::ComponentManager::enqueueAddComponent ( const std::shared_ptr< Component > &  component)

Queues a component to be added later.

Parameters
componentThe component to be added.
Returns
true if the component was scheduled for addition, this does not indicate that the component will actually be added to this manager
bool SurgSim::Framework::ComponentManager::enqueueRemoveComponent ( const std::shared_ptr< Component > &  component)

Queues a component to be removed.

Parameters
componentThe component to be removed.
Returns
true if the component was scheduled for removal, this does not indicate that the component will actually be removed from this manager
virtual bool SurgSim::Framework::ComponentManager::executeAdditions ( const std::shared_ptr< Component > &  component)
privatepure virtual

Adds a component.

Parameters
componentThe component to be added.
Returns
true if the component was scheduled for addition, this does not indicate that the component will actually be added to this manager.

Implemented in SurgSim::Physics::PhysicsManager, SurgSim::Graphics::Manager, SurgSim::Input::InputManager, SurgSim::Framework::BehaviorManager, and SurgSim::Testing::MockPhysicsManager.

bool SurgSim::Framework::ComponentManager::executeInitialization ( )
overrideprivatevirtual

Overridden from BasicThread, extends the initialization to contain component initialization including waiting for the other threads to conclude their component initialization and wakeup.

Reimplemented from SurgSim::Framework::BasicThread.

virtual bool SurgSim::Framework::ComponentManager::executeRemovals ( const std::shared_ptr< Component > &  component)
privatepure virtual

Handle representations, override for each thread.

Parameters
componentThe component to be removed.
Returns
true if the component was scheduled for removal, this does not indicate that the component will actually be removed from this manager.

Implemented in SurgSim::Physics::PhysicsManager, SurgSim::Graphics::Manager, SurgSim::Input::InputManager, SurgSim::Framework::BehaviorManager, and SurgSim::Testing::MockPhysicsManager.

std::shared_ptr< SurgSim::Framework::Logger > SurgSim::Framework::ComponentManager::getLogger ( ) const
protected

Returns this manager's logger.

std::shared_ptr< Runtime > SurgSim::Framework::ComponentManager::getRuntime ( ) const

Runtime accessors

virtual int SurgSim::Framework::ComponentManager::getType ( ) const
protectedpure virtual
void SurgSim::Framework::ComponentManager::processBehaviors ( const double  dt)
protected

Processes behaviors This needs to be called inside doUpdate() function in each 'sub' manager.

void SurgSim::Framework::ComponentManager::processComponents ( )
protected

Processes all the components that are scheduled for addition or removal, this needs to be called inside the doUpdate() function.

void SurgSim::Framework::ComponentManager::removeComponents ( const std::vector< std::shared_ptr< Component >>::const_iterator &  beginIt,
const std::vector< std::shared_ptr< Component >>::const_iterator &  endIt 
)
private

Delegates to doRemoveComponent to remove all the components in the indicated array.

Parameters
beginItThe begin iterator.
endItThe end iterator.
void SurgSim::Framework::ComponentManager::setRuntime ( std::shared_ptr< Runtime val)

Runtime accessors

template<class T >
std::shared_ptr< T > SurgSim::Framework::ComponentManager::tryAddComponent ( std::shared_ptr< SurgSim::Framework::Component component,
std::vector< std::shared_ptr< T >> *  container 
)
protected

Template version of the addComponent method.

Executes the add component operation.

Template Parameters
TSpecific type of the component that is being added.
Parameters
componentThe component that needs to be added.
[in,out]containerIf non-null, the container that should receive the component if of the correct type.
Returns
the correctly cast component pointer if successful and the component did not already exist in the container
Template Parameters
TType of the component to be added.
Parameters
componentThe component that is being added.
[in,out]containerThe container that the component is being added to.
Returns
The correctly cast component if it is of type T and does not exist in the container yet, nullptr otherwise.
template<class T >
bool SurgSim::Framework::ComponentManager::tryRemoveComponent ( std::shared_ptr< SurgSim::Framework::Component component,
std::vector< std::shared_ptr< T >> *  container 
)
protected

Template version of the removeComponent method.

Template Parameters
TSpecific type of the component that is being removed.
Parameters
componentThe component that needs to be removed.
[in,out]containerIf non-null, the container, from which the component should be removed.
Returns
true if the component exists in the container or the component did not cast to T, otherwise.
void SurgSim::Framework::ComponentManager::wakeUpComponents ( const std::vector< std::shared_ptr< Component >>::const_iterator &  beginIt,
const std::vector< std::shared_ptr< Component >>::const_iterator &  endIt 
)
private

Wake all the components up, only the components that were successfully initialized get the wakeup call, check for isAwake because there to catch multiple versions of the same component from being awoken more than once.

Will also remove components if they did not wake up as expected

Parameters
beginItThe begin iterator.
endItThe end iterator.

Member Data Documentation

std::vector<std::shared_ptr<SurgSim::Framework::Behavior> > SurgSim::Framework::ComponentManager::m_behaviors
protected

Collection of behaviors.

std::vector<std::shared_ptr<Component> > SurgSim::Framework::ComponentManager::m_componentAdditions
protected

Data structures Contain components scheduled to be added/removed

boost::mutex SurgSim::Framework::ComponentManager::m_componentMutex
protected

Blocks protects addition and removal queues.

std::vector<std::shared_ptr<Component> > SurgSim::Framework::ComponentManager::m_componentRemovals
protected

Data structures Contain components scheduled to be added/removed

std::shared_ptr<SurgSim::Framework::Logger> SurgSim::Framework::ComponentManager::m_logger
protected

Logger for this class.

std::weak_ptr<Runtime> SurgSim::Framework::ComponentManager::m_runtime
private

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