16 #ifndef SURGSIM_FRAMEWORK_COMPONENTMANAGER_H 17 #define SURGSIM_FRAMEWORK_COMPONENTMANAGER_H 23 #include <boost/thread/mutex.hpp> 25 #include "SurgSim/Framework/BasicThread.h" 26 #include "SurgSim/Framework/Behavior.h" 28 #include "SurgSim/Framework/Component.h" 53 explicit ComponentManager(
const std::string& name =
"Unknown Component Manager");
71 void setRuntime(std::shared_ptr<Runtime> val);
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);
105 virtual int getType()
const = 0;
111 std::vector<std::shared_ptr<Component>>* inflightRemovals,
112 std::vector<std::shared_ptr<SceneElement>>* inflightElements);
115 std::shared_ptr<SurgSim::Framework::Logger>
getLogger()
const;
124 std::vector<std::shared_ptr<Component>> m_componentRemovals;
125 std::vector<std::shared_ptr<SceneElement>> m_elementCache;
131 std::vector<std::shared_ptr<SurgSim::Framework::Behavior>>
m_behaviors;
136 void retireComponents(
const std::vector<std::shared_ptr<T>>& container);
143 virtual bool executeAdditions(
const std::shared_ptr<Component>& component) = 0;
149 virtual bool executeRemovals(
const std::shared_ptr<Component>& component) = 0;
153 bool executeInitialization()
override;
158 void removeComponents(
const std::vector<std::shared_ptr<Component>>::const_iterator& beginIt,
159 const std::vector<std::shared_ptr<Component>>::const_iterator& endIt);
166 const std::vector<std::shared_ptr<Component>>::const_iterator& beginIt,
167 const std::vector<std::shared_ptr<Component>>::const_iterator& endIt,
168 std::vector<std::shared_ptr<Component>>* actualAdditions);
176 void wakeUpComponents(
const std::vector<std::shared_ptr<Component>>::const_iterator& beginIt,
177 const std::vector<std::shared_ptr<Component>>::const_iterator& endIt);
179 std::weak_ptr<Runtime> m_runtime;
185 #include "SurgSim/Framework/ComponentManager-inl.h" 187 #endif // SURGSIM_FRAMEWORK_COMPONENTMANAGER_H Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
std::shared_ptr< SurgSim::Framework::Logger > getLogger() const
Returns this manager's logger.
Definition: ComponentManager.cpp:226
std::vector< std::shared_ptr< SurgSim::Framework::Behavior > > m_behaviors
Collection of behaviors.
Definition: ComponentManager.h:131
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:54
boost::mutex m_componentMutex
Blocks protects addition and removal queues.
Definition: ComponentManager.h:118
Base Component Manager class.
Definition: ComponentManager.h:49
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:87
std::shared_ptr< Runtime > getRuntime() const
Definition: ComponentManager.cpp:58
bool enqueueAddComponent(const std::shared_ptr< Component > &component)
Queues a component to be added later.
Definition: ComponentManager.cpp:43
void doBeforeStop() override
Prepares the thread for its execution to be stopped.
Definition: ComponentManager.cpp:217
void processComponents()
Processes all the components that are scheduled for addition or removal, this needs to be called insi...
Definition: ComponentManager.cpp:63
bool enqueueRemoveComponent(const std::shared_ptr< Component > &component)
Queues a component to be removed.
Definition: ComponentManager.cpp:50
Basic thread implementation, tries to maintain a constant rate, supplies startup an initialization...
Definition: BasicThread.h:48
std::vector< std::shared_ptr< Component > > m_componentAdditions
Definition: ComponentManager.h:123
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
void copyScheduledComponents(std::vector< std::shared_ptr< Component >> *inflightAdditions, std::vector< std::shared_ptr< Component >> *inflightRemovals, std::vector< std::shared_ptr< SceneElement >> *inflightElements)
Helper, blocks access to the additions and removal queue and copies the components from there to the ...
Definition: ComponentManager.cpp:147
virtual int getType() const =0
Returns the type of Manager.