Runtime.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_FRAMEWORK_RUNTIME_H
17 #define SURGSIM_FRAMEWORK_RUNTIME_H
18 
19 #include <vector>
20 #include <memory>
21 #include <string>
22 #include <map>
23 
24 #include <boost/thread/mutex.hpp>
25 
26 namespace SurgSim
27 {
28 namespace Framework
29 {
30 
31 class ApplicationData;
32 class Barrier;
33 class ComponentManager;
34 class Component;
35 class Logger;
36 class Scene;
37 class SceneElement;
38 
43 class Runtime : public std::enable_shared_from_this<Runtime>
44 {
45 public:
46 
48  Runtime();
49 
54  explicit Runtime(const std::string& configFilePath);
55 
57  ~Runtime();
58 
60  void addManager(std::shared_ptr<ComponentManager> thread);
61 
63  std::shared_ptr<Scene> getScene();
64 
66  std::shared_ptr<Scene> getScene() const;
67 
71  bool addSceneElement(std::shared_ptr<SceneElement> sceneElement);
72 
74  bool execute();
75 
78  bool start(bool paused = false);
79 
85  void pause();
86 
90  void resume();
91 
93  void step();
94 
100  bool stop();
101 
104  bool isRunning() const;
105 
108  bool isPaused() const;
109 
112  static std::shared_ptr<const ApplicationData> getApplicationData();
113 
116  void addComponent(const std::shared_ptr<Component>& component);
117 
120  void removeComponent(const std::shared_ptr<Component>& component);
121 
122 private:
123 
127 
131  void addComponents(const std::vector<std::shared_ptr<SurgSim::Framework::Component>>& components);
132 
136  void initSearchPaths(const std::string& configFilePath);
137 
140  std::shared_ptr<Runtime> getSharedPtr();
141 
143  std::vector< std::shared_ptr<ComponentManager> > m_managers;
144  std::shared_ptr<Scene> m_scene;
145  static std::shared_ptr<ApplicationData> m_applicationData;
146 
147  boost::mutex m_mutex;
148 
149  std::shared_ptr<Barrier> m_barrier;
151 };
152 
153 }; // namespace Framework
154 }; // namespace SurgSim
155 
156 #endif // SURGSIM_FRAMEWORK_RUNTIME_H
bool isPaused() const
Query if this object is paused.
Definition: Runtime.cpp:229
void pause()
Pause all managers, this will set all managers to synchronous execution, they will all complete their...
Definition: Runtime.cpp:191
Definition: DriveElementFromInputBehavior.cpp:27
bool isRunning() const
Query if this object is running.
Definition: Runtime.cpp:224
bool start(bool paused=false)
Start all the threads non returns after the startup as succeeded.
Definition: Runtime.cpp:134
bool addSceneElement(std::shared_ptr< SceneElement > sceneElement)
Adds a scene element.
Definition: Runtime.cpp:77
bool stop()
Stops the simulation.
Definition: Runtime.cpp:174
std::shared_ptr< Runtime > getSharedPtr()
Gets a shared pointer to the runtime.
Definition: Runtime.cpp:253
~Runtime()
Destructor.
Definition: Runtime.cpp:50
void initSearchPaths(const std::string &configFilePath)
Initializes the search paths.
Definition: Runtime.cpp:267
void removeComponent(const std::shared_ptr< Component > &component)
Removes the component described by component.
Definition: Runtime.cpp:299
void addManager(std::shared_ptr< ComponentManager > thread)
Add a worker thread, this should probably only be possible if the system is not running.
Definition: Runtime.cpp:56
bool m_isRunning
Definition: Runtime.h:142
void resume()
Resume from pause, causes all managers to resume normal processing.
Definition: Runtime.cpp:200
bool execute()
Start all the threads and block until one of them quits.
Definition: Runtime.cpp:110
void addComponents(const std::vector< std::shared_ptr< SurgSim::Framework::Component >> &components)
Adds the components.
Definition: Runtime.cpp:89
std::vector< std::shared_ptr< ComponentManager > > m_managers
Definition: Runtime.h:143
void preprocessSceneElements()
Preprocess scene elements.
Definition: Runtime.cpp:234
void step()
Make all managers execute 1 update loop, afterwards they will wait for another step() call or resume(...
Definition: Runtime.cpp:216
bool m_isPaused
Definition: Runtime.h:150
Runtime()
Default constructor.
Definition: Runtime.cpp:36
boost::mutex m_mutex
Definition: Runtime.h:147
std::shared_ptr< Scene > getScene()
Definition: Runtime.cpp:67
void addComponent(const std::shared_ptr< Component > &component)
Adds a component.
Definition: Runtime.cpp:288
std::shared_ptr< Barrier > m_barrier
Definition: Runtime.h:149
static std::shared_ptr< const ApplicationData > getApplicationData()
Gets application data for the runtime.
Definition: Runtime.cpp:281
std::shared_ptr< Scene > m_scene
Definition: Runtime.h:144
static std::shared_ptr< ApplicationData > m_applicationData
Definition: Runtime.h:145
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.
Definition: Runtime.h:43