Runtime.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013-2015, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_FRAMEWORK_RUNTIME_H
#define SURGSIM_FRAMEWORK_RUNTIME_H
#include <boost/thread/mutex.hpp>
#include <map>
#include <memory>
#include <string>
#include <vector>
namespace YAML
{
class Node;
}
namespace SurgSim
{
namespace Framework
{
class ApplicationData;
class Barrier;
class ComponentManager;
class Component;
class Logger;
class Scene;
class SceneElement;
class ThreadPool;
class Runtime : public std::enable_shared_from_this<Runtime>
{
public:
Runtime();
explicit Runtime(const std::string& configFilePath);
~Runtime();
void addManager(std::shared_ptr<ComponentManager> thread);
std::vector<std::weak_ptr<ComponentManager>> getManagers() const;
template <class T>
std::shared_ptr<T> getManager() const;
std::shared_ptr<Scene> getScene();
std::shared_ptr<Scene> getScene() const;
bool addSceneElement(std::shared_ptr<SceneElement> sceneElement);
bool execute();
bool start(bool paused = false);
void pause();
void resume();
void step();
bool stop();
bool isRunning() const;
bool isPaused() const;
static std::shared_ptr<const ApplicationData> getApplicationData();
static std::shared_ptr<ThreadPool> getThreadPool();
void addComponent(const std::shared_ptr<Component>& component);
void removeComponent(const std::shared_ptr<Component>& component);
void loadScene(const std::string& fileName);
void addSceneElements(const std::string& fileName);
std::vector<std::shared_ptr<SceneElement>> duplicateSceneElements(const std::string& fileName);
void saveScene(const std::string& fileName) const;
private:
void preprocessSceneElements();
void addComponents(const std::vector<std::shared_ptr<SurgSim::Framework::Component>>& components);
void initSearchPaths(const std::string& configFilePath);
bool tryConvertElements(const std::string& fileName, const YAML::Node& node,
std::vector<std::shared_ptr<SceneElement>>* elements);
std::shared_ptr<Runtime> getSharedPtr();
bool m_isRunning;
std::vector<std::shared_ptr<ComponentManager>> m_managers;
std::shared_ptr<Scene> m_scene;
static std::shared_ptr<ApplicationData> m_applicationData;
boost::mutex m_sceneHandling;
std::shared_ptr<Barrier> m_barrier;
bool m_isPaused;
bool m_isStopped;
};
template <class T>
std::shared_ptr<T>
SurgSim::Framework::Runtime::getManager() const
{
std::shared_ptr<T> result;
for (auto& manager : m_managers)
{
result = std::dynamic_pointer_cast<T>(manager);
if (result != nullptr)
{
return result;
}
}
return result;
}
bool tryLoadNode(const std::string& fileName, YAML::Node* node);
}; // namespace Framework
}; // namespace SurgSim
#endif // SURGSIM_FRAMEWORK_RUNTIME_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Framework::Runtime::m_managers
std::vector< std::shared_ptr< ComponentManager > > m_managers
Definition: Runtime.h:207
SurgSim::Framework::tryLoadNode
bool tryLoadNode(const std::string &fileName, YAML::Node *node)
Perform a YAML load operation.
Definition: Runtime.cpp:424
SurgSim::Framework::Runtime::m_isStopped
bool m_isStopped
Definition: Runtime.h:216
SurgSim::Framework::Runtime::m_isRunning
bool m_isRunning
Definition: Runtime.h:206
SurgSim::Framework::Runtime::getManager
std::shared_ptr< T > getManager() const
Definition: Runtime.h:221
SurgSim::Framework::Runtime::m_sceneHandling
boost::mutex m_sceneHandling
Definition: Runtime.h:211
SurgSim::Framework::Runtime::m_isPaused
bool m_isPaused
Definition: Runtime.h:214
YAML
Definition: DataStructuresConvert.h:28
SurgSim::Framework::Runtime::m_barrier
std::shared_ptr< Barrier > m_barrier
Definition: Runtime.h:213
SurgSim::Framework::Runtime::m_scene
std::shared_ptr< Scene > m_scene
Definition: Runtime.h:208
SurgSim::Framework::Runtime::m_applicationData
static std::shared_ptr< ApplicationData > m_applicationData
Definition: Runtime.h:209
SurgSim::Framework::Runtime
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:49