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 
30 namespace 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  for (const manager::dto::FluxioNode& node : i.nodes)
205  {
206  auto n = CreateNode(node, parameters, skillsMap, profilesMap, typesMap);
207 
208  if (n != nullptr)
209  {
210  nodes.emplace(n->nodeId, std::move(n));
211  }
212  }
213  }
214 
215  // edges
216  if (i.edgesHasValue)
217  {
218  edges.clear(); // create all edges anew
219  for (const manager::dto::FluxioEdge& edge : i.edges)
220  {
221  const auto& e = FluxioEdge::FromIce(edge, nodes, parameters);
222 
223  if (e.has_value())
224  {
225  edges.push_back(e.value());
226  }
227  else
228  {
229  ARMARX_WARNING << "Edge could not be converted";
230  }
231  }
232  }
233 
234  return true;
235  }
236 
237  bool
239  std::map<std::string, FluxioProvider>& providersMap,
240  std::map<std::string, FluxioProfile>& profilesMap,
241  std::map<std::string, FluxioSkill>& skillsMap,
242  std::map<std::string, aron::type::ObjectPtr>& typesMap)
243  {
244  const aron::data::DictPtr& dict = aron::make_dict(d);
245 
246  if (!dict->fullfillsType(manager::arondto::FluxioSkill::ToAronType()))
247  {
248  ARMARX_WARNING << "DictPtr does not fullfill type FluxioSkill";
249  return false;
250  }
251 
252  const manager::arondto::FluxioSkill i = manager::arondto::FluxioSkill::FromAron(d);
253 
254  if (id != i.id)
255  {
256  ARMARX_WARNING << "Trying to update Skill with id " << id << " with Skill with id "
257  << i.id;
258  return false;
259  }
260 
261  if (native != i.native)
262  {
263  ARMARX_WARNING << "Trying to update native state of Skill with id " << id;
264  return false;
265  }
266 
267  // TODO: add corrupted flag to FluxioSkill to indicate invalid states
268 
269  name = i.name;
270  description = i.description;
271  timeout = i.timeout;
273  executable = i.executable;
275  i.skillProviderId, providersMap);
277 
278  // parameters
279  // create a parameter dto map for convenience
280  std::map<std::string, manager::arondto::FluxioParameter> parameterDTOMap;
281  for (const auto& parameter : i.parameters)
282  {
283  parameterDTOMap[parameter.id] = parameter;
284  }
285 
286  // find parameters to delete
287  std::list<std::string> parameterIdsToDelete;
288  for (const auto& [id, param] : parameters)
289  {
290  const auto& paramIt = parameterDTOMap.find(id);
291  if (paramIt == parameterDTOMap.end())
292  {
293  parameterIdsToDelete.push_back(id);
294  }
295  }
296 
297  // handle parameter deletion
298  for (const std::string& paramId : parameterIdsToDelete)
299  {
300  for (auto& [k, s] : skillsMap)
301  {
302  s.deleteParameter(paramId);
303  }
304  }
305 
306  for (const auto& [id, paramDTO] : parameterDTOMap)
307  {
308  const auto& paramIt = parameters.find(id);
309  if (paramIt == parameters.end()) // add new parameter
310  {
311  parameters[id] = FluxioParameter::FromAron(paramDTO, profilesMap, typesMap);
312  }
313  else // update existing parameter
314  {
315  parameters[id].updateFromAron(paramDTO, profilesMap, typesMap);
316  }
317  }
318 
319  // nodes
320  if (i.nodesHasValue)
321  {
322  nodes.clear(); // create all nodes anew
323  for (const manager::arondto::FluxioNode& node : i.nodes)
324  {
325  auto n = CreateNode(node, parameters, skillsMap, profilesMap, typesMap);
326 
327  if (n != nullptr)
328  {
329  nodes.emplace(n->nodeId, std::move(n));
330  }
331  }
332  }
333 
334  // edges
335  if (i.edgesHasValue)
336  {
337  edges.clear(); // create all edges anew
338  for (const manager::arondto::FluxioEdge& edge : i.edges)
339  {
340  const auto& e = FluxioEdge::FromAron(edge, nodes, parameters);
341 
342  if (e.has_value())
343  {
344  edges.push_back(e.value());
345  }
346  else
347  {
348  ARMARX_WARNING << "Edge could not be converted";
349  }
350  }
351  }
352 
353  return true;
354  }
355 
356  void
357  FluxioSkill::removeParameterNodesAndEdges(const std::string& parameterId,
358  bool keepParameterNodes)
359  {
360  std::vector<std::string> nodeIdsToDelete = {};
361  for (const auto& [nodeId, nodePtr] : nodes)
362  {
363  if (nodePtr == nullptr)
364  {
365  ARMARX_WARNING << "Unexpected nullptr!";
366  continue;
367  }
368 
369  if (nodePtr->nodeType != FluxioNodeType::PARAMETER)
370  {
371  continue;
372  }
373 
374  const auto& parameterNodePtr = std::experimental::make_observer(
375  dynamic_cast<const FluxioParameterNode*>(nodePtr.get()));
376  if (parameterNodePtr == nullptr)
377  {
378  ARMARX_WARNING << "Failed to cast node to parameter node";
379  continue;
380  }
381 
382  if (parameterNodePtr->parameterPtr == nullptr)
383  {
384  ARMARX_WARNING << "ParameterPtr for ParameterNode is not set";
385  continue;
386  }
387  if (parameterNodePtr->parameterPtr->id == parameterId)
388  {
389  edges.remove_if(
390  [nodeId](const FluxioEdge& e)
391  {
392  return e.fromNodePtr == nullptr || e.toNodePtr == nullptr ||
393  e.fromNodePtr->nodeId == nodeId || e.toNodePtr->nodeId == nodeId;
394  });
395 
396  nodeIdsToDelete.push_back(nodeId);
397  }
398  }
399 
400  if (!keepParameterNodes)
401  {
402  for (const auto& id : nodeIdsToDelete)
403  {
404  nodes.erase(id);
405  }
406  }
407  }
408 
409  void
410  FluxioSkill::deleteParameter(const std::string& parameterId)
411  {
412  removeParameterNodesAndEdges(parameterId, false);
413  parameters.erase(parameterId);
414  }
415 
416  void
417  FluxioSkill::removeSubSkillNodesAndEdges(const std::string& skillId)
418  {
419  std::vector<std::string> nodeIdsToDelete = {};
420  for (const auto& [nodeId, nodePtr] : nodes)
421  {
422  if (nodePtr == nullptr)
423  {
424  ARMARX_WARNING << "Unexpected nullptr!";
425  continue;
426  }
427 
428  if (nodePtr->nodeType != FluxioNodeType::SUBSKILL)
429  {
430  continue;
431  }
432 
433  const auto& subSkillNodePtr = std::experimental::make_observer(
434  dynamic_cast<const FluxioSubSkillNode*>(nodePtr.get()));
435  if (subSkillNodePtr == nullptr)
436  {
437  ARMARX_WARNING << "Failed to cast node to sub skill node";
438  continue;
439  }
440 
441  if (subSkillNodePtr->skillPtr == nullptr)
442  {
443  ARMARX_WARNING << "SkillPtr for SubSkillNode is not set";
444  continue;
445  }
446 
447  if (subSkillNodePtr->skillPtr->id == skillId)
448  {
449  edges.remove_if(
450  [&nodeId](const FluxioEdge& e) {
451  return e.fromNodePtr->nodeId == nodeId || e.toNodePtr->nodeId == nodeId;
452  });
453 
454  nodeIdsToDelete.push_back(nodeId);
455  }
456  }
457 
458  for (const auto& id : nodeIdsToDelete)
459  {
460  nodes.erase(id);
461  }
462  }
463 
464  void
465  FluxioSkill::removeEdgesConnectedToParameter(const std::string& parameterId)
466  {
467  edges.remove_if(
468  [&parameterId](const FluxioEdge& e)
469  {
470  if (e.fromParameterPtr != nullptr && e.fromParameterPtr->id == parameterId)
471  {
472  return true;
473  }
474 
475  if (e.toParameterPtr != nullptr && e.toParameterPtr->id == parameterId)
476  {
477  return true;
478  }
479 
480  return false;
481  });
482  }
483 
485  FluxioSkill::FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator& i,
486  std::map<std::string, FluxioSkill>& skillsMap)
487  {
488  const auto& skillIt = skillsMap.find(i.id);
489 
490  if (skillIt == skillsMap.end())
491  {
492  ARMARX_WARNING << "Skill with id " << i.id << " not found";
493  return nullptr;
494  }
495 
496  return std::experimental::make_observer(&skillsMap[skillIt->first]);
497  }
498 
500  FluxioSkill::FromFluxioIdentificatorAron(const manager::arondto::FluxioIdentificator& i,
501  std::map<std::string, FluxioSkill>& skillsMap)
502  {
503  const auto& skillIt = skillsMap.find(i.id);
504 
505  if (skillIt == skillsMap.end())
506  {
507  ARMARX_WARNING << "Skill with id " << i.id << " not found";
508  return nullptr;
509  }
510 
511  return std::experimental::make_observer(&skillsMap[skillIt->first]);
512  }
513 
514  std::unique_ptr<FluxioSkill>
515  FluxioSkill::FromIce(const manager::dto::FluxioSkill& i,
516  std::map<std::string, FluxioProvider>& providersMap,
517  std::map<std::string, FluxioProfile>& profilesMap,
518  std::map<std::string, FluxioSkill>& skillsMap,
519  std::map<std::string, aron::type::ObjectPtr>& typesMap)
520  {
521  const auto& providerPtr =
522  FluxioProvider::FromFluxioIdentificatorIce(i.skillProviderId, providersMap);
523  if (providerPtr == nullptr)
524  {
525  ARMARX_WARNING << "Provider for Skill with id " << i.id << " not found";
526  return nullptr;
527  }
528 
530 
531  ret.id = i.id;
532  ret.name = i.name;
533  ret.description = i.description;
534  armarx::core::time::fromIce(i.timeout, ret.timeout);
535  ret.lastChanged = i.lastChanged;
536  ret.executable = i.executable;
537  ret.native = i.native;
538  ret.skillProviderPtr = providerPtr;
539  ret.parameters = std::map<std::string, FluxioParameter>();
540  ret.nodes = std::map<const std::string, const std::unique_ptr<FluxioNode>>();
541  ret.edges = std::list<FluxioEdge>();
542 
543  for (const manager::dto::FluxioParameter& parameter : i.parameters)
544  {
546  FluxioParameter::FromIce(parameter, profilesMap, typesMap);
547  ret.parameters[param.id] = param;
548  }
549 
550  if (i.native)
551  {
552  return std::make_unique<FluxioSkill>(std::move(ret));
553  }
554 
555  if (i.nodesHasValue)
556  {
557  for (const manager::dto::FluxioNode& node : i.nodes)
558  {
559  auto n = CreateNode(node, ret.parameters, skillsMap, profilesMap, typesMap);
560 
561  if (n != nullptr)
562  {
563  ret.nodes.emplace(n->nodeId, std::move(n));
564  }
565  }
566  }
567 
568  if (i.edgesHasValue)
569  {
570  for (const manager::dto::FluxioEdge& edge : i.edges)
571  {
572  const auto& e = FluxioEdge::FromIce(edge, ret.nodes, ret.parameters);
573 
574  if (e.has_value())
575  {
576  ret.edges.push_back(e.value());
577  }
578  }
579  }
580 
581  return std::make_unique<FluxioSkill>(std::move(ret));
582  }
583 
584  std::unique_ptr<FluxioSkill>
586  std::map<std::string, FluxioProvider>& providersMap,
587  std::map<std::string, FluxioProfile>& profilesMap,
588  std::map<std::string, FluxioSkill>& skillsMap,
589  std::map<std::string, aron::type::ObjectPtr>& typesMap)
590  {
591  const aron::data::DictPtr dict = aron::make_dict(d);
592  if (!dict->fullfillsType(manager::arondto::FluxioSkill::ToAronType()))
593  {
594  ARMARX_WARNING << "DictPtr does not fullfill type FluxioSkill";
595  return nullptr;
596  }
597 
598  const manager::arondto::FluxioSkill i = manager::arondto::FluxioSkill::FromAron(d);
599 
600  const auto& providerPtr =
601  FluxioProvider::FromFluxioIdentificatorAron(i.skillProviderId, providersMap);
602 
603  if (providerPtr == nullptr)
604  {
605  ARMARX_WARNING << "Provider for Skill with id " << i.id << " not found";
606  return nullptr;
607  }
608 
610 
611  ret.id = i.id;
612  ret.name = i.name;
613  ret.description = i.description;
614  ret.timeout = i.timeout;
615  ret.lastChanged = i.lastChanged;
616  ret.executable = i.executable;
617  ret.native = i.native;
618  ret.skillProviderPtr = providerPtr;
619  ret.parameters = std::map<std::string, FluxioParameter>();
620  ret.nodes = std::map<const std::string, const std::unique_ptr<FluxioNode>>();
621  ret.edges = std::list<FluxioEdge>();
622 
623  for (const manager::arondto::FluxioParameter& parameter : i.parameters)
624  {
626  FluxioParameter::FromAron(parameter, profilesMap, typesMap);
627  ret.parameters[param.id] = param;
628  }
629 
630  if (i.native)
631  {
632  return std::make_unique<FluxioSkill>(std::move(ret));
633  }
634 
635  if (i.nodesHasValue)
636  {
637  for (const manager::arondto::FluxioNode& node : i.nodes)
638  {
639  auto n = CreateNode(node, ret.parameters, skillsMap, profilesMap, typesMap);
640 
641  if (n != nullptr)
642  {
643  ret.nodes.emplace(n->nodeId, std::move(n));
644  }
645  }
646  }
647 
648  if (i.edgesHasValue)
649  {
650  for (const manager::arondto::FluxioEdge& edge : i.edges)
651  {
652  const auto& e = FluxioEdge::FromAron(edge, ret.nodes, ret.parameters);
653 
654  if (e.has_value())
655  {
656  ret.edges.push_back(e.value());
657  }
658  }
659  }
660 
661  return std::make_unique<FluxioSkill>(std::move(ret));
662  }
663 
664  std::unique_ptr<FluxioNode>
665  FluxioSkill::CreateNode(const manager::dto::FluxioNode& i,
666  std::map<std::string, FluxioParameter>& parametersMap,
667  std::map<std::string, FluxioSkill>& skillsMap,
668  std::map<std::string, FluxioProfile>& profilesMap,
669  std::map<std::string, aron::type::ObjectPtr>& typesMap)
670  {
671  FluxioNodeType nodeType = FluxioNodeTypeFromString(i.nodeType);
672 
673  if (nodeType == FluxioNodeType::PARAMETER)
674  {
675  const auto& n = FluxioParameterNode::FromIce(i, parametersMap);
676 
677  if (n.has_value())
678  {
679  return std::make_unique<FluxioParameterNode>(n.value());
680  }
681 
682  ARMARX_WARNING << "ParameterNode with id " << i.nodeId << " could not be converted";
683  }
684  else if (nodeType == FluxioNodeType::SUBSKILL)
685  {
686  const auto& n = FluxioSubSkillNode::FromIce(i, skillsMap);
687 
688  if (n.has_value())
689  {
690  return std::make_unique<FluxioSubSkillNode>(n.value());
691  }
692  ARMARX_WARNING << "SubSkillNode with id " << i.nodeId << " could not be converted";
693  }
694  else if (nodeType == FluxioNodeType::CONTROL)
695  {
696  const auto& n = FluxioControlNode::FromIce(i, profilesMap, typesMap);
697 
698  if (n.has_value())
699  {
700  return std::make_unique<FluxioControlNode>(n.value());
701  }
702  ARMARX_WARNING << "controlNode with id " << i.nodeId << " could not be converted";
703  }
704  else if (nodeType == FluxioNodeType::UNKNOWN)
705  {
706  ARMARX_WARNING << "Node with id " << i.nodeId << " has unknown type";
707  }
708  else
709  {
710  ARMARX_INFO << "Node type " << i.nodeType << " not supported yet. Ignoring.";
711  }
712 
713  return nullptr;
714  }
715 
716  std::unique_ptr<FluxioNode>
717  FluxioSkill::CreateNode(const manager::arondto::FluxioNode& i,
718  std::map<std::string, FluxioParameter>& parametersMap,
719  std::map<std::string, FluxioSkill>& skillsMap,
720  std::map<std::string, FluxioProfile>& profilesMap,
721  std::map<std::string, aron::type::ObjectPtr>& typesMap)
722  {
723  FluxioNodeType nodeType = FluxioNodeTypeFromString(i.nodeType);
724 
725  if (nodeType == FluxioNodeType::PARAMETER)
726  {
727  const auto& n = FluxioParameterNode::FromAron(i, parametersMap);
728 
729  if (n.has_value())
730  {
731  return std::make_unique<FluxioParameterNode>(n.value());
732  }
733 
734  ARMARX_WARNING << "ParameterNode with id " << i.nodeId << " could not be converted";
735  }
736  else if (nodeType == FluxioNodeType::SUBSKILL)
737  {
738  const auto& n = FluxioSubSkillNode::FromAron(i, skillsMap);
739 
740  if (n.has_value())
741  {
742  return std::make_unique<FluxioSubSkillNode>(n.value());
743  }
744  ARMARX_WARNING << "SubSkillNode with id " << i.nodeId << " could not be converted";
745  }
746  else if (nodeType == FluxioNodeType::CONTROL)
747  {
748  const auto& n = FluxioControlNode::FromAron(i, profilesMap, typesMap);
749 
750  if (n.has_value())
751  {
752  return std::make_unique<FluxioControlNode>(n.value());
753  }
754  ARMARX_WARNING << "controlNode with id " << i.nodeId << " could not be converted";
755  }
756  else if (nodeType == FluxioNodeType::UNKNOWN)
757  {
758  ARMARX_WARNING << "Node with id " << i.nodeId << " has unknown type";
759  }
760  else
761  {
762  ARMARX_INFO << "Node type " << i.nodeType << " not supported yet. Ignoring.";
763  }
764 
765  return nullptr;
766  }
767 
768  std::optional<manager::arondto::FluxioSkill>
770  {
771  if (skillProviderPtr == nullptr)
772  {
773  ARMARX_WARNING << "SkillProvider for Skill with id " << id << " not set";
774  return std::nullopt;
775  }
776 
777  manager::arondto::FluxioSkill ret;
778 
779  ret.id = id;
780  ret.name = name;
781  ret.description = description;
782  ret.lastChanged = lastChanged;
783  ret.executable = executable;
784  ret.native = native;
785  ret.skillProviderId = skillProviderPtr->toFluxioIdentificatorAron();
786 
787  std::vector<manager::arondto::FluxioParameter> ret_parameters;
788  ret_parameters.reserve(parameters.size());
789  for (const auto& [id, parameter] : parameters)
790  {
791  ret_parameters.push_back(parameter.toAron());
792  }
793  ret.parameters = ret_parameters;
794 
795  std::vector<manager::arondto::FluxioNode> ret_nodes;
796  std::vector<manager::arondto::FluxioEdge> ret_edges;
797  if (native)
798  {
799  ret.nodesHasValue = false;
800  ret.edgesHasValue = false;
801  }
802  else
803  {
804  ret.nodesHasValue = true;
805  ret.edgesHasValue = true;
806 
807  for (const auto& [id, nodePtr] : nodes)
808  {
809  const auto& node = nodePtr->toAron();
810 
811  if (!node.has_value())
812  {
813  ARMARX_WARNING << "Node with id " << id << " could not be converted";
814  continue;
815  }
816 
817  ret_nodes.push_back(node.value());
818  }
819 
820  for (const auto& edge : edges)
821  {
822  const auto& edgeDTO = edge.toAron();
823 
824  if (!edgeDTO.has_value())
825  {
826  ARMARX_WARNING << "Edge could not be converted";
827  continue;
828  }
829 
830  ret_edges.push_back(edgeDTO.value());
831  }
832  }
833  ret.nodes = ret_nodes;
834  ret.edges = ret_edges;
835 
836  ret.timeout = timeout;
837 
838  return ret;
839  }
840 
841  std::optional<aron::data::dto::DictPtr>
843  {
844  const std::optional<manager::arondto::FluxioSkill> ret = toAronXml();
845  if (!ret.has_value())
846  {
847  return std::nullopt;
848  }
849 
850  return toAronXml()->toAronDTO();
851  }
852 
853  } // namespace skills
854 } // namespace armarx
armarx::skills::FluxioSkill::description
std::string description
Definition: FluxioSkill.h:29
armarx::skills::FluxioSkill
Definition: FluxioSkill.h:25
armarx::skills::FluxioEdge
Definition: FluxioEdge.h:15
armarx::skills::FluxioSkill::nodes
std::map< const std::string, const std::unique_ptr< FluxioNode > > nodes
Definition: FluxioSkill.h:40
armarx::skills::FluxioParameter
Definition: FluxioParameter.h:23
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:13
skills
This file is part of ArmarX.
armarx::skills::FluxioParameter::FromIce
static FluxioParameter FromIce(const manager::dto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
Definition: FluxioParameter.cpp:161
armarx::core::time::fromIce
void fromIce(const dto::ClockType::ClockTypeEnum &dto, ClockType &bo)
Definition: ice_conversions.cpp:11
armarx::skills::FluxioParameterNode
Definition: FluxioParameterNode.h:14
FluxioSkill.h
armarx::skills::FluxioSkill::id
std::string id
Definition: FluxioSkill.h:27
armarx::aron::make_dict
aron::data::DictPtr make_dict(_Args &&... args)
Definition: Dict.h:107
armarx::skills::FluxioNodeType::PARAMETER
@ PARAMETER
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:51
DateTime.h
armarx::core::time::toIce
void toIce(dto::ClockType::ClockTypeEnum &dto, const ClockType &bo)
Definition: ice_conversions.cpp:31
armarx::skills::FluxioProvider::FromFluxioIdentificatorIce
static std::experimental::observer_ptr< const FluxioProvider > FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator &i, std::map< std::string, FluxioProvider > &providersMap)
Definition: FluxioProvider.cpp:50
FluxioProvider.h
FluxioControlNode.h
armarx::skills::FluxioSkill::FromFluxioIdentificatorIce
static std::experimental::observer_ptr< const FluxioSkill > FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator &i, std::map< std::string, FluxioSkill > &skillsMap)
Definition: FluxioSkill.cpp:485
std::experimental::fundamentals_v2::make_observer
observer_ptr< _Tp > make_observer(_Tp *__p) noexcept
Duration.h
armarx::skills::FluxioSubSkillNode::FromIce
static std::optional< FluxioSubSkillNode > FromIce(const manager::dto::FluxioNode &i, std::map< std::string, FluxioSkill > &skillsMap)
Definition: FluxioSubSkillNode.cpp:83
armarx::skills::FluxioParameterNode::FromAron
static std::optional< FluxioParameterNode > FromAron(const manager::arondto::FluxioNode &i, std::map< std::string, FluxioParameter > &parametersMap)
Definition: FluxioParameterNode.cpp:109
ice_conversions.h
armarx::skills::FluxioSkill::toFluxioIdentificatorIce
manager::dto::FluxioIdentificator toFluxioIdentificatorIce() const
Definition: FluxioSkill.cpp:107
std::experimental::fundamentals_v2::observer_ptr
Definition: ManagedIceObject.h:53
Dict.h
armarx::skills::FluxioEdge::FromIce
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)
Definition: FluxioEdge.cpp:67
armarx::skills::FluxioSkill::removeParameterNodesAndEdges
void removeParameterNodesAndEdges(const std::string &parameterId, bool keepParameterNodes=false)
Definition: FluxioSkill.cpp:357
armarx::skills::FluxioProvider::FromFluxioIdentificatorAron
static std::experimental::observer_ptr< const FluxioProvider > FromFluxioIdentificatorAron(const manager::arondto::FluxioIdentificator &i, std::map< std::string, FluxioProvider > &providersMap)
Definition: FluxioProvider.cpp:67
armarx::skills::FluxioParameter::FromAron
static FluxioParameter FromAron(const manager::arondto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
Definition: FluxioParameter.cpp:193
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::skills::FluxioSkill::removeEdgesConnectedToParameter
void removeEdgesConnectedToParameter(const std::string &parameterId)
Definition: FluxioSkill.cpp:465
armarx::skills::FluxioSkill::deleteParameter
void deleteParameter(const std::string &parameterId)
Definition: FluxioSkill.cpp:410
armarx::skills::FluxioSkill::executable
bool executable
Definition: FluxioSkill.h:35
armarx::skills::FluxioEdge::FromAron
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)
Definition: FluxioEdge.cpp:189
armarx::skills::FluxioControlNode::FromAron
static std::optional< FluxioControlNode > FromAron(const manager::arondto::FluxioNode &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
Definition: FluxioControlNode.cpp:162
armarx::skills::FluxioSkill::removeSubSkillNodesAndEdges
void removeSubSkillNodesAndEdges(const std::string &skillId)
Definition: FluxioSkill.cpp:417
if
if(!yyvaluep)
Definition: Grammar.cpp:645
armarx::skills::FluxioSkill::toAronXml
std::optional< manager::arondto::FluxioSkill > toAronXml() const
Definition: FluxioSkill.cpp:769
armarx::skills::FluxioParameterNode::FromIce
static std::optional< FluxioParameterNode > FromIce(const manager::dto::FluxioNode &i, std::map< std::string, FluxioParameter > &parametersMap)
Definition: FluxioParameterNode.cpp:80
FluxioParameter.h
armarx::skills::FluxioSkill::toAronDTO
std::optional< aron::data::dto::DictPtr > toAronDTO() const
Definition: FluxioSkill.cpp:842
armarx::skills::FluxioNodeType::CONTROL
@ CONTROL
FluxioEdge.h
armarx::skills::FluxioEdge::fromParameterPtr
std::experimental::observer_ptr< const FluxioParameter > fromParameterPtr
Definition: FluxioEdge.h:18
forward_declarations.h
armarx::skills::FluxioSkill::FromIce
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)
Definition: FluxioSkill.cpp:515
armarx::skills::FluxioSkill::skillProviderPtr
std::experimental::observer_ptr< const FluxioProvider > skillProviderPtr
Definition: FluxioSkill.h:38
armarx::skills::FluxioControlNode::FromIce
static std::optional< FluxioControlNode > FromIce(const manager::dto::FluxioNode &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
Definition: FluxioControlNode.cpp:136
armarx::skills::FluxioParameter::id
std::string id
Definition: FluxioParameter.h:25
armarx::skills::FluxioSkill::FromFluxioIdentificatorAron
static std::experimental::observer_ptr< const FluxioSkill > FromFluxioIdentificatorAron(const manager::arondto::FluxioIdentificator &i, std::map< std::string, FluxioSkill > &skillsMap)
Definition: FluxioSkill.cpp:500
FluxioSubSkillNode.h
armarx::skills::FluxioNodeTypeFromString
FluxioNodeType FluxioNodeTypeFromString(const std::string &type)
Definition: FluxioNode.cpp:19
armarx::skills::FluxioSkill::timeout
armarx::Duration timeout
How long (in ms) to wait for the skill to finish execution before timing out.
Definition: FluxioSkill.h:33
armarx::skills::FluxioSkill::updateFromAron
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)
Definition: FluxioSkill.cpp:238
armarx::skills::FluxioSkill::toFluxioIdentificatorAron
manager::arondto::FluxioIdentificator toFluxioIdentificatorAron() const
Definition: FluxioSkill.cpp:118
armarx::skills::FluxioEdge::toParameterPtr
std::experimental::observer_ptr< const FluxioParameter > toParameterPtr
Definition: FluxioEdge.h:20
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::skills::FluxioSkill::updateFromIce
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)
Definition: FluxioSkill.cpp:129
armarx::skills::FluxioSkill::native
bool native
Definition: FluxioSkill.h:37
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::skills::FluxioSubSkillNode
Definition: FluxioSubSkillNode.h:17
armarx::skills::FluxioSkill::lastChanged
std::string lastChanged
Definition: FluxioSkill.h:34
armarx::skills::FluxioNodeType::UNKNOWN
@ UNKNOWN
Logging.h
armarx::skills::FluxioNodeType
FluxioNodeType
Definition: FluxioNode.h:15
armarx::skills::FluxioSubSkillNode::FromAron
static std::optional< FluxioSubSkillNode > FromAron(const manager::arondto::FluxioNode &i, std::map< std::string, FluxioSkill > &skillsMap)
Definition: FluxioSubSkillNode.cpp:111
armarx::skills::FluxioSkill::FromAron
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)
Definition: FluxioSkill.cpp:585
armarx::skills::FluxioSkill::CreateNode
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)
Definition: FluxioSkill.cpp:665
FluxioParameterNode.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::skills::FluxioSkill::toManagerIce
std::optional< manager::dto::FluxioSkill > toManagerIce() const
Definition: FluxioSkill.cpp:35
armarx::skills::FluxioSkill::edges
std::list< FluxioEdge > edges
Definition: FluxioSkill.h:41
armarx::skills::FluxioNodeType::SUBSKILL
@ SUBSKILL
armarx::skills::FluxioSkill::name
std::string name
Definition: FluxioSkill.h:28
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::skills::FluxioEdge::toNodePtr
std::experimental::observer_ptr< const FluxioNode > toNodePtr
Definition: FluxioEdge.h:19
armarx::core::time::DateTime::toDateTimeString
std::string toDateTimeString() const
Definition: DateTime.cpp:75
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
FluxioNode.h
armarx::skills::FluxioSkill::parameters
std::map< std::string, FluxioParameter > parameters
Definition: FluxioSkill.h:39
armarx::skills::FluxioEdge::fromNodePtr
std::experimental::observer_ptr< const FluxioNode > fromNodePtr
Definition: FluxioEdge.h:17