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 }
37 
38 #include "Scenario.h"
39 
40 #include <memory>
41 #include <string>
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  */
63  class ApplicationInstance : public Application, public std::enable_shared_from_this<ApplicationInstance>
64  {
65 
66  private:
67  std::string instanceName;
68  std::filesystem::path configPath;
69  std::string status;
70  std::string nodeName;
71  std::string configDomain;
72  ScenarioPtr scenario;
73  int pid;
74  bool statusWriteBlock;
75  bool enabled;
76  bool iceAutoRestart;
77  bool readOnly;
78 
79  public:
80  /**
81  * Constructor that sets the base data of this ApplicationInstance.
82  * @param executableName The name of the Application
83  * @param executablePath The path of the Executable
84  * @param instanceName a name that distinguishes this instance from other instances
85  * @param configPath path to the config file of this instance
86  */
87  ApplicationInstance(std::string executableName, std::string executablePath, std::string instanceName, std::string configPath, std::string packageName, ScenarioPtr scenarioName, std::string node, bool enabled, bool iceAutoRestart);
88 
89  /**
90  * Constructor that sets the base data of this ApplicationInstance.
91  * @param application The application this class instantiates.
92  * @param instanceName a name that distinguishes this instance from other instances
93  * @param configPath path to the config file of this instance
94  */
95  ApplicationInstance(Application application, std::string instanceName, std::string configPath, ScenarioPtr scenarioName, std::string node, bool enabled, bool iceAutoRestart);
96 
97  /**
98  * @return name of this ApplicationInstance
99  */
100  std::string getInstanceName();
101 
102  /**
103  * Sets the name of this ApplicationInstance
104  * @param new name
105  */
106  void setInstanceName(std::string newName); //wird die setter gebraucht?
107 
108  /**
109  * @return config path of this ApplicationInstance
110  */
111  std::string getConfigPath();
112  bool isConfigWritable();
113 
115 
116  /**
117  * Sets the config path of this ApplicationInstance
118  * @param new config path
119  */
120  void setConfigPath(std::string configPath);
121 
122  /**
123  * @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
124  * you should call save after this
125  */
126  void resetConfigPath();
127 
128  /**
129  * Returns the status. Doesn't update automatically, is not necessarily synchronized with
130  * the actual status of the process. Use the Executor to get the actual status of this application.
131  * @return status of this ApplicationInstance
132  * @see Executor
133  */
134  std::string getStatus();
135 
136  /**
137  * Sets the status of this ApplicationInstance
138  * @param new status. Should be either "running" or "stopped" for Scenario statuses to work
139  * properly.
140  * @return tree if status changed.
141  */
142  bool setStatus(const std::string& status);
143 
144  std::string getNodeName() const;
145  std::string getEffectiveNodeName() const;
146  void setNodeName(std::string nodeName);
147 
148  /**
149  * @return pid of this ApplicationInstance
150  */
151  int getPid();
152 
153  /**
154  * Sets the pid of this ApplicationInstance. This pid gets used by the Executor to
155  * stop this application, therefore it is not suggested to set this to random values.
156  * Set this to -1, if no pid is known.
157  * @param pid new pid
158  */
159  void setPid(int pid);
160 
161  /**
162  * Changes the value of the specified property.
163  * @param name name of the property whose value is to be changed
164  * @param value new value of the property
165  */
166  void modifyProperty(std::string name, std::string value);
167 
168  /**
169  * Adds a new property with the specified name and value to this ApplicationInstance.
170  * @param name name of the new property
171  * @param value value of the new property
172  */
173  void addProperty(std::string name, std::string value);
174 
175 
176  /**
177  * Saves the IceProperties to the configPath
178  */
179  void save();
180 
181  /**
182  * Make a local copy of this instance if it is linked and nothing otherwise
183  */
184  void makeLocal();
185 
186  /**
187  * @brief linkFrom Link this instance configuration from the other instance.
188  * @param other the source instance
189  */
190  void linkFrom(ApplicationInstance& other);
191 
192  /**
193  * @brief copyFrom Copy the other instance configuration to this one.
194  * @param other the instance to copy
195  */
196  void copyFrom(ApplicationInstance& other);
197 
198  void deleteConfig();
199 
200  /**
201  * Loades the IceProperties from the configPath
202  * Firstload determins if properties that equal their default value get uncommented
203  */
204  void load(bool firstLoad = false);
205 
206  bool getStatusWriteBlock();
207  void setStatusWriteBlock(bool blocked);
208 
209 
210  bool getEnabled();
211  void setEnabled(bool enabled);
212 
213  bool getIceAutoRestart();
214  void setIceAutoRestart(bool enabled);
215  std::string getConfigDomain() const;
216  void setConfigDomain(const std::string& value);
217 
218  bool isReadOnly() const;
219  };
220 }
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:36
Scenario.h
ScenarioManager::Data_Structure::ApplicationInstance::getPid
int getPid()
Definition: ApplicationInstance.cpp:152
ScenarioManager::Data_Structure::ApplicationInstance::modifyProperty
void modifyProperty(std::string name, std::string value)
Changes the value of the specified property.
Definition: ApplicationInstance.cpp:162
ScenarioManager::Data_Structure::ApplicationInstance::setIceAutoRestart
void setIceAutoRestart(bool enabled)
Definition: ApplicationInstance.cpp:297
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:267
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:272
ScenarioManager::Data_Structure::ApplicationInstance::setStatus
bool setStatus(const std::string &status)
Sets the status of this ApplicationInstance.
Definition: ApplicationInstance.cpp:142
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:55
ScenarioManager::Data_Structure::ApplicationInstance::getScenario
ScenarioPtr getScenario()
Definition: ApplicationInstance.cpp:88
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, bool iceAutoRestart)
Constructor that sets the base data of this ApplicationInstance.
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
ScenarioManager::Data_Structure::ApplicationInstance::setInstanceName
void setInstanceName(std::string newName)
Sets the name of this ApplicationInstance.
Definition: ApplicationInstance.cpp:98
ScenarioManager::Data_Structure::ApplicationInstance::getConfigDomain
std::string getConfigDomain() const
Definition: ApplicationInstance.cpp:50
ScenarioManager::Data_Structure::ApplicationInstance::getStatus
std::string getStatus()
Returns the status.
Definition: ApplicationInstance.cpp:137
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
ScenarioManager::Data_Structure::ApplicationInstance::deleteConfig
void deleteConfig()
Definition: ApplicationInstance.cpp:223
ScenarioManager::Data_Structure::ApplicationInstance::getIceAutoRestart
bool getIceAutoRestart()
Definition: ApplicationInstance.cpp:292
ScenarioManager::Data_Structure::ApplicationInstance::resetConfigPath
void resetConfigPath()
resetConfigPath.
Definition: ApplicationInstance.cpp:113
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:103
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:157
ScenarioManager::Data_Structure::ApplicationInstance::isConfigWritable
bool isConfigWritable()
Definition: ApplicationInstance.cpp:247
ScenarioManager::Data_Structure
Definition: Application.cpp:166
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:214
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:262
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:171
ScenarioManager::Data_Structure::ApplicationInstance::save
void save()
Saves the IceProperties to the configPath.
Definition: ApplicationInstance.cpp:180
ScenarioManager::Data_Structure::ApplicationInstance::getInstanceName
std::string getInstanceName()
Definition: ApplicationInstance.cpp:93
ScenarioManager::Data_Structure::ApplicationInstance::setEnabled
void setEnabled(bool enabled)
Definition: ApplicationInstance.cpp:287
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:231
ScenarioManager::Data_Structure::ApplicationInstance::getEnabled
bool getEnabled()
Definition: ApplicationInstance.cpp:282
ScenarioManager::Data_Structure::ApplicationInstance::getStatusWriteBlock
bool getStatusWriteBlock()
Definition: ApplicationInstance.cpp:257
ScenarioManager::Data_Structure::ApplicationInstance::makeLocal
void makeLocal()
Make a local copy of this instance if it is linked and nothing otherwise.
Definition: ApplicationInstance.cpp:186
ScenarioManager::Data_Structure::ApplicationInstance::linkFrom
void linkFrom(ApplicationInstance &other)
linkFrom Link this instance configuration from the other instance.
Definition: ApplicationInstance.cpp:205
Application.h
ScenarioManager::Data_Structure::ApplicationInstance::isReadOnly
bool isReadOnly() const
Definition: ApplicationInstance.cpp:61
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:277
ScenarioManager::Data_Structure::ApplicationInstance::setConfigPath
void setConfigPath(std::string configPath)
Sets the config path of this ApplicationInstance.
Definition: ApplicationInstance.cpp:108