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