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 
40 std::string 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, std::string executablePath, std::string packageName)
59  : name(prettify(executableName)),
60  executableName(executableName),
61  executablePath(executablePath),
62  packageName(packageName),
63  found(false),
64  properties(new PropertyDefinitionContainer(name))
65 {
66  updateFound();
67 
68  Ice::PropertiesPtr cfgProperties = IceProperties::create();
69  armarx::IceProperties* cfgInternal = static_cast<armarx::IceProperties*>(cfgProperties.get());
70  cfgInternal->setInheritanceSolver(nullptr);
71  properties->setProperties(cfgProperties);
72 }
73 
75  : name(application.name)
76  , executableName(application.executableName)
77  , executablePath(application.executablePath)
78  , packageName(application.packageName)
79  , found(application.found)
80  , properties(new PropertyDefinitionContainer(name))
81 {
82  Ice::PropertiesPtr cfgProperties = IceProperties::create(application.getProperties()->getProperties()->clone());
83  armarx::IceProperties* cfgInternal = static_cast<armarx::IceProperties*>(cfgProperties.get());
84  cfgInternal->setInheritanceSolver(nullptr);
85  properties->setProperties(cfgProperties);
86 }
87 
88 
90 {
91  return this->name;
92 }
93 
95 {
96  return this->executablePath;
97 }
98 
100 {
101  return packageName;
102 }
103 
105 {
106  return this->properties;
107 }
108 
109 void Data_Structure::Application::setProperties(PropertyDefinitionsPtr properties) //oder Ice::StringSeq und create-Methode
110 {
111  armarx::IceProperties* cfgInternal = static_cast<armarx::IceProperties*>(properties->getProperties().get());
112  cfgInternal->setInheritanceSolver(nullptr);
113 
114  this->properties = properties;
115  this->properties->setPrefix("");
116  this->properties->setDescription(name + " properties");
117 }
118 
120 {
121  return std::filesystem::exists(executablePath / executableName);
122 }
123 
125 {
126  ;
127 }
128 
130 {
131  if (defaultMap.count(name) == 0)
132  {
133  return false;
134  }
135  if (enabledMap.count(name) == 0)
136  {
137  return false;
138  }
139  return enabledMap[name];
140 }
141 
143 {
144  if (defaultMap.count(name) == 0)
145  {
146  return;
147  }
148  enabledMap[name] = enabled;
149 }
150 
151 
153 {
154  if (defaultMap.count(name) == 0)
155  {
156  return false;
157  }
158  return defaultMap[name];
159 }
160 
161 void Data_Structure::Application::setIsDefaultProperty(std::string name, bool defaultValue)
162 {
163  defaultMap[name] = defaultValue;
164 }
165 
167 {
169  {
170  return executableName;
171  }
172 
174  {
175  return executablePath / executableName;
176  }
177 
178 } // namespace ScenarioManager::Data_Structure
ScenarioManager::Data_Structure::Application::getProperties
armarx::PropertyDefinitionsPtr getProperties()
Definition: Application.cpp:104
ScenarioManager::Data_Structure::Application::updateFound
void updateFound()
Definition: Application.cpp:124
ScenarioManager::Data_Structure::Application::isDefaultPropertyEnabled
bool isDefaultPropertyEnabled(std::string name)
Definition: Application.cpp:129
prettify
std::string prettify(const std::string &executableName)
Definition: Application.cpp:40
ScenarioManager::Data_Structure::Application::getExecutableAbsPath
std::string getExecutableAbsPath()
Definition: Application.cpp:173
ScenarioManager::Data_Structure::Application::properties
armarx::PropertyDefinitionsPtr properties
Definition: Application.h:56
ScenarioManager::Data_Structure::Application
Class containing data about an application Provides methods to get and set the date contained in the ...
Definition: Application.h:45
IceInternal::Handle< ::Ice::Properties >
ScenarioManager::Data_Structure::Application::setProperties
void setProperties(armarx::PropertyDefinitionsPtr properties)
Sets the properties of this application.
Definition: Application.cpp:109
ScenarioManager::Data_Structure::Application::getFound
bool getFound()
Definition: Application.cpp:119
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
ScenarioManager::Data_Structure
Definition: Application.cpp:166
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:217
ScenarioManager::Data_Structure::Application::getExecutableName
std::string getExecutableName()
Definition: Application.cpp:168
armarx::IceProperties
IceProperties stores ice properties and resolves property inheritance.
Definition: IceProperties.h:120
ScenarioManager
Definition: Application.cpp:166
ScenarioManager::Data_Structure::Application::getPathToExecutable
std::string getPathToExecutable()
Definition: Application.cpp:94
IceUtil::Handle< class PropertyDefinitionContainer >
ScenarioManager::Data_Structure::Application::getName
std::string getName()
Definition: Application.cpp:89
armarx::ends_with
bool ends_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:50
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:99
ScenarioManager::Data_Structure::Application::setDefaultPropertyEnabled
void setDefaultPropertyEnabled(std::string name, bool enabled)
Definition: Application.cpp:142
Application.h
ScenarioManager::Data_Structure::Application::isDefaultProperty
bool isDefaultProperty(std::string name)
Definition: Application.cpp:152
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ScenarioManager::Data_Structure::Application::setIsDefaultProperty
void setIsDefaultProperty(std::string name, bool defaultValue)
Definition: Application.cpp:161