16 #ifndef SURGSIM_FRAMEWORK_COMPONENTMANAGER_H
17 #define SURGSIM_FRAMEWORK_COMPONENTMANAGER_H
23 #include <boost/thread/mutex.hpp>
53 explicit ComponentManager(
const std::string& name =
"Unknown Component Manager");
82 std::shared_ptr<T>
tryAddComponent(std::shared_ptr<SurgSim::Framework::Component> component,
83 std::vector<std::shared_ptr<T>>* container);
92 std::vector<std::shared_ptr<T>>* container);
104 virtual int getType()
const = 0;
110 std::vector<std::shared_ptr<Component>>* inflightRemovals);
113 std::shared_ptr<SurgSim::Framework::Logger>
getLogger()
const;
126 std::shared_ptr<SurgSim::Framework::Logger>
m_logger;
131 std::vector<std::shared_ptr<SurgSim::Framework::Behavior>>
m_behaviors;
138 virtual bool executeAdditions(
const std::shared_ptr<Component>& component) = 0;
144 virtual bool executeRemovals(
const std::shared_ptr<Component>& component) = 0;
153 void removeComponents(
const std::vector<std::shared_ptr<Component>>::const_iterator& beginIt,
154 const std::vector<std::shared_ptr<Component>>::const_iterator& endIt);
161 const std::vector<std::shared_ptr<Component>>::const_iterator& beginIt,
162 const std::vector<std::shared_ptr<Component>>::const_iterator& endIt,
163 std::vector<std::shared_ptr<Component>>* actualAdditions);
171 void wakeUpComponents(
const std::vector<std::shared_ptr<Component>>::const_iterator& beginIt,
172 const std::vector<std::shared_ptr<Component>>::const_iterator& endIt);
182 #endif // SURGSIM_FRAMEWORK_COMPONENTMANAGER_H
Definition: DriveElementFromInputBehavior.cpp:27
std::vector< std::shared_ptr< SurgSim::Framework::Behavior > > m_behaviors
Collection of behaviors.
Definition: ComponentManager.h:131
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 cal...
Definition: ComponentManager.cpp:191
bool tryRemoveComponent(std::shared_ptr< SurgSim::Framework::Component > component, std::vector< std::shared_ptr< T >> *container)
Template version of the removeComponent method.
Definition: ComponentManager-inl.h:55
boost::mutex m_componentMutex
Blocks protects addition and removal queues.
Definition: ComponentManager.h:116
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 ...
Definition: ComponentManager.cpp:143
virtual bool executeRemovals(const std::shared_ptr< Component > &component)=0
Handle representations, override for each thread.
Base Component Manager class.
Definition: ComponentManager.h:49
std::vector< std::shared_ptr< Component > > m_componentRemovals
Definition: ComponentManager.h:122
virtual bool executeInitialization() override
Overridden from BasicThread, extends the initialization to contain component initialization including...
Definition: ComponentManager.cpp:97
The convenience header that provides the entirety of the logging API.
void processBehaviors(const double dt)
Processes behaviors This needs to be called inside doUpdate() function in each 'sub' manager...
Definition: ComponentManager.cpp:84
bool enqueueAddComponent(const std::shared_ptr< Component > &component)
Queues a component to be added later.
Definition: ComponentManager.cpp:42
std::shared_ptr< SurgSim::Framework::Logger > getLogger() const
Returns this manager's logger.
Definition: ComponentManager.cpp:209
void processComponents()
Processes all the components that are scheduled for addition or removal, this needs to be called insi...
Definition: ComponentManager.cpp:61
ComponentManager(const std::string &name="Unknown Component Manager")
Definition: ComponentManager.cpp:28
bool enqueueRemoveComponent(const std::shared_ptr< Component > &component)
Queues a component to be removed.
Definition: ComponentManager.cpp:49
void setRuntime(std::shared_ptr< Runtime > val)
Definition: ComponentManager.cpp:37
std::weak_ptr< Runtime > m_runtime
Definition: ComponentManager.h:174
virtual ~ComponentManager()
Definition: ComponentManager.cpp:33
std::shared_ptr< SurgSim::Framework::Logger > m_logger
Logger for this class.
Definition: ComponentManager.h:126
Basic thread implementation, tries to maintain a constant rate, supplies startup an initialization...
Definition: BasicThread.h:47
virtual bool executeAdditions(const std::shared_ptr< Component > &component)=0
Adds a component.
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.
Definition: ComponentManager.cpp:158
std::shared_ptr< Runtime > getRuntime() const
Definition: ComponentManager.cpp:56
std::vector< std::shared_ptr< Component > > m_componentAdditions
Definition: ComponentManager.h:121
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.
Definition: ComponentManager-inl.h:30
virtual int getType() const =0
Returns the type of Manager.
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.
Definition: ComponentManager.cpp:168