ApplicationInstance.h
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#pragma once
27
28#include "Application.h"
29
31{
33 using ApplicationInstancePtr = std::shared_ptr<ApplicationInstance>;
34 using ApplicationInstanceWPtr = std::weak_ptr<ApplicationInstance>;
35 using ApplicationInstanceVectorPtr = std::shared_ptr<std::vector<ApplicationInstancePtr>>;
36} // namespace ScenarioManager::Data_Structure
37
38#include <memory>
39#include <string>
40
41#include "Scenario.h"
42
44{
46 {
47 static const std::string Stopped;
48 static const std::string Running;
49 static const std::string Waiting;
50 static const std::string Mixed;
51 static const std::string Unknown;
52 static const std::string Inactive;
53 static const std::string Missing;
54 };
55
56 /**
57 * @class ApplicationInstance
58 * @ingroup Data_Structure
59 * @brief Class containing data about the instance of an application.
60 * Provides methods to get and set the data. It is only representative and doesn't actually synchronize
61 * with the configuration files.
62 */
64 public Application,
65 public std::enable_shared_from_this<ApplicationInstance>
66 {
67
68 private:
69 std::string instanceName;
70 std::filesystem::path configPath;
71 std::string status;
72 std::string nodeName;
73 std::string configDomain;
74 ScenarioPtr scenario;
75 int pid;
76 bool statusWriteBlock;
77 bool enabled;
78 bool readOnly;
79
80 public:
81 /**
82 * Constructor that sets the base data of this ApplicationInstance.
83 * @param executableName The name of the Application
84 * @param executablePath The path of the Executable
85 * @param instanceName a name that distinguishes this instance from other instances
86 * @param configPath path to the config file of this instance
87 */
88 ApplicationInstance(std::string executableName,
89 std::string executablePath,
90 std::string instanceName,
91 std::string configPath,
92 std::string packageName,
93 ScenarioPtr scenarioName,
94 std::string node,
95 bool enabled);
96
97 /**
98 * Constructor that sets the base data of this ApplicationInstance.
99 * @param application The application this class instantiates.
100 * @param instanceName a name that distinguishes this instance from other instances
101 * @param configPath path to the config file of this instance
102 */
104 std::string instanceName,
105 std::string configPath,
106 ScenarioPtr scenarioName,
107 std::string node,
108 bool enabled);
109
110 /**
111 * @return name of this ApplicationInstance
112 */
113 std::string getInstanceName();
114
115 /**
116 * Sets the name of this ApplicationInstance
117 * @param new name
118 */
119 void setInstanceName(std::string newName); //wird die setter gebraucht?
120
121 /**
122 * @return config path of this ApplicationInstance
123 */
124 std::string getConfigPath();
125 bool isConfigWritable();
126
128
129 /**
130 * Sets the config path of this ApplicationInstance
131 * @param new config path
132 */
133 void setConfigPath(std::string configPath);
134
135 /**
136 * @brief resetConfigPath. should be called when the instanceName is changed/ deletes the old cfg file and resets the local config Path to where the file should be
137 * you should call save after this
138 */
139 void resetConfigPath();
140
141 /**
142 * Returns the status. Doesn't update automatically, is not necessarily synchronized with
143 * the actual status of the process. Use the Executor to get the actual status of this application.
144 * @return status of this ApplicationInstance
145 * @see Executor
146 */
147 std::string getStatus();
148
149 /**
150 * Sets the status of this ApplicationInstance
151 * @param new status. Should be either "running" or "stopped" for Scenario statuses to work
152 * properly.
153 * @return tree if status changed.
154 */
155 bool setStatus(const std::string& status);
156
157 std::string getNodeName() const;
158 std::string getEffectiveNodeName() const;
159 void setNodeName(std::string nodeName);
160
161 /**
162 * @return pid of this ApplicationInstance
163 */
164 int getPid();
165
166 /**
167 * Sets the pid of this ApplicationInstance. This pid gets used by the Executor to
168 * stop this application, therefore it is not suggested to set this to random values.
169 * Set this to -1, if no pid is known.
170 * @param pid new pid
171 */
172 void setPid(int pid);
173
174 /**
175 * Changes the value of the specified property.
176 * @param name name of the property whose value is to be changed
177 * @param value new value of the property
178 */
179 void modifyProperty(std::string name, std::string value);
180
181 /**
182 * Adds a new property with the specified name and value to this ApplicationInstance.
183 * @param name name of the new property
184 * @param value value of the new property
185 */
186 void addProperty(std::string name, std::string value);
187
188
189 /**
190 * Saves the IceProperties to the configPath
191 */
192 void save();
193
194 /**
195 * Make a local copy of this instance if it is linked and nothing otherwise
196 */
197 void makeLocal();
198
199 /**
200 * @brief linkFrom Link this instance configuration from the other instance.
201 * @param other the source instance
202 */
203 void linkFrom(ApplicationInstance& other);
204
205 /**
206 * @brief copyFrom Copy the other instance configuration to this one.
207 * @param other the instance to copy
208 */
209 void copyFrom(ApplicationInstance& other);
210
211 void deleteConfig();
212
213 /**
214 * Loades the IceProperties from the configPath
215 * Firstload determins if properties that equal their default value get uncommented
216 */
217 void load(bool firstLoad = false);
218
219 bool getStatusWriteBlock();
220 void setStatusWriteBlock(bool blocked);
221
222
223 bool getEnabled();
224 void setEnabled(bool enabled);
225
226 std::string getConfigDomain() const;
227 void setConfigDomain(const std::string& value);
228
229 bool isReadOnly() const;
230 };
231} // namespace ScenarioManager::Data_Structure
Class containing data about the instance of an application.
ApplicationInstance(std::string executableName, std::string executablePath, std::string instanceName, std::string configPath, std::string packageName, ScenarioPtr scenarioName, std::string node, bool enabled)
Constructor that sets the base data of this ApplicationInstance.
void setInstanceName(std::string newName)
Sets the name of this ApplicationInstance.
void setPid(int pid)
Sets the pid of this ApplicationInstance.
void addProperty(std::string name, std::string value)
Adds a new property with the specified name and value to this ApplicationInstance.
void setConfigPath(std::string configPath)
Sets the config path of this ApplicationInstance.
void modifyProperty(std::string name, std::string value)
Changes the value of the specified property.
void makeLocal()
Make a local copy of this instance if it is linked and nothing otherwise.
void save()
Saves the IceProperties to the configPath.
void copyFrom(ApplicationInstance &other)
copyFrom Copy the other instance configuration to this one.
void linkFrom(ApplicationInstance &other)
linkFrom Link this instance configuration from the other instance.
void load(bool firstLoad=false)
Loades the IceProperties from the configPath Firstload determins if properties that equal their defau...
bool setStatus(const std::string &status)
Sets the status of this ApplicationInstance.
Application(std::string name, std::string executablePath, std::string packageName)
Constructor that sets the name and the path to the executable of the application.
std::shared_ptr< Scenario > ScenarioPtr
Definition Scenario.h:35
std::weak_ptr< ApplicationInstance > ApplicationInstanceWPtr
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
std::shared_ptr< std::vector< ApplicationInstancePtr > > ApplicationInstanceVectorPtr