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 {
32  class ApplicationInstance;
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  */
103  ApplicationInstance(Application application,
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
ScenarioManager::Data_Structure::ApplicationInstancePtr
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
Definition: ApplicationInstance.h:33
ScenarioManager::Data_Structure::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Definition: Scenario.h:35
Scenario.h
ScenarioManager::Data_Structure::ApplicationInstance::getPid
int getPid()
Definition: ApplicationInstance.cpp:182
ScenarioManager::Data_Structure::ApplicationInstance::modifyProperty
void modifyProperty(std::string name, std::string value)
Changes the value of the specified property.
Definition: ApplicationInstance.cpp:194
ScenarioManager::Data_Structure::ApplicationInstanceVectorPtr
std::shared_ptr< std::vector< ApplicationInstancePtr > > ApplicationInstanceVectorPtr
Definition: ApplicationInstance.h:35
ScenarioManager::Data_Structure::ApplicationInstance
Class containing data about the instance of an application. Provides methods to get and set the data....
Definition: ApplicationInstance.h:63
ScenarioManager::Data_Structure::ApplicationInstance::getNodeName
std::string getNodeName() const
Definition: ApplicationInstance.cpp:310
ScenarioManager::Data_Structure::ApplicationStatus
Definition: ApplicationInstance.h:45
ScenarioManager::Data_Structure::ApplicationStatus::Stopped
static const std::string Stopped
Definition: ApplicationInstance.h:47
ScenarioManager::Data_Structure::ApplicationInstance::getEffectiveNodeName
std::string getEffectiveNodeName() const
Definition: ApplicationInstance.cpp:316
ScenarioManager::Data_Structure::ApplicationInstance::setStatus
bool setStatus(const std::string &status)
Sets the status of this ApplicationInstance.
Definition: ApplicationInstance.cpp:171
ScenarioManager::Data_Structure::ApplicationStatus::Missing
static const std::string Missing
Definition: ApplicationInstance.h:53
ScenarioManager::Data_Structure::ApplicationStatus::Running
static const std::string Running
Definition: ApplicationInstance.h:48
ScenarioManager::Data_Structure::ApplicationInstance::setConfigDomain
void setConfigDomain(const std::string &value)
Definition: ApplicationInstance.cpp:57
ScenarioManager::Data_Structure::ApplicationInstance::getScenario
ScenarioPtr getScenario()
Definition: ApplicationInstance.cpp:108
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
ScenarioManager::Data_Structure::ApplicationInstance::setInstanceName
void setInstanceName(std::string newName)
Sets the name of this ApplicationInstance.
Definition: ApplicationInstance.cpp:120
ScenarioManager::Data_Structure::ApplicationInstance::getConfigDomain
std::string getConfigDomain() const
Definition: ApplicationInstance.cpp:51
ScenarioManager::Data_Structure::ApplicationInstance::getStatus
std::string getStatus()
Returns the status.
Definition: ApplicationInstance.cpp:165
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
ScenarioManager::Data_Structure::ApplicationInstance::deleteConfig
void deleteConfig()
Definition: ApplicationInstance.cpp:261
ScenarioManager::Data_Structure::ApplicationInstance::ApplicationInstance
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.
ScenarioManager::Data_Structure::ApplicationInstance::resetConfigPath
void resetConfigPath()
resetConfigPath.
Definition: ApplicationInstance.cpp:138
ScenarioManager::Data_Structure::ApplicationStatus::Waiting
static const std::string Waiting
Definition: ApplicationInstance.h:49
ScenarioManager::Data_Structure::ApplicationInstance::getConfigPath
std::string getConfigPath()
Definition: ApplicationInstance.cpp:126
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
ScenarioManager::Data_Structure::ApplicationInstance::setPid
void setPid(int pid)
Sets the pid of this ApplicationInstance.
Definition: ApplicationInstance.cpp:188
ScenarioManager::Data_Structure::ApplicationInstance::isConfigWritable
bool isConfigWritable()
Definition: ApplicationInstance.cpp:287
ScenarioManager::Data_Structure
Definition: Application.cpp:180
ScenarioManager::Data_Structure::ApplicationStatus::Inactive
static const std::string Inactive
Definition: ApplicationInstance.h:52
ScenarioManager::Data_Structure::ApplicationInstance::copyFrom
void copyFrom(ApplicationInstance &other)
copyFrom Copy the other instance configuration to this one.
Definition: ApplicationInstance.cpp:251
ScenarioManager::Data_Structure::ApplicationStatus::Mixed
static const std::string Mixed
Definition: ApplicationInstance.h:50
ScenarioManager::Data_Structure::ApplicationStatus::Unknown
static const std::string Unknown
Definition: ApplicationInstance.h:51
ScenarioManager::Data_Structure::ApplicationInstance::setStatusWriteBlock
void setStatusWriteBlock(bool blocked)
Definition: ApplicationInstance.cpp:304
ScenarioManager::Data_Structure::ApplicationInstance::addProperty
void addProperty(std::string name, std::string value)
Adds a new property with the specified name and value to this ApplicationInstance.
Definition: ApplicationInstance.cpp:204
ScenarioManager::Data_Structure::ApplicationInstance::save
void save()
Saves the IceProperties to the configPath.
Definition: ApplicationInstance.cpp:214
ScenarioManager::Data_Structure::ApplicationInstance::getInstanceName
std::string getInstanceName()
Definition: ApplicationInstance.cpp:114
ScenarioManager::Data_Structure::ApplicationInstance::setEnabled
void setEnabled(bool enabled)
Definition: ApplicationInstance.cpp:334
ApplicationInstance
Interface for classes that handle the starting of applications Classes implementing this interface al...
ScenarioManager::Data_Structure::ApplicationInstance::load
void load(bool firstLoad=false)
Loades the IceProperties from the configPath Firstload determins if properties that equal their defau...
Definition: ApplicationInstance.cpp:270
ScenarioManager::Data_Structure::ApplicationInstance::getEnabled
bool getEnabled()
Definition: ApplicationInstance.cpp:328
ScenarioManager::Data_Structure::ApplicationInstance::getStatusWriteBlock
bool getStatusWriteBlock()
Definition: ApplicationInstance.cpp:298
ScenarioManager::Data_Structure::ApplicationInstance::makeLocal
void makeLocal()
Make a local copy of this instance if it is linked and nothing otherwise.
Definition: ApplicationInstance.cpp:221
ScenarioManager::Data_Structure::ApplicationInstance::linkFrom
void linkFrom(ApplicationInstance &other)
linkFrom Link this instance configuration from the other instance.
Definition: ApplicationInstance.cpp:241
Application.h
ScenarioManager::Data_Structure::ApplicationInstance::isReadOnly
bool isReadOnly() const
Definition: ApplicationInstance.cpp:64
ScenarioManager::Data_Structure::ApplicationInstanceWPtr
std::weak_ptr< ApplicationInstance > ApplicationInstanceWPtr
Definition: ApplicationInstance.h:34
ScenarioManager::Data_Structure::ApplicationInstance::setNodeName
void setNodeName(std::string nodeName)
Definition: ApplicationInstance.cpp:322
ScenarioManager::Data_Structure::ApplicationInstance::setConfigPath
void setConfigPath(std::string configPath)
Sets the config path of this ApplicationInstance.
Definition: ApplicationInstance.cpp:132