3 #include <experimental/memory>
18 #include "../ProviderID.h"
19 #include "../SkillExecutionRequest.h"
20 #include "../SkillID.h"
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_WARNING <<
"No fallback value found for parameter " << param.name;
79 type->addMemberType(param.name, param.type);
82 const auto& params = std::make_shared<armarx::aron::data::Dict>();
86 const auto& paramIt = this->fluxioSkill.
parameters.find(key);
87 if (paramIt == this->fluxioSkill.
parameters.end())
89 ARMARX_WARNING <<
"Parameter with ID " << key <<
" not found in skill "
90 << this->fluxioSkill.
id;
97 ARMARX_WARNING <<
"Value for parameter " << paramIt->second.name <<
" is null";
100 params->addElement(paramIt->second.name,
value);
104 const auto& isValide = params->fullfillsType(type);
108 ARMARX_WARNING <<
"Parameters do not fullfill the type of the skill";
109 ARMARX_WARNING <<
"Can't execute skill due to incompatible params.";
120 ARMARX_WARNING <<
"Executing skill with the following parameters: "
123 auto eid = executeSkillAsync(req);
125 this->executionId = eid;
140 if (!this->executionId.has_value())
143 ARMARX_WARNING <<
"Execution ID not set. Cannot abort skill (it should not be running "
148 abortSkill(this->executionId.value());
151 std::optional<std::vector<skills::FluxioSkillStatusUpdate>>
154 if (!this->executionId.has_value())
158 return std::vector<skills::FluxioSkillStatusUpdate>(this->
statusUpdates.begin(),
159 this->statusUpdates.end());
162 auto executionId = this->executionId.value();
164 auto status = getSkillExecutionStatus(executionId);
169 ARMARX_WARNING <<
"No status with execution ID " << this->executionId->toString()
180 this->setStatus(
update.status);
183 return std::vector<skills::FluxioSkillStatusUpdate>(this->
statusUpdates.begin(),
184 this->statusUpdates.end());
197 if (!executionId.has_value())
199 ARMARX_WARNING <<
"No execution ID available for skill " << this->skillId;
203 const auto&
s = getSkillExecutionStatus(executionId.value());
204 if (!
s.has_value() ||
s->result ==
nullptr)
206 ARMARX_WARNING <<
"No result available for skill " << this->skillId;
210 for (
const auto& [key,
value] :
s->result->getElements())
213 const auto& params = this->fluxioSkill.
parameters;
215 std::find_if(params.begin(),
217 [&key](
const std::pair<std::string, FluxioParameter>& it)
218 { return !it.second.isInput && it.second.name == key; });
220 if (param == params.end())
222 ARMARX_WARNING <<
"Parameter with name " << key <<
" not found in skill "
229 return this->
result->clone();