3#include <experimental/memory>
25 const std::string&
id,
30 executeSkillAsyncFunc,
31 const std::function<std::optional<skills::SkillStatusUpdate>(
35 fluxioSkill(fluxioSkill),
36 abortSkill(abortSkillFunc),
37 executeSkillAsync(executeSkillAsyncFunc),
38 getSkillExecutionStatus(getSkillExecutionStatusFunc)
41 result = std::make_shared<armarx::aron::data::Dict>();
51 result = std::make_shared<armarx::aron::data::Dict>();
57 const auto& type = std::make_shared<armarx::aron::type::Object>();
60 for (
const auto& [key, param] : this->fluxioSkill.
parameters)
62 if (param.type->getShortName() ==
"Object<Event>" || !param.isInput ||
63 this->possibleInputs[this->fluxioSkill.id]->hasElement(key))
69 if (fallBack ==
nullptr)
71 ARMARX_INFO <<
"No fallback value found for parameter " << param.name;
74 ARMARX_INFO <<
"Parameter is not required (MAYBE type). Using nullptr "
75 "(std::nullopt) instead.";
79 ARMARX_INFO <<
"Can't execute skill due to incomplete params.";
88 type->addMemberType(param.name, param.type);
91 const auto& params = std::make_shared<armarx::aron::data::Dict>();
93 for (
const auto& [key, value] : this->
possibleInputs[this->fluxioSkill.
id]->getElements())
95 const auto& paramIt = this->fluxioSkill.
parameters.find(key);
96 if (paramIt == this->fluxioSkill.
parameters.end())
98 ARMARX_WARNING <<
"Parameter with ID " << key <<
" not found in skill "
99 << this->fluxioSkill.
id;
100 ARMARX_WARNING <<
"Can't execute skill due to incomplete params.";
104 if (value ==
nullptr && paramIt->second.required)
106 ARMARX_INFO <<
"Value for parameter " << paramIt->second.name <<
" is null.";
109 params->addElement(paramIt->second.name, value);
113 const auto& isValid = params->fullfillsType(type);
117 ARMARX_WARNING <<
"Parameters do not fullfill the type of the skill";
118 ARMARX_WARNING <<
"Can't execute skill due to incompatible params.";
129 ARMARX_WARNING <<
"Executing skill with the following parameters: "
132 auto eid = executeSkillAsync(req);
134 this->executionId = eid;
149 if (!this->executionId.has_value())
152 ARMARX_WARNING <<
"Execution ID not set. Cannot abort skill (it should not be running "
157 abortSkill(this->executionId.value());
160 std::optional<std::vector<skills::FluxioSkillStatusUpdate>>
163 if (!this->executionId.has_value())
167 return std::vector<skills::FluxioSkillStatusUpdate>(this->
statusUpdates.begin(),
168 this->statusUpdates.end());
171 auto executionId = this->executionId.value();
173 auto status = getSkillExecutionStatus(executionId);
178 ARMARX_WARNING <<
"No status with execution ID " << this->executionId->toString()
187 if (this->
statusUpdates.empty() || update.status != this->statusUpdates.front().status)
189 this->setStatus(update.status);
192 return std::vector<skills::FluxioSkillStatusUpdate>(this->
statusUpdates.begin(),
193 this->statusUpdates.end());
206 if (!executionId.has_value())
208 ARMARX_WARNING <<
"No execution ID available for skill " << this->skillId;
212 const auto& s = getSkillExecutionStatus(executionId.value());
213 if (!s.has_value() || s->result ==
nullptr)
215 ARMARX_WARNING <<
"No result available for skill " << this->skillId;
219 for (
const auto& [key, value] : s->result->getElements())
222 const auto& params = this->fluxioSkill.
parameters;
224 std::find_if(params.begin(),
226 [&key](
const std::pair<std::string, FluxioParameter>& it)
227 { return !it.second.isInput && it.second.name == key; });
229 if (param == params.end())
231 ARMARX_WARNING <<
"Parameter with name " << key <<
" not found in skill "
235 this->
result->addElement(param->second.id, value);
238 return this->
result->clone();
static nlohmann::json ConvertToNlohmannJSON(const data::VariantPtr &)
FluxioExecutor(const FluxioExecutor &)=delete
armarx::aron::data::DictPtr result
armarx::aron::data::VariantPtr findParameterValue(const std::experimental::observer_ptr< const FluxioProfile > profilePtr, const FluxioParameter ¶meter) const
std::optional< skills::FluxioSkillStatusUpdate > status
std::shared_mutex resultMutex
std::list< skills::FluxioSkillStatusUpdate > statusUpdates
std::shared_mutex statusMutex
std::map< std::string, armarx::aron::data::DictPtr > possibleInputs
std::optional< std::string > executorName
virtual void setStatus(skills::SkillStatus status, const std::string &nodeId="noId")
std::shared_mutex possibleInputsMutex
void run(std::string executorName, armarx::aron::data::DictPtr parameters, std::experimental::observer_ptr< const FluxioProfile > profilePtr) override
FluxioNativeExecutor(const std::string &id, const skills::SkillID &skillId, const FluxioSkill &fluxioSkill, const std::function< bool(const skills::SkillExecutionID &)> &&abortSkillFunc, const std::function< skills::SkillExecutionID(const skills::SkillExecutionRequest &)> &&executeSkillAsyncFunc, const std::function< std::optional< skills::SkillStatusUpdate >(const skills::SkillExecutionID &)> &&getSkillExecutionStatusFunc)
std::optional< std::vector< skills::FluxioSkillStatusUpdate > > getStatusUpdate() override
armarx::aron::data::DictPtr getResultsCopy() override
armarx::aron::data::DictPtr parameters
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
std::shared_ptr< Dict > DictPtr
This file is part of ArmarX.
std::map< std::string, FluxioParameter > parameters