FluxioSkill.cpp
Go to the documentation of this file.
1#include "FluxioSkill.h"
2
3#include <memory>
4#include <optional>
5#include <utility>
6#include <vector>
7
12
17#include <RobotAPI/interface/aron/Aron.h>
18#include <RobotAPI/interface/skills/SkillManagerInterface.h>
19#include <RobotAPI/libraries/skills/core/aron/FluxioEdge.aron.generated.h>
20#include <RobotAPI/libraries/skills/core/aron/FluxioNode.aron.generated.h>
21#include <RobotAPI/libraries/skills/core/aron/FluxioParameter.aron.generated.h>
22#include <RobotAPI/libraries/skills/core/aron/FluxioSkill.aron.generated.h>
23
24#include "FluxioControlNode.h"
25#include "FluxioEdge.h"
26#include "FluxioNode.h"
27#include "FluxioParameterNode.h"
28#include "FluxioSubSkillNode.h"
29
30namespace armarx
31{
32 namespace skills
33 {
34 std::optional<manager::dto::FluxioSkill>
36 {
37 if (skillProviderPtr == nullptr)
38 {
39 ARMARX_WARNING << "SkillProvider for Skill with id " << id << " not set";
40 return std::nullopt;
41 }
42
43 manager::dto::FluxioSkill ret;
44
45 ret.id = id;
46 ret.name = name;
47 ret.description = description;
48 ret.lastChanged = lastChanged;
49 ret.executable = executable;
50 ret.native = native;
51 ret.skillProviderId = skillProviderPtr->toFluxioIdentificatorIce();
52
53 skills::manager::dto::FluxioParameterList ret_parameters;
54 for (const auto& [id, parameter] : parameters)
55 {
56 ret_parameters.push_back(parameter.toManagerIce());
57 }
58 ret.parameters = ret_parameters;
59
60 skills::manager::dto::FluxioNodeList ret_nodes;
61 skills::manager::dto::FluxioEdgeList ret_edges;
62 if (native)
63 {
64 ret.nodesHasValue = false;
65 ret.edgesHasValue = false;
66 }
67 else
68 {
69 ret.nodesHasValue = true;
70 ret.edgesHasValue = true;
71
72 for (const auto& [id, nodePtr] : nodes)
73 {
74 const auto& node = nodePtr->toManagerIce();
75
76 if (!node.has_value())
77 {
78 ARMARX_WARNING << "Node with id " << id << " could not be converted";
79 continue;
80 }
81
82 ret_nodes.push_back(node.value());
83 }
84
85 for (const auto& edge : edges)
86 {
87 const auto& edgeDTO = edge.toManagerIce();
88
89 if (!edgeDTO.has_value())
90 {
91 ARMARX_WARNING << "Edge could not be converted";
92 continue;
93 }
94
95 ret_edges.push_back(edgeDTO.value());
96 }
97 }
98 ret.nodes = ret_nodes;
99 ret.edges = ret_edges;
100
102
103 return ret;
104 }
105
106 manager::dto::FluxioIdentificator
108 {
109 manager::dto::FluxioIdentificator ret;
110
111 ret.id = id;
112 ret.hint = name;
113
114 return ret;
115 }
116
117 manager::arondto::FluxioIdentificator
119 {
120 manager::arondto::FluxioIdentificator ret;
121
122 ret.id = id;
123 ret.hint = name;
124
125 return ret;
126 }
127
128 bool
129 FluxioSkill::updateFromIce(const manager::dto::FluxioSkill& i,
130 std::map<std::string, FluxioProvider>& providersMap,
131 std::map<std::string, FluxioProfile>& profilesMap,
132 std::map<std::string, FluxioSkill>& skillsMap,
133 std::map<std::string, aron::type::ObjectPtr>& typesMap)
134 {
135 if (id != i.id)
136 {
137 ARMARX_WARNING << "Trying to update Skill with id " << id << " with Skill with id "
138 << i.id;
139 return false;
140 }
141
142 if (native != i.native)
143 {
144 ARMARX_WARNING << "Trying to update native state of Skill with id " << id;
145 return false;
146 }
147
148 // TODO: add corrupted flag to FluxioSkill to indicate invalid states
149
150 name = i.name;
151 description = i.description;
154 executable = i.executable;
155 const auto skillProviderPtr =
156 skills::FluxioProvider::FromFluxioIdentificatorIce(i.skillProviderId, providersMap);
158
159 // parameters
160 // create a parameter dto map for convenience
161 std::map<std::string, manager::dto::FluxioParameter> parameterDTOMap;
162 for (const auto& parameter : i.parameters)
163 {
164 parameterDTOMap[parameter.id] = parameter;
165 }
166
167 // find parameters to delete
168 std::list<std::string> parameterIdsToDelete;
169 for (const auto& [id, param] : parameters)
170 {
171 const auto& paramIt = parameterDTOMap.find(id);
172 if (paramIt == parameterDTOMap.end())
173 {
174 parameterIdsToDelete.push_back(id);
175 }
176 }
177
178 // handle parameter deletion
179 for (const std::string& paramId : parameterIdsToDelete)
180 {
181 for (auto& [k, s] : skillsMap)
182 {
183 s.deleteParameter(paramId);
184 }
185 }
186
187 for (const auto& [id, paramDTO] : parameterDTOMap)
188 {
189 const auto& paramIt = parameters.find(id);
190 if (paramIt == parameters.end()) // add new parameter
191 {
192 parameters[id] = FluxioParameter::FromIce(paramDTO, profilesMap, typesMap);
193 }
194 else // update existing parameter
195 {
196 parameters[id].updateFromIce(paramDTO, profilesMap, typesMap);
197 }
198 }
199
200 // nodes
201 if (i.nodesHasValue)
202 {
203 nodes.clear(); // create all nodes anew
204 auto controllNodes = std::vector<manager::dto::FluxioNode>();
205 for (const manager::dto::FluxioNode& node : i.nodes)
206 {
207 FluxioNodeType nodeType = FluxioNodeTypeFromString(node.nodeType);
208 if (nodeType == FluxioNodeType::CONTROL)
209 {
210 controllNodes.push_back(node);
211 continue;
212 }
213 auto n = CreateNode(node, parameters, skillsMap, profilesMap, typesMap, nodes);
214
215 if (n != nullptr)
216 {
217 nodes.emplace(n->nodeId, std::move(n));
218 }
219 }
220 for (const manager::dto::FluxioNode& node : controllNodes)
221 {
222 auto n = CreateNode(node, parameters, skillsMap, profilesMap, typesMap, nodes);
223
224 if (n != nullptr)
225 {
226 nodes.emplace(n->nodeId, std::move(n));
227 }
228 }
229 }
230
231 // edges
232 if (i.edgesHasValue)
233 {
234 edges.clear(); // create all edges anew
235 for (const manager::dto::FluxioEdge& edge : i.edges)
236 {
237 const auto& e = FluxioEdge::FromIce(edge, nodes, parameters);
238
239 if (e.has_value())
240 {
241 edges.push_back(e.value());
242 }
243 else
244 {
245 ARMARX_WARNING << "Edge could not be converted";
246 }
247 }
248 }
249
250 return true;
251 }
252
253 bool
255 std::map<std::string, FluxioProvider>& providersMap,
256 std::map<std::string, FluxioProfile>& profilesMap,
257 std::map<std::string, FluxioSkill>& skillsMap,
258 std::map<std::string, aron::type::ObjectPtr>& typesMap)
259 {
260 const aron::data::DictPtr& dict = aron::make_dict(d);
261
262 if (!dict->fullfillsType(manager::arondto::FluxioSkill::ToAronType()))
263 {
264 ARMARX_WARNING << "DictPtr does not fullfill type FluxioSkill";
265 return false;
266 }
267
268 const manager::arondto::FluxioSkill i = manager::arondto::FluxioSkill::FromAron(d);
269
270 if (id != i.id)
271 {
272 ARMARX_WARNING << "Trying to update Skill with id " << id << " with Skill with id "
273 << i.id;
274 return false;
275 }
276
277 if (native != i.native)
278 {
279 ARMARX_WARNING << "Trying to update native state of Skill with id " << id;
280 return false;
281 }
282
283 // TODO: add corrupted flag to FluxioSkill to indicate invalid states
284
285 name = i.name;
286 description = i.description;
287 timeout = i.timeout;
289 executable = i.executable;
291 i.skillProviderId, providersMap);
293
294 // parameters
295 // create a parameter dto map for convenience
296 std::map<std::string, manager::arondto::FluxioParameter> parameterDTOMap;
297 for (const auto& parameter : i.parameters)
298 {
299 parameterDTOMap[parameter.id] = parameter;
300 }
301
302 // find parameters to delete
303 std::list<std::string> parameterIdsToDelete;
304 for (const auto& [id, param] : parameters)
305 {
306 const auto& paramIt = parameterDTOMap.find(id);
307 if (paramIt == parameterDTOMap.end())
308 {
309 parameterIdsToDelete.push_back(id);
310 }
311 }
312
313 // handle parameter deletion
314 for (const std::string& paramId : parameterIdsToDelete)
315 {
316 for (auto& [k, s] : skillsMap)
317 {
318 s.deleteParameter(paramId);
319 }
320 }
321
322 for (const auto& [id, paramDTO] : parameterDTOMap)
323 {
324 const auto& paramIt = parameters.find(id);
325 if (paramIt == parameters.end()) // add new parameter
326 {
327 parameters[id] = FluxioParameter::FromAron(paramDTO, profilesMap, typesMap);
328 }
329 else // update existing parameter
330 {
331 parameters[id].updateFromAron(paramDTO, profilesMap, typesMap);
332 }
333 }
334
335 // nodes
336 if (i.nodesHasValue)
337 {
338 nodes.clear(); // create all nodes anew
339 auto controllNodes = std::vector<manager::arondto::FluxioNode>();
340 for (const manager::arondto::FluxioNode& node : i.nodes)
341 {
342 FluxioNodeType nodeType = FluxioNodeTypeFromString(node.nodeType);
343 if (nodeType == FluxioNodeType::CONTROL)
344 {
345 controllNodes.push_back(node);
346 continue;
347 }
348 auto n = CreateNode(node, parameters, skillsMap, profilesMap, typesMap, nodes);
349
350 if (n != nullptr)
351 {
352 nodes.emplace(n->nodeId, std::move(n));
353 }
354 }
355 for (const manager::arondto::FluxioNode& node : controllNodes)
356 {
357 auto n = CreateNode(node, parameters, skillsMap, profilesMap, typesMap, nodes);
358
359 if (n != nullptr)
360 {
361 nodes.emplace(n->nodeId, std::move(n));
362 }
363 }
364 }
365
366 // edges
367 if (i.edgesHasValue)
368 {
369 edges.clear(); // create all edges anew
370 for (const manager::arondto::FluxioEdge& edge : i.edges)
371 {
372 const auto& e = FluxioEdge::FromAron(edge, nodes, parameters);
373
374 if (e.has_value())
375 {
376 edges.push_back(e.value());
377 }
378 else
379 {
380 ARMARX_WARNING << "Edge could not be converted";
381 }
382 }
383 }
384
385 return true;
386 }
387
388 void
389 FluxioSkill::removeParameterNodesAndEdges(const std::string& parameterId,
390 bool keepParameterNodes)
391 {
392 std::vector<std::string> nodeIdsToDelete = {};
393 for (const auto& [nodeId, nodePtr] : nodes)
394 {
395 if (nodePtr == nullptr)
396 {
397 ARMARX_WARNING << "Unexpected nullptr!";
398 continue;
399 }
400
401 if (nodePtr->nodeType != FluxioNodeType::PARAMETER)
402 {
403 continue;
404 }
405
406 const auto& parameterNodePtr = std::experimental::make_observer(
407 dynamic_cast<const FluxioParameterNode*>(nodePtr.get()));
408 if (parameterNodePtr == nullptr)
409 {
410 ARMARX_WARNING << "Failed to cast node to parameter node";
411 continue;
412 }
413
414 if (parameterNodePtr->parameterPtr == nullptr)
415 {
416 ARMARX_WARNING << "ParameterPtr for ParameterNode is not set";
417 continue;
418 }
419 if (parameterNodePtr->parameterPtr->id == parameterId)
420 {
421 edges.remove_if(
422 [nodeId](const FluxioEdge& e)
423 {
424 return e.fromNodePtr == nullptr || e.toNodePtr == nullptr ||
425 e.fromNodePtr->nodeId == nodeId || e.toNodePtr->nodeId == nodeId;
426 });
427
428 nodeIdsToDelete.push_back(nodeId);
429 }
430 }
431
432 if (!keepParameterNodes)
433 {
434 for (const auto& id : nodeIdsToDelete)
435 {
436 nodes.erase(id);
437 }
438 }
439 }
440
441 void
442 FluxioSkill::deleteParameter(const std::string& parameterId)
443 {
444 removeParameterNodesAndEdges(parameterId, false);
445 parameters.erase(parameterId);
446 }
447
448 void
450 {
451 std::vector<std::string> nodeIdsToDelete = {};
452 for (const auto& [nodeId, nodePtr] : nodes)
453 {
454 if (nodePtr == nullptr)
455 {
456 ARMARX_WARNING << "Unexpected nullptr!";
457 continue;
458 }
459
460 if (nodePtr->nodeType != FluxioNodeType::SUBSKILL)
461 {
462 continue;
463 }
464
465 const auto& subSkillNodePtr = std::experimental::make_observer(
466 dynamic_cast<const FluxioSubSkillNode*>(nodePtr.get()));
467 if (subSkillNodePtr == nullptr)
468 {
469 ARMARX_WARNING << "Failed to cast node to sub skill node";
470 continue;
471 }
472
473 if (subSkillNodePtr->skillPtr == nullptr)
474 {
475 ARMARX_WARNING << "SkillPtr for SubSkillNode is not set";
476 continue;
477 }
478
479 if (subSkillNodePtr->skillPtr->id == skillId)
480 {
481 edges.remove_if(
482 [&nodeId](const FluxioEdge& e) {
483 return e.fromNodePtr->nodeId == nodeId || e.toNodePtr->nodeId == nodeId;
484 });
485
486 nodeIdsToDelete.push_back(nodeId);
487 }
488 }
489
490 for (const auto& id : nodeIdsToDelete)
491 {
492 nodes.erase(id);
493 }
494 }
495
496 void
497 FluxioSkill::removeEdgesConnectedToParameter(const std::string& parameterId)
498 {
499 edges.remove_if(
500 [&parameterId](const FluxioEdge& e)
501 {
502 if (e.fromParameterPtr != nullptr && e.fromParameterPtr->id == parameterId)
503 {
504 return true;
505 }
506
507 if (e.toParameterPtr != nullptr && e.toParameterPtr->id == parameterId)
508 {
509 return true;
510 }
511
512 return false;
513 });
514 }
515
517 FluxioSkill::FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator& i,
518 std::map<std::string, FluxioSkill>& skillsMap)
519 {
520 const auto& skillIt = skillsMap.find(i.id);
521
522 if (skillIt == skillsMap.end())
523 {
524 ARMARX_WARNING << "Skill with id " << i.id << " not found";
525 return nullptr;
526 }
527
528 return std::experimental::make_observer(&skillsMap[skillIt->first]);
529 }
530
532 FluxioSkill::FromFluxioIdentificatorAron(const manager::arondto::FluxioIdentificator& i,
533 std::map<std::string, FluxioSkill>& skillsMap)
534 {
535 const auto& skillIt = skillsMap.find(i.id);
536
537 if (skillIt == skillsMap.end())
538 {
539 ARMARX_WARNING << "Skill with id " << i.id << " not found";
540 return nullptr;
541 }
542
543 return std::experimental::make_observer(&skillsMap[skillIt->first]);
544 }
545
546 std::unique_ptr<FluxioSkill>
547 FluxioSkill::FromIce(const manager::dto::FluxioSkill& i,
548 std::map<std::string, FluxioProvider>& providersMap,
549 std::map<std::string, FluxioProfile>& profilesMap,
550 std::map<std::string, FluxioSkill>& skillsMap,
551 std::map<std::string, aron::type::ObjectPtr>& typesMap)
552 {
553 const auto& providerPtr =
554 FluxioProvider::FromFluxioIdentificatorIce(i.skillProviderId, providersMap);
555 if (providerPtr == nullptr)
556 {
557 ARMARX_WARNING << "Provider for Skill with id " << i.id << " not found";
558 return nullptr;
559 }
560
561 FluxioSkill ret;
562
563 ret.id = i.id;
564 ret.name = i.name;
565 ret.description = i.description;
566 armarx::core::time::fromIce(i.timeout, ret.timeout);
567 ret.lastChanged = i.lastChanged;
568 ret.executable = i.executable;
569 ret.native = i.native;
570 ret.skillProviderPtr = providerPtr;
571 ret.parameters = std::map<std::string, FluxioParameter>();
572 ret.nodes = std::map<const std::string, const std::unique_ptr<FluxioNode>>();
573 ret.edges = std::list<FluxioEdge>();
574
575 for (const manager::dto::FluxioParameter& parameter : i.parameters)
576 {
578 FluxioParameter::FromIce(parameter, profilesMap, typesMap);
579 ret.parameters[param.id] = param;
580 }
581
582 if (i.native)
583 {
584 return std::make_unique<FluxioSkill>(std::move(ret));
585 }
586
587 if (i.nodesHasValue)
588 {
589 auto controllNodes = std::vector<manager::dto::FluxioNode>();
590 for (const manager::dto::FluxioNode& node : i.nodes)
591 {
592 FluxioNodeType nodeType = FluxioNodeTypeFromString(node.nodeType);
593 if (nodeType == FluxioNodeType::CONTROL)
594 {
595 controllNodes.push_back(node);
596 continue;
597 }
598 auto n = CreateNode(
599 node, ret.parameters, skillsMap, profilesMap, typesMap, ret.nodes);
600
601 if (n != nullptr)
602 {
603 ret.nodes.emplace(n->nodeId, std::move(n));
604 }
605 }
606 for (const manager::dto::FluxioNode& node : controllNodes)
607 {
608 auto n = CreateNode(
609 node, ret.parameters, skillsMap, profilesMap, typesMap, ret.nodes);
610
611 if (n != nullptr)
612 {
613 ret.nodes.emplace(n->nodeId, std::move(n));
614 }
615 }
616 }
617
618 if (i.edgesHasValue)
619 {
620 for (const manager::dto::FluxioEdge& edge : i.edges)
621 {
622 const auto& e = FluxioEdge::FromIce(edge, ret.nodes, ret.parameters);
623
624 if (e.has_value())
625 {
626 ret.edges.push_back(e.value());
627 }
628 }
629 }
630
631 return std::make_unique<FluxioSkill>(std::move(ret));
632 }
633
634 std::unique_ptr<FluxioSkill>
636 std::map<std::string, FluxioProvider>& providersMap,
637 std::map<std::string, FluxioProfile>& profilesMap,
638 std::map<std::string, FluxioSkill>& skillsMap,
639 std::map<std::string, aron::type::ObjectPtr>& typesMap)
640 {
641 const aron::data::DictPtr dict = aron::make_dict(d);
642 if (!dict->fullfillsType(manager::arondto::FluxioSkill::ToAronType()))
643 {
644 ARMARX_WARNING << "DictPtr does not fullfill type FluxioSkill";
645 return nullptr;
646 }
647
648 const manager::arondto::FluxioSkill i = manager::arondto::FluxioSkill::FromAron(d);
649
650 const auto& providerPtr =
651 FluxioProvider::FromFluxioIdentificatorAron(i.skillProviderId, providersMap);
652
653 if (providerPtr == nullptr)
654 {
655 ARMARX_WARNING << "Provider for Skill with id " << i.id << " not found";
656 return nullptr;
657 }
658
659 FluxioSkill ret;
660
661 ret.id = i.id;
662 ret.name = i.name;
663 ret.description = i.description;
664 ret.timeout = i.timeout;
665 ret.lastChanged = i.lastChanged;
666 ret.executable = i.executable;
667 ret.native = i.native;
668 ret.skillProviderPtr = providerPtr;
669 ret.parameters = std::map<std::string, FluxioParameter>();
670 ret.nodes = std::map<const std::string, const std::unique_ptr<FluxioNode>>();
671 ret.edges = std::list<FluxioEdge>();
672
673 for (const manager::arondto::FluxioParameter& parameter : i.parameters)
674 {
676 FluxioParameter::FromAron(parameter, profilesMap, typesMap);
677 ret.parameters[param.id] = param;
678 }
679
680 if (i.native)
681 {
682 return std::make_unique<FluxioSkill>(std::move(ret));
683 }
684
685 if (i.nodesHasValue)
686 {
687 auto controllNodes = std::vector<manager::arondto::FluxioNode>();
688 for (const manager::arondto::FluxioNode& node : i.nodes)
689 {
690 FluxioNodeType nodeType = FluxioNodeTypeFromString(node.nodeType);
691 if (nodeType == FluxioNodeType::CONTROL)
692 {
693 controllNodes.push_back(node);
694 continue;
695 }
696 auto n = CreateNode(
697 node, ret.parameters, skillsMap, profilesMap, typesMap, ret.nodes);
698
699 if (n != nullptr)
700 {
701 ret.nodes.emplace(n->nodeId, std::move(n));
702 }
703 }
704 for (const manager::arondto::FluxioNode& node : i.nodes)
705 {
706 auto n = CreateNode(
707 node, ret.parameters, skillsMap, profilesMap, typesMap, ret.nodes);
708
709 if (n != nullptr)
710 {
711 ret.nodes.emplace(n->nodeId, std::move(n));
712 }
713 }
714 }
715
716 if (i.edgesHasValue)
717 {
718 for (const manager::arondto::FluxioEdge& edge : i.edges)
719 {
720 const auto& e = FluxioEdge::FromAron(edge, ret.nodes, ret.parameters);
721
722 if (e.has_value())
723 {
724 ret.edges.push_back(e.value());
725 }
726 }
727 }
728
729 return std::make_unique<FluxioSkill>(std::move(ret));
730 }
731
732 std::unique_ptr<FluxioNode>
734 const manager::dto::FluxioNode& i,
735 std::map<std::string, FluxioParameter>& parametersMap,
736 std::map<std::string, FluxioSkill>& skillsMap,
737 std::map<std::string, FluxioProfile>& profilesMap,
738 std::map<std::string, aron::type::ObjectPtr>& typesMap,
739 std::map<const std::string, const std::unique_ptr<FluxioNode>>& nodesMap)
740 {
741 FluxioNodeType nodeType = FluxioNodeTypeFromString(i.nodeType);
742
743 if (nodeType == FluxioNodeType::PARAMETER)
744 {
745 const auto& n = FluxioParameterNode::FromIce(i, parametersMap);
746
747 if (n.has_value())
748 {
749 return std::make_unique<FluxioParameterNode>(n.value());
750 }
751
752 ARMARX_WARNING << "ParameterNode with id " << i.nodeId << " could not be converted";
753 }
754 else if (nodeType == FluxioNodeType::SUBSKILL)
755 {
756 const auto& n = FluxioSubSkillNode::FromIce(i, skillsMap);
757
758 if (n.has_value())
759 {
760 return std::make_unique<FluxioSubSkillNode>(n.value());
761 }
762 ARMARX_WARNING << "SubSkillNode with id " << i.nodeId << " could not be converted";
763 }
764 else if (nodeType == FluxioNodeType::CONTROL)
765 {
766 const auto& n = FluxioControlNode::FromIce(i, profilesMap, typesMap, nodesMap);
767
768 if (n.has_value())
769 {
770 return std::make_unique<FluxioControlNode>(n.value());
771 }
772 ARMARX_WARNING << "controlNode with id " << i.nodeId << " could not be converted";
773 }
774 else if (nodeType == FluxioNodeType::UNKNOWN)
775 {
776 ARMARX_WARNING << "Node with id " << i.nodeId << " has unknown type";
777 }
778 else
779 {
780 ARMARX_INFO << "Node type " << i.nodeType << " not supported yet. Ignoring.";
781 }
782
783 return nullptr;
784 }
785
786 std::unique_ptr<FluxioNode>
788 const manager::arondto::FluxioNode& i,
789 std::map<std::string, FluxioParameter>& parametersMap,
790 std::map<std::string, FluxioSkill>& skillsMap,
791 std::map<std::string, FluxioProfile>& profilesMap,
792 std::map<std::string, aron::type::ObjectPtr>& typesMap,
793 std::map<const std::string, const std::unique_ptr<FluxioNode>>& nodesMap)
794 {
795 FluxioNodeType nodeType = FluxioNodeTypeFromString(i.nodeType);
796
797 if (nodeType == FluxioNodeType::PARAMETER)
798 {
799 const auto& n = FluxioParameterNode::FromAron(i, parametersMap);
800
801 if (n.has_value())
802 {
803 return std::make_unique<FluxioParameterNode>(n.value());
804 }
805
806 ARMARX_WARNING << "ParameterNode with id " << i.nodeId << " could not be converted";
807 }
808 else if (nodeType == FluxioNodeType::SUBSKILL)
809 {
810 const auto& n = FluxioSubSkillNode::FromAron(i, skillsMap);
811
812 if (n.has_value())
813 {
814 return std::make_unique<FluxioSubSkillNode>(n.value());
815 }
816 ARMARX_WARNING << "SubSkillNode with id " << i.nodeId << " could not be converted";
817 }
818 else if (nodeType == FluxioNodeType::CONTROL)
819 {
820 const auto& n = FluxioControlNode::FromAron(i, profilesMap, typesMap, nodesMap);
821
822 if (n.has_value())
823 {
824 return std::make_unique<FluxioControlNode>(n.value());
825 }
826 ARMARX_WARNING << "controlNode with id " << i.nodeId << " could not be converted";
827 }
828 else if (nodeType == FluxioNodeType::UNKNOWN)
829 {
830 ARMARX_WARNING << "Node with id " << i.nodeId << " has unknown type";
831 }
832 else
833 {
834 ARMARX_INFO << "Node type " << i.nodeType << " not supported yet. Ignoring.";
835 }
836
837 return nullptr;
838 }
839
840 std::optional<manager::arondto::FluxioSkill>
842 {
843 if (skillProviderPtr == nullptr)
844 {
845 ARMARX_WARNING << "SkillProvider for Skill with id " << id << " not set";
846 return std::nullopt;
847 }
848
849 manager::arondto::FluxioSkill ret;
850
851 ret.id = id;
852 ret.name = name;
853 ret.description = description;
854 ret.lastChanged = lastChanged;
855 ret.executable = executable;
856 ret.native = native;
857 ret.skillProviderId = skillProviderPtr->toFluxioIdentificatorAron();
858
859 std::vector<manager::arondto::FluxioParameter> ret_parameters;
860 ret_parameters.reserve(parameters.size());
861 for (const auto& [id, parameter] : parameters)
862 {
863 ret_parameters.push_back(parameter.toAron());
864 }
865 ret.parameters = ret_parameters;
866
867 std::vector<manager::arondto::FluxioNode> ret_nodes;
868 std::vector<manager::arondto::FluxioEdge> ret_edges;
869 if (native)
870 {
871 ret.nodesHasValue = false;
872 ret.edgesHasValue = false;
873 }
874 else
875 {
876 ret.nodesHasValue = true;
877 ret.edgesHasValue = true;
878
879 for (const auto& [id, nodePtr] : nodes)
880 {
881 const auto& node = nodePtr->toAron();
882
883 if (!node.has_value())
884 {
885 ARMARX_WARNING << "Node with id " << id << " could not be converted";
886 continue;
887 }
888
889 ret_nodes.push_back(node.value());
890 }
891
892 for (const auto& edge : edges)
893 {
894 const auto& edgeDTO = edge.toAron();
895
896 if (!edgeDTO.has_value())
897 {
898 ARMARX_WARNING << "Edge could not be converted";
899 continue;
900 }
901
902 ret_edges.push_back(edgeDTO.value());
903 }
904 }
905 ret.nodes = ret_nodes;
906 ret.edges = ret_edges;
907
908 ret.timeout = timeout;
909
910 return ret;
911 }
912
913 std::optional<aron::data::dto::DictPtr>
915 {
916 const std::optional<manager::arondto::FluxioSkill> ret = toAronXml();
917 if (!ret.has_value())
918 {
919 return std::nullopt;
920 }
921
922 return toAronXml()->toAronDTO();
923 }
924
925 } // namespace skills
926} // namespace armarx
static DateTime Now()
Definition DateTime.cpp:51
std::string toDateTimeString() const
Definition DateTime.cpp:75
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
::IceInternal::Handle< Dict > DictPtr
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
aron::data::DictPtr make_dict(_Args &&... args)
Definition Dict.h:107
void toIce(dto::ClockType::ClockTypeEnum &dto, const ClockType &bo)
void fromIce(const dto::ClockType::ClockTypeEnum &dto, ClockType &bo)
This file is part of ArmarX.
FluxioNodeType FluxioNodeTypeFromString(const std::string &type)
This file offers overloads of toIce() and fromIce() functions for STL container types.
observer_ptr< _Tp > make_observer(_Tp *__p) noexcept
static std::optional< FluxioControlNode > FromIce(const manager::dto::FluxioNode &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap, std::map< const std::string, const std::unique_ptr< FluxioNode > > &nodesMap)
static std::optional< FluxioControlNode > FromAron(const manager::arondto::FluxioNode &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap, std::map< const std::string, const std::unique_ptr< FluxioNode > > &nodesMap)
std::experimental::observer_ptr< const FluxioParameter > fromParameterPtr
Definition FluxioEdge.h:18
static std::optional< FluxioEdge > FromAron(const manager::arondto::FluxioEdge &i, const std::map< const std::string, const std::unique_ptr< FluxioNode > > &nodesMap, const std::map< std::string, FluxioParameter > &parametersMap)
static std::optional< FluxioEdge > FromIce(const manager::dto::FluxioEdge &i, const std::map< const std::string, const std::unique_ptr< FluxioNode > > &nodesMap, const std::map< std::string, FluxioParameter > &parametersMap)
std::experimental::observer_ptr< const FluxioParameter > toParameterPtr
Definition FluxioEdge.h:20
std::experimental::observer_ptr< const FluxioNode > fromNodePtr
Definition FluxioEdge.h:17
std::experimental::observer_ptr< const FluxioNode > toNodePtr
Definition FluxioEdge.h:19
static std::optional< FluxioParameterNode > FromIce(const manager::dto::FluxioNode &i, std::map< std::string, FluxioParameter > &parametersMap)
static std::optional< FluxioParameterNode > FromAron(const manager::arondto::FluxioNode &i, std::map< std::string, FluxioParameter > &parametersMap)
static FluxioParameter FromIce(const manager::dto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
static FluxioParameter FromAron(const manager::arondto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
static std::experimental::observer_ptr< const FluxioProvider > FromFluxioIdentificatorAron(const manager::arondto::FluxioIdentificator &i, std::map< std::string, FluxioProvider > &providersMap)
static std::experimental::observer_ptr< const FluxioProvider > FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator &i, std::map< std::string, FluxioProvider > &providersMap)
manager::arondto::FluxioIdentificator toFluxioIdentificatorAron() const
FluxioSkill(const FluxioSkill &)=delete
void deleteParameter(const std::string &parameterId)
bool updateFromAron(const aron::data::dto::DictPtr &i, std::map< std::string, FluxioProvider > &providersMap, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, FluxioSkill > &skillsMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
armarx::Duration timeout
How long (in ms) to wait for the skill to finish execution before timing out.
Definition FluxioSkill.h:33
static std::unique_ptr< FluxioSkill > FromIce(const manager::dto::FluxioSkill &i, std::map< std::string, FluxioProvider > &providersMap, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, FluxioSkill > &skillsMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
static std::unique_ptr< FluxioSkill > FromAron(const aron::data::dto::DictPtr &d, std::map< std::string, FluxioProvider > &providersMap, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, FluxioSkill > &skillsMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
std::optional< manager::arondto::FluxioSkill > toAronXml() const
std::map< std::string, FluxioParameter > parameters
Definition FluxioSkill.h:39
std::list< FluxioEdge > edges
Definition FluxioSkill.h:41
void removeEdgesConnectedToParameter(const std::string &parameterId)
bool updateFromIce(const manager::dto::FluxioSkill &i, std::map< std::string, FluxioProvider > &providersMap, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, FluxioSkill > &skillsMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
std::map< const std::string, const std::unique_ptr< FluxioNode > > nodes
Definition FluxioSkill.h:40
static std::experimental::observer_ptr< const FluxioSkill > FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator &i, std::map< std::string, FluxioSkill > &skillsMap)
std::optional< aron::data::dto::DictPtr > toAronDTO() const
void removeSubSkillNodesAndEdges(const std::string &skillId)
static std::experimental::observer_ptr< const FluxioSkill > FromFluxioIdentificatorAron(const manager::arondto::FluxioIdentificator &i, std::map< std::string, FluxioSkill > &skillsMap)
std::optional< manager::dto::FluxioSkill > toManagerIce() const
manager::dto::FluxioIdentificator toFluxioIdentificatorIce() const
static std::unique_ptr< skills::FluxioNode > CreateNode(const manager::dto::FluxioNode &i, std::map< std::string, FluxioParameter > &parametersMap, std::map< std::string, FluxioSkill > &skillsMap, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap, std::map< const std::string, const std::unique_ptr< FluxioNode > > &nodesMap)
void removeParameterNodesAndEdges(const std::string &parameterId, bool keepParameterNodes=false)
std::experimental::observer_ptr< const FluxioProvider > skillProviderPtr
Definition FluxioSkill.h:38
static std::optional< FluxioSubSkillNode > FromIce(const manager::dto::FluxioNode &i, std::map< std::string, FluxioSkill > &skillsMap)
static std::optional< FluxioSubSkillNode > FromAron(const manager::arondto::FluxioNode &i, std::map< std::string, FluxioSkill > &skillsMap)