9 using StatusMap = std::map<skills::SkillExecutionID, skills::SkillStatusUpdate>;
11 std::map<skills::ProviderID, std::map<skills::SkillID, skills::SkillDescription>>;
14 SkillManagerWrapper::fetchExecutionsFromMemory()
24 std::scoped_lock l(mutex_memory);
29 auto currentManagerStatuses =
memory->ice_invocationTimeout(10000)->getSkillExecutionStatuses();
32 for (
const auto& [k,
v] : currentManagerStatuses)
38 statusMap[executionId] = statusUpdate;
42 catch (Ice::Exception
const& e)
45 <<
"Unhandled Ice exception encountered while updating executions. Exception was: "
52 ARMARX_WARNING <<
"Unknown exception encountered while updating executions.";
59 matches(std::string skillName, std::vector<std::string>& searches)
62 for (std::string& substring : searches)
64 size_t occurance = skillName.find(substring,
index);
65 if (occurance == std::string::npos)
77 SkillManagerWrapper::Snapshot
78 SkillManagerWrapper::filterUpdate(Snapshot
update)
81 if (this->currentSkillSearch.empty())
89 filtered.statuses =
update.statuses;
91 std::vector<std::string> substrings;
95 for (
auto&
string : rawSubstrings)
97 substrings.push_back(simox::alg::to_lower(
string));
102 for (
auto& provider_and_descrMap :
update.skills)
104 using DescriptionMap = std::map<skills::SkillID, skills::SkillDescription>;
106 DescriptionMap& descriptionMap = provider_and_descrMap.second;
107 skills::ProviderID provider = provider_and_descrMap.first;
109 for (
auto& skill_and_description : descriptionMap)
111 skills::SkillID sid = skill_and_description.first;
112 skills::SkillDescription descr = skill_and_description.second;
114 if (
matches(simox::alg::to_lower(sid.skillName), substrings))
117 filtered.skills[provider][sid] = descr;
126 SkillManagerWrapper::fetchSkillsFromMemory()
135 std::scoped_lock l(mutex_memory);
139 auto managerSkills = memory->ice_invocationTimeout(5000)->getSkillDescriptions();
141 for (
const auto& [sid, desc] : managerSkills)
145 auto providerId = skillId.providerId.value_or(
146 skills::ProviderID{.providerName =
"UNKNOWN PROVIDER NAME"});
150 auto& providedSkillsMap =
skills[providerId];
151 providedSkillsMap.insert({skillId, description});
156 catch (Ice::Exception
const& e)
159 <<
"Unhandled Ice exception encountered while updating skills. Exception was: "
166 ARMARX_WARNING <<
"Unknown exception encountered while updating skills.";
173 skills::manager::dti::SkillManagerInterfacePrx
const& updatedMemory)
175 std::scoped_lock l(mutex_memory);
176 this->
memory = updatedMemory;
184 std::scoped_lock l(mutex_memory);
191 this->currentSkillSearch = search;
207 executions = this->fetchExecutionsFromMemory();
215 for (
auto& [executionId,
status] : executions)
218 if (!
status.hasBeenTerminated())
229 std::scoped_lock l(mutex_snapshot);
231 snapshot.
statuses = fetchExecutionsFromMemory();
232 snapshot.
skills = fetchSkillsFromMemory();
238 const std::optional<ProviderID>
244 ARMARX_WARNING <<
"The memory snapshot was searched for any provider, when a provider "
249 for (
auto& [prov, skillMap] : map)
251 for (
auto& [skill, desc] : skillMap)
253 if (skill == skillId)
265 std::scoped_lock l(mutex_snapshot);
267 Snapshot filtered = filterUpdate(snapshot);
275 std::scoped_lock l(mutex_snapshot);
281 const unsigned int max_retries)
289 unsigned int retries = max_retries;
297 std::scoped_lock l(mutex_memory);
298 this->
memory->ice_invocationTimeout(5000)->abortSkillAsync(executionId.
toManagerIce());
300 catch (Ice::Exception
const& e)
303 ARMARX_ERROR <<
"Unhandeled Ice exception while aborting skill '"
311 ARMARX_ERROR <<
"Unhandled error while aborting skill '"
321 ARMARX_WARNING <<
"There where errors aborting skills. Retrying...";
325 ARMARX_ERROR <<
"Couldn't abort all skills after " << max_retries
326 <<
" tries. Giving up.";
344 if (!providerId.has_value())
347 <<
"' has been requested to be executed, but no provider was "
348 "given. Aborting...";
352 std::map<skills::SkillID, skills::SkillDescription> skillDescriptions;
353 if (this->UPDATE_ON_EXECUTION_REQUEST)
355 skillDescriptions = this->fetchSkillsFromMemory().at(providerId.value());
359 skillDescriptions = this->
getSkills().at(providerId.value());
362 if (skillDescriptions.find(skillId) == skillDescriptions.end())
365 <<
"' has been requested to be executed, but no skill description was "
366 "found. Aborting...";
370 char hostname[HOST_NAME_MAX];
371 gethostname(hostname, HOST_NAME_MAX);
375 .executorName =
"Skills.Manager GUI (hostname: " + std::string(hostname) +
")",
376 .parameters = params};
383 std::scoped_lock l(mutex_memory);
384 memory->ice_invocationTimeout(5000)->executeSkillAsync(req.toManagerIce());
386 catch (Ice::Exception
const& e)
388 ARMARX_ERROR <<
"Unhandeled Ice exception while executing skill '" << skillId.skillName
390 emit
connectionUpdate(
"Execution failed of skill " + skillId.skillName, e.what());
394 ARMARX_ERROR <<
"Unhandled error while executing skill '" << skillId.skillName