Application.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::core
19 * @author Dennis Weigelt
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25
26#include "Application.h"
27
28#include <filesystem>
29
30#include <Ice/Properties.h>
31
32#include <SimoxUtility/algorithm/string/string_tools.h>
33
35
36using namespace ScenarioManager;
37using namespace armarx;
38
39std::string
40prettify(const std::string& executableName)
41{
42 //reduce Run from the name
43 using simox::alg::ends_with;
44
45 if (ends_with(executableName, "Run"))
46 {
47 return simox::alg::replace_last(executableName, "Run", "");
48 }
49
50 if (ends_with(executableName, "_run"))
51 {
52 return simox::alg::replace_last(executableName, "_run", "");
53 }
54
55 return executableName;
56}
57
59 std::string executablePath,
60 std::string packageName) :
61 name(prettify(executableName)),
62 executableName(executableName),
63 executablePath(executablePath),
64 packageName(packageName),
65 found(false),
67{
69
71 armarx::IceProperties* cfgInternal = static_cast<armarx::IceProperties*>(cfgProperties.get());
72 cfgInternal->setInheritanceSolver(nullptr);
73 properties->setProperties(cfgProperties);
74}
75
77 name(application.name),
78 executableName(application.executableName),
79 executablePath(application.executablePath),
80 packageName(application.packageName),
81 found(application.found.load()),
83{
84 Ice::PropertiesPtr cfgProperties =
85 IceProperties::create(application.getProperties()->getProperties()->clone());
86 armarx::IceProperties* cfgInternal = static_cast<armarx::IceProperties*>(cfgProperties.get());
87 cfgInternal->setInheritanceSolver(nullptr);
88 properties->setProperties(cfgProperties);
89}
90
91std::string
93{
94 return this->name;
95}
96
97std::string
99{
100 return this->executablePath;
101}
102
103std::string
105{
106 return packageName;
107}
108
111{
112 // Hand out a shared_ptr copy so the caller keeps a consistent snapshot even if a concurrent
113 // load() swaps in a freshly parsed container while the caller is still reading this one.
114 std::lock_guard<std::mutex> guard(propertiesMutex);
115 return this->properties;
116}
117
118void
120 PropertyDefinitionsPtr properties) //oder Ice::StringSeq und create-Methode
121{
122 armarx::IceProperties* cfgInternal =
123 static_cast<armarx::IceProperties*>(properties->getProperties().get());
124 cfgInternal->setInheritanceSolver(nullptr);
125
126 properties->setPrefix("");
127 properties->setDescription(name + " properties");
128
129 std::lock_guard<std::mutex> guard(propertiesMutex);
130 this->properties = properties;
131}
132
133bool
135{
136 return found;
137}
138
139void
141{
142 std::error_code ec;
143 found = std::filesystem::exists(executablePath / executableName, ec);
144}
145
146bool
148{
149 std::lock_guard<std::mutex> guard(propertiesMutex);
150 if (defaultMap.count(name) == 0)
151 {
152 return false;
153 }
154 if (enabledMap.count(name) == 0)
155 {
156 return false;
157 }
158 return enabledMap[name];
159}
160
161void
163{
164 std::lock_guard<std::mutex> guard(propertiesMutex);
165 if (defaultMap.count(name) == 0)
166 {
167 return;
168 }
169 enabledMap[name] = enabled;
170}
171
172bool
174{
175 std::lock_guard<std::mutex> guard(propertiesMutex);
176 if (defaultMap.count(name) == 0)
177 {
178 return false;
179 }
180 return defaultMap[name];
181}
182
183void
184Data_Structure::Application::setIsDefaultProperty(std::string name, bool defaultValue)
185{
186 std::lock_guard<std::mutex> guard(propertiesMutex);
187 defaultMap[name] = defaultValue;
188}
189
191{
192 std::string
194 {
195 return executableName;
196 }
197
198 std::string
200 {
201 return executablePath / executableName;
202 }
203
204} // namespace ScenarioManager::Data_Structure
Class containing data about an application Provides methods to get and set the date contained in the ...
Definition Application.h:49
void setProperties(armarx::PropertyDefinitionsPtr properties)
Sets the properties of this application.
std::mutex propertiesMutex
Guards properties, enabledMap and defaultMap.
Definition Application.h:70
void setDefaultPropertyEnabled(std::string name, bool enabled)
armarx::PropertyDefinitionsPtr properties
Definition Application.h:71
Application(std::string name, std::string executablePath, std::string packageName)
Constructor that sets the name and the path to the executable of the application.
void updateFound()
Checks whether the executable exists and caches the result for getFound().
void setIsDefaultProperty(std::string name, bool defaultValue)
armarx::PropertyDefinitionsPtr getProperties()
IceProperties stores ice properties and resolves property inheritance.
virtual void setInheritanceSolver(const InheritanceSolverPtr &inheritanceSolver)
Sets an inheritance solver in case of testing or using a non-default solver.
static Ice::PropertiesPtr create(const Ice::PropertiesPtr &iceProperties=nullptr)
::IceInternal::Handle<::Ice::Properties > PropertiesPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
bool ends_with(const std::string &haystack, const std::string &needle)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::string prettify(const std::string &executableName)