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 
34 #include "../../../core/logging/Logging.h"
35 
36 using namespace ScenarioManager;
37 using namespace armarx;
38 
39 std::string
40 prettify(const std::string& executableName)
41 {
42  //reduce Run from the name
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 
58 Data_Structure::Application::Application(std::string executableName,
59  std::string executablePath,
60  std::string packageName) :
61  name(prettify(executableName)),
62  executableName(executableName),
63  executablePath(executablePath),
64  packageName(packageName),
65  found(false),
66  properties(new PropertyDefinitionContainer(name))
67 {
68  updateFound();
69 
70  Ice::PropertiesPtr cfgProperties = IceProperties::create();
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),
82  properties(new PropertyDefinitionContainer(name))
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 
91 std::string
93 {
94  return this->name;
95 }
96 
97 std::string
99 {
100  return this->executablePath;
101 }
102 
103 std::string
105 {
106  return packageName;
107 }
108 
111 {
112  return this->properties;
113 }
114 
115 void
117  PropertyDefinitionsPtr properties) //oder Ice::StringSeq und create-Methode
118 {
119  armarx::IceProperties* cfgInternal =
120  static_cast<armarx::IceProperties*>(properties->getProperties().get());
121  cfgInternal->setInheritanceSolver(nullptr);
122 
123  this->properties = properties;
124  this->properties->setPrefix("");
125  this->properties->setDescription(name + " properties");
126 }
127 
128 bool
130 {
131  return std::filesystem::exists(executablePath / executableName);
132 }
133 
134 void
136 {
137  ;
138 }
139 
140 bool
142 {
143  if (defaultMap.count(name) == 0)
144  {
145  return false;
146  }
147  if (enabledMap.count(name) == 0)
148  {
149  return false;
150  }
151  return enabledMap[name];
152 }
153 
154 void
156 {
157  if (defaultMap.count(name) == 0)
158  {
159  return;
160  }
161  enabledMap[name] = enabled;
162 }
163 
164 bool
166 {
167  if (defaultMap.count(name) == 0)
168  {
169  return false;
170  }
171  return defaultMap[name];
172 }
173 
174 void
175 Data_Structure::Application::setIsDefaultProperty(std::string name, bool defaultValue)
176 {
177  defaultMap[name] = defaultValue;
178 }
179 
181 {
182  std::string
184  {
185  return executableName;
186  }
187 
188  std::string
190  {
191  return executablePath / executableName;
192  }
193 
194 } // namespace ScenarioManager::Data_Structure
ScenarioManager::Data_Structure::Application::getProperties
armarx::PropertyDefinitionsPtr getProperties()
Definition: Application.cpp:110
ScenarioManager::Data_Structure::Application::updateFound
void updateFound()
Definition: Application.cpp:135
ScenarioManager::Data_Structure::Application::isDefaultPropertyEnabled
bool isDefaultPropertyEnabled(std::string name)
Definition: Application.cpp:141
prettify
std::string prettify(const std::string &executableName)
Definition: Application.cpp:40
ScenarioManager::Data_Structure::Application::getExecutableAbsPath
std::string getExecutableAbsPath()
Definition: Application.cpp:189
ScenarioManager::Data_Structure::Application::properties
armarx::PropertyDefinitionsPtr properties
Definition: Application.h:57
ScenarioManager::Data_Structure::Application
Class containing data about an application Provides methods to get and set the date contained in the ...
Definition: Application.h:46
IceInternal::Handle<::Ice::Properties >
ScenarioManager::Data_Structure::Application::setProperties
void setProperties(armarx::PropertyDefinitionsPtr properties)
Sets the properties of this application.
Definition: Application.cpp:116
ScenarioManager::Data_Structure::Application::getFound
bool getFound()
Definition: Application.cpp:129
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
ScenarioManager::Data_Structure
Definition: Application.cpp:180
armarx::PropertyDefinitionContainer
PropertyDefinitionContainer.
Definition: PropertyDefinitionContainer.h:53
armarx::IceProperties::setInheritanceSolver
virtual void setInheritanceSolver(const InheritanceSolverPtr &inheritanceSolver)
Sets an inheritance solver in case of testing or using a non-default solver.
Definition: IceProperties.cpp:233
ScenarioManager::Data_Structure::Application::getExecutableName
std::string getExecutableName()
Definition: Application.cpp:183
armarx::IceProperties
IceProperties stores ice properties and resolves property inheritance.
Definition: IceProperties.h:120
ScenarioManager
Definition: Application.cpp:180
ScenarioManager::Data_Structure::Application::getPathToExecutable
std::string getPathToExecutable()
Definition: Application.cpp:98
IceUtil::Handle< class PropertyDefinitionContainer >
ScenarioManager::Data_Structure::Application::getName
std::string getName()
Definition: Application.cpp:92
armarx::ends_with
bool ends_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:53
ScenarioManager::Data_Structure::Application::Application
Application(std::string name, std::string executablePath, std::string packageName)
Constructor that sets the name and the path to the executable of the application.
Definition: Application.cpp:58
ScenarioManager::Data_Structure::Application::getPackageName
std::string getPackageName()
Definition: Application.cpp:104
ScenarioManager::Data_Structure::Application::setDefaultPropertyEnabled
void setDefaultPropertyEnabled(std::string name, bool enabled)
Definition: Application.cpp:155
Application.h
ScenarioManager::Data_Structure::Application::isDefaultProperty
bool isDefaultProperty(std::string name)
Definition: Application.cpp:165
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
ScenarioManager::Data_Structure::Application::setIsDefaultProperty
void setIsDefaultProperty(std::string name, bool defaultValue)
Definition: Application.cpp:175