70 bool sawMissing =
false;
71 bool sawUnknown =
false;
73 const std::string* definite =
nullptr;
75 for (
const std::string&
status : stati)
92 if (definite ==
nullptr)
96 else if (*definite !=
status)
102 if (definite !=
nullptr)
127 configDomain = value;
133 return this->readOnly;
137 std::string executablePath,
138 std::string instanceName,
139 std::string configPath,
140 std::string packageName,
144 Application(executableName, executablePath, packageName),
145 instanceName(instanceName),
146 configPath(configPath),
157 std::string instanceName,
158 std::string configPath,
163 instanceName(instanceName),
164 configPath(configPath),
183 return this->instanceName;
189 this->instanceName = newName;
195 return this->configPath;
201 this->configPath = configPath;
207 std::filesystem::path scenariosFolder(scenario->getPackage()->getScenarioPath());
208 std::filesystem::path scenarioFolder = scenariosFolder / scenario->getName();
209 std::filesystem::path scenarioCfgFolder = scenarioFolder /
"config";
211 std::filesystem::path configPath = scenarioCfgFolder;
213 if (!this->instanceName.empty() && this->instanceName != R
"("")" &&
214 this->instanceName != R"(" ")")
220 configPath = configPath / (this->
getName() +
".cfg");
224 if (configPath != this->configPath)
226 std::filesystem::remove(std::filesystem::path(this->configPath));
228 this->configPath = configPath.string();
240 bool result = status != this->status;
243 this->status = status;
263 int expected = expectedPid;
264 return pid.compare_exchange_strong(expected, -1);
271 return pid.compare_exchange_strong(expected, newPid);
280 if (!props->isPropertySet(name))
282 props->defineOptionalProperty(name, std::string(
"::NOT_DEFINED::"),
"Custom Property");
284 props->getProperties()->setProperty(name, value);
291 if (!props->isPropertySet(name))
293 props->defineOptionalProperty(name, std::string(
"::NOT_DEFINED::"),
"Custom Property");
295 props->getProperties()->setProperty(name, value);
302 parser.saveCfg(shared_from_this());
313 if (!std::filesystem::is_symlink(configPath))
319 std::filesystem::remove(configPath);
330 auto target_path = other.configPath.lexically_relative(configPath.parent_path());
331 std::filesystem::create_symlink(target_path, configPath);
340 std::filesystem::copy_file(
341 other.configPath, configPath, std::filesystem::copy_options::overwrite_existing);
348 if (std::filesystem::exists(this->configPath))
350 std::filesystem::remove(this->configPath);
357 if (!std::filesystem::exists(configPath))
359 ARMARX_WARNING_S <<
"Cannot find ApplicationInstance Config at:" << configPath;
364 setProperties(parser.mergeXmlAndCfg(shared_from_this(), firstLoad));
368 this->readOnly = std::filesystem::is_symlink(configPath);
376 ofs.open(configPath.c_str(), std::ofstream::out | std::ofstream::app);
377 ARMARX_DEBUG << configPath <<
" is writeable: " << ofs.is_open();
379 return ofs.is_open();
385 return pendingIntent;
391 pendingIntent = intent;
403 return nodeName.empty() && scenario ? scenario->getNodeName() : nodeName;
409 this->nodeName = nodeName;
421 this->enabled = enabled;
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.
std::string getInstanceName()
void setEnabled(bool enabled)
void setPid(int pid)
Sets the pid of this ApplicationInstance.
void resetConfigPath()
resetConfigPath.
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.
std::string getConfigDomain() const
bool adoptPidIfUnset(int newPid)
Sets the pid to newPid, but only if no pid is currently known (i.e.
void setPendingIntent(Intent intent)
std::string getConfigPath()
std::string getEffectiveNodeName() const
ScenarioPtr getScenario()
Intent getPendingIntent() const
The intent this application is currently moving towards, or None when idle.
void modifyProperty(std::string name, std::string value)
Changes the value of the specified property.
void setConfigDomain(const std::string &value)
std::string getStatus()
Returns the status.
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.
bool compareAndResetPid(int expectedPid)
Sets the pid to -1, but only if it is still expectedPid.
void load(bool firstLoad=false)
Loades the IceProperties from the configPath Firstload determins if properties that equal their defau...
void setNodeName(std::string nodeName)
bool setStatus(const std::string &status)
Sets the status of this ApplicationInstance.
std::string getNodeName() const
void setProperties(armarx::PropertyDefinitionsPtr properties)
Sets the properties of this 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.
armarx::PropertyDefinitionsPtr getProperties()
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
std::shared_ptr< Scenario > ScenarioPtr
Intent
What the ScenarioManager is currently trying to do with an application.
const char * ToString(Intent intent)
Human readable name of an intent, for logging.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
static const std::string Stopped
static const std::string Mixed
static const std::string Missing
static const std::string Unknown
static const std::string Inactive
static const std::string Waiting
static std::string Aggregate(const std::vector< std::string > &stati)
Combines the stati of several applications into the status of their common parent (a scenario or the ...
static const std::string Running