18 auto& p = parent<SkillProviderComponentPluginUser>();
19 p.getProxy(myPrx, -1);
25 auto& p = parent<SkillProviderComponentPluginUser>();
26 const std::string providerName = p.getName();
30 .providerInterface = myPrx,
33 ARMARX_INFO <<
"Adding provider to manager: " << i.providerId;
34 manager->addProvider(i.toIce());
40 auto& p = parent<SkillProviderComponentPluginUser>();
41 std::string providerName = p.getName();
43 auto id = skills::manager::dto::ProviderID{providerName};
44 manager->removeProvider(
id);
50 std::string
prefix =
"skill.";
51 properties->component(
55 "The name of the SkillManager (or SkillMemory) proxy this provider belongs to.");
66 auto& p = parent<SkillProviderComponentPluginUser>();
67 const std::string componentName = p.getName();
72 const std::unique_lock l(skillFactoriesMutex);
73 auto skillId = fac->createSkillDescription(providerId).skillId;
75 if (skillFactories.find(skillId) != skillFactories.end())
77 ARMARX_WARNING <<
"Try to add a skill factory for skill '" + skillId.toString() +
78 "' which already exists in list. Ignoring this skill.";
82 ARMARX_INFO <<
"Adding skill `" << skillId <<
"` to component `" << componentName <<
"` .";
84 skillFactories.emplace(skillId, std::move(fac));
99 return addSkillFactory<skills::LambdaSkill>(desc, f);
108 if (skillFactories.count(skillId) == 0)
110 ARMARX_INFO <<
"Could not find a skill factory for id: " << skillId;
114 auto* facPtr = skillFactories.at(skillId).get();
118 std::optional<skills::SkillStatusUpdate>
124 const std::shared_lock l(skillExecutionsMutex);
125 if (skillExecutions.find(execId) == skillExecutions.end())
132 std::scoped_lock l2{skillExecutions.at(execId).skillStatusesMutex};
133 return skillExecutions.at(execId).statusUpdate;
136 std::map<skills::SkillExecutionID, skills::SkillStatusUpdate>
139 std::map<skills::SkillExecutionID, skills::SkillStatusUpdate> skillUpdates;
141 const std::shared_lock l(skillExecutionsMutex);
142 for (
const auto& [key, impl] : skillExecutions)
144 const std::scoped_lock l2(impl.skillStatusesMutex);
145 skillUpdates.insert({key, impl.statusUpdate});
150 std::optional<skills::SkillDescription>
155 const std::shared_lock l(skillFactoriesMutex);
156 if (skillFactories.find(skillId) == skillFactories.end())
158 std::stringstream ss;
159 ss <<
"Skill description for skill '" + skillId.
toString() +
160 "' not found! Found instead: {"
162 for (
const auto& [k, _] : skillFactories)
164 ss <<
"\t" << k.toString() <<
"\n";
172 return skillFactories.at(skillId)->createSkillDescription(*skillId.
providerId);
175 std::map<skills::SkillID, skills::SkillDescription>
178 std::map<skills::SkillID, skills::SkillDescription> skillDesciptions;
179 const std::shared_lock l(skillFactoriesMutex);
180 for (
const auto& [key, fac] : skillFactories)
183 skillDesciptions.insert({key, fac->createSkillDescription(*key.providerId)});
185 return skillDesciptions;
196 .executionStartedTime =
204 auto l1 = std::unique_lock{skillFactoriesMutex};
206 const auto& fac = getSkillFactory(executionId.skillId);
207 ARMARX_CHECK(fac) <<
"Could not find a factory for skill " << executionId.skillId;
210 const std::unique_lock l2{skillExecutionsMutex};
212 skillExecutions.emplace(std::piecewise_construct,
213 std::make_tuple(executionId),
218 wrapper = &it.first->second;
230 ret.result = x.result;
233 catch(std::exception& e)
235 ARMARX_WARNING <<
"Got an uncatched Exception when executing a skill. Exception was: " << e.what();
240 if (wrapper && wrapper->
execution.joinable())
265 auto l1 = std::unique_lock{skillFactoriesMutex};
267 const auto& fac = getSkillFactory(executionRequest.
skillId);
271 const std::unique_lock l2{skillExecutionsMutex};
277 if (skillExecutions.count(executionId) > 0)
279 ARMARX_ERROR <<
"SkillsExecutionID already exists! This is undefined behaviour and should not occur!";
283 skillExecutions.emplace(std::piecewise_construct,
284 std::make_tuple(executionId),
289 wrapper = &it.first->second;
301 catch(std::exception& e)
303 ARMARX_WARNING <<
"Got an uncatched Exception when executing a skill. Exception was: " << e.what();
320 std::this_thread::sleep_for(std::chrono::milliseconds(20));
332 std::shared_lock l{skillExecutionsMutex};
333 auto it = skillExecutions.find(executionId);
334 if (it == skillExecutions.end())
337 "' found! Ignoring prepareSkill request.";
341 std::scoped_lock l2{it->second.skillStatusesMutex};
345 "' because its not in preparing phase.";
349 it->second.updateSkillParameters(
input);
358 std::shared_lock l(skillExecutionsMutex);
359 auto it = skillExecutions.find(executionId);
360 if (it == skillExecutions.end())
363 "' found! Ignoring abortSkill request.";
367 auto& runtime = it->second;
373 std::scoped_lock l(runtime.skillStatusesMutex);
374 auto status = runtime.statusUpdate;
376 if (
status.hasBeenTerminated())
381 std::this_thread::sleep_for(std::chrono::milliseconds(20));
392 std::shared_lock l(skillExecutionsMutex);
393 auto it = skillExecutions.find(executionId);
394 if (it == skillExecutions.end())
397 "' found! Ignoring abortSkill request.";
401 it->second.stopSkill();
414 IceUtil::Optional<skills::provider::dto::SkillDescription>
416 const skills::provider::dto::SkillID& skillId,
417 const Ice::Current& )
420 auto o = plugin->getSkillDescription(
id);
423 return o->toProviderIce();
428 skills::provider::dto::SkillDescriptionMap
431 skills::provider::dto::SkillDescriptionMap
ret;
432 for (
const auto& [k,
v] : plugin->getSkillDescriptions())
434 ret.insert({k.toProviderIce(),
v.toProviderIce()});
439 IceUtil::Optional<skills::provider::dto::SkillStatusUpdate>
441 const skills::provider::dto::SkillExecutionID& executionId,
442 const Ice::Current& )
446 auto o = plugin->getSkillExecutionStatus(execId);
449 return o->toProviderIce();
454 skills::provider::dto::SkillStatusUpdateMap
457 skills::provider::dto::SkillStatusUpdateMap
ret;
458 for (
const auto& [k,
v] : plugin->getSkillExecutionStatuses())
460 ret.insert({k.toProviderIce(),
v.toProviderIce()});
466 skills::provider::dto::SkillStatusUpdate
468 const skills::provider::dto::SkillExecutionRequest& info,
469 const Ice::Current& )
473 auto up = this->plugin->executeSkill(exec);
474 return up.toProviderIce();
477 skills::provider::dto::SkillExecutionID
479 const skills::provider::dto::SkillExecutionRequest& info,
480 const Ice::Current& current )
484 auto id = this->plugin->executeSkillAsync(exec);
485 return id.toProviderIce();
488 skills::provider::dto::ParameterUpdateResult
490 const skills::provider::dto::SkillExecutionID&
id,
492 const Ice::Current& current )
494 skills::provider::dto::ParameterUpdateResult res;
499 res.success = this->plugin->updateSkillParameters(exec, prep);
503 skills::provider::dto::AbortSkillResult
505 const Ice::Current& )
507 skills::provider::dto::AbortSkillResult res;
510 res.success = this->plugin->abortSkill(exec);
514 skills::provider::dto::AbortSkillResult
516 const skills::provider::dto::SkillExecutionID&
id,
517 const Ice::Current& )
519 skills::provider::dto::AbortSkillResult res;
522 res.success = this->plugin->abortSkillAsync(exec);