FluxioEdge.cpp
Go to the documentation of this file.
1#include "FluxioEdge.h"
2
3#include <memory>
4#include <optional>
5
7
9#include <RobotAPI/libraries/skills/core/aron/FluxioEdge.aron.generated.h>
10
11#include "FluxioNode.h"
12#include "FluxioParameter.h"
13#include "FluxioSubSkillNode.h"
14
15namespace armarx
16{
17 namespace skills
18 {
19 bool
21 {
22 return fromNodePtr != nullptr && fromParameterPtr != nullptr && toNodePtr != nullptr &&
23 toParameterPtr != nullptr;
24 }
25
26 std::optional<manager::dto::FluxioEdge>
28 {
29 if (fromNodePtr == nullptr || fromParameterPtr == nullptr || toNodePtr == nullptr ||
30 toParameterPtr == nullptr)
31 {
32 ARMARX_WARNING << "Could not create FluxioEdge DTO";
33 return std::nullopt;
34 }
35
36 manager::dto::FluxioEdge ret;
37
38 ret.fromNodeId = fromNodePtr->toFluxioIdentificatorIce();
39 ret.fromParameterId = fromParameterPtr->toFluxioIdentificatorIce();
40 ret.toNodeId = toNodePtr->toFluxioIdentificatorIce();
41 ret.toParameterId = toParameterPtr->toFluxioIdentificatorIce();
42
43 return ret;
44 }
45
46 std::optional<manager::arondto::FluxioEdge>
48 {
49 if (fromNodePtr == nullptr || fromParameterPtr == nullptr || toNodePtr == nullptr ||
50 toParameterPtr == nullptr)
51 {
52 ARMARX_WARNING << "Could not create FluxioEdge DTO";
53 return std::nullopt;
54 }
55
56 manager::arondto::FluxioEdge ret;
57
58 ret.fromNodeId = fromNodePtr->toFluxioIdentificatorAron();
59 ret.fromParameterId = fromParameterPtr->toFluxioIdentificatorAron();
60 ret.toNodeId = toNodePtr->toFluxioIdentificatorAron();
61 ret.toParameterId = toParameterPtr->toFluxioIdentificatorAron();
62
63 return ret;
64 }
65
66 std::optional<FluxioEdge>
68 const manager::dto::FluxioEdge& i,
69 const std::map<const std::string, const std::unique_ptr<FluxioNode>>& nodesMap,
70 const std::map<std::string, FluxioParameter>& parametersMap)
71 {
72 const auto& fromNodePtr =
73 FluxioNode::FromFluxioIdentificatorIce(i.fromNodeId, nodesMap);
74 const auto& toNodePtr = FluxioNode::FromFluxioIdentificatorIce(i.toNodeId, nodesMap);
75
76 if (fromNodePtr == nullptr || toNodePtr == nullptr)
77 {
78 ARMARX_WARNING << "Failed to convert node(s)";
79 return std::nullopt;
80 }
81
83 nullptr;
85
86 // Check if fromNode is a SubSkillNode
88 {
89 const auto& subSkillNodePtr = std::experimental::make_observer(
90 dynamic_cast<const FluxioSubSkillNode*>(fromNodePtr.get()));
91 if (subSkillNodePtr == nullptr)
92 {
93 ARMARX_WARNING << "Failed to cast node to sub skill node";
94 return std::nullopt;
95 }
96
97 if (subSkillNodePtr->skillPtr == nullptr)
98 {
99 ARMARX_WARNING << "SkillPtr for SubSkillNode is not set";
100 return std::nullopt;
101 }
102
103 const auto& subSkillParams = subSkillNodePtr->skillPtr->parameters;
105 FluxioParameter::FromFluxioIdentificatorIce(i.fromParameterId, subSkillParams);
106 }
107 else if (fromNodePtr->nodeType == FluxioNodeType::PARAMETER)
108 {
110 FluxioParameter::FromFluxioIdentificatorIce(i.fromParameterId, parametersMap);
111 }
112 else if (fromNodePtr->nodeType == FluxioNodeType::CONTROL)
113 {
114 const auto& controlNodePtr = std::experimental::make_observer(
115 dynamic_cast<const FluxioControlNode*>(fromNodePtr.get()));
116 if (controlNodePtr == nullptr)
117 {
118 ARMARX_WARNING << "Failed to cast node to control node";
119 return std::nullopt;
120 }
121
123 i.fromParameterId, controlNodePtr->parametersMap);
124 }
125 else
126 {
127 ARMARX_WARNING << "Unknown from node type";
128 return std::nullopt;
129 }
130
131 // Check if toNode is a SubSkillNode
132 if (toNodePtr->nodeType == FluxioNodeType::SUBSKILL)
133 {
134 const auto& subSkillNodePtr = std::experimental::make_observer(
135 dynamic_cast<const FluxioSubSkillNode*>(toNodePtr.get()));
136 if (subSkillNodePtr == nullptr)
137 {
138 ARMARX_WARNING << "Failed to cast node to sub skill node";
139 return std::nullopt;
140 }
141
142 if (subSkillNodePtr->skillPtr == nullptr)
143 {
144 ARMARX_WARNING << "SkillPtr for SubSkillNode is not set";
145 return std::nullopt;
146 }
147
148 const auto& subSkillParams = subSkillNodePtr->skillPtr->parameters;
150 FluxioParameter::FromFluxioIdentificatorIce(i.toParameterId, subSkillParams);
151 }
152 else if (toNodePtr->nodeType == FluxioNodeType::CONTROL)
153 {
154 const auto& controlNodePtr = std::experimental::make_observer(
155 dynamic_cast<const FluxioControlNode*>(toNodePtr.get()));
156 if (controlNodePtr == nullptr)
157 {
158 ARMARX_WARNING << "Failed to cast node to control node";
159 return std::nullopt;
160 }
161
163 i.toParameterId, controlNodePtr->parametersMap);
164 }
165 else if (toNodePtr->nodeType == FluxioNodeType::PARAMETER)
166 {
168 FluxioParameter::FromFluxioIdentificatorIce(i.toParameterId, parametersMap);
169 }
170 else
171 {
172 ARMARX_WARNING << "Unknown to node type";
173 return std::nullopt;
174 }
175
176 if (fromParameterPtr == nullptr || toParameterPtr == nullptr)
177 {
178 ARMARX_WARNING << "Failed to convert parameter(s)";
179 return std::nullopt;
180 }
181
182 return FluxioEdge{.fromNodePtr = fromNodePtr,
183 .fromParameterPtr = fromParameterPtr,
184 .toNodePtr = toNodePtr,
185 .toParameterPtr = toParameterPtr};
186 }
187
188 std::optional<FluxioEdge>
190 const manager::arondto::FluxioEdge& i,
191 const std::map<const std::string, const std::unique_ptr<FluxioNode>>& nodesMap,
192 const std::map<std::string, FluxioParameter>& parametersMap)
193 {
194 const auto& fromNodePtr =
195 FluxioNode::FromFluxioIdentificatorAron(i.fromNodeId, nodesMap);
196 const auto& toNodePtr = FluxioNode::FromFluxioIdentificatorAron(i.toNodeId, nodesMap);
197
198 if (fromNodePtr == nullptr || toNodePtr == nullptr)
199 {
200 ARMARX_WARNING << "Failed to convert node(s)";
201 return std::nullopt;
202 }
203
205 nullptr;
207
208 // Check if fromNode is a SubSkillNode
209 if (fromNodePtr->nodeType == FluxioNodeType::SUBSKILL)
210 {
211 const auto& subSkillNodePtr = std::experimental::make_observer(
212 dynamic_cast<const FluxioSubSkillNode*>(fromNodePtr.get()));
213 if (subSkillNodePtr == nullptr)
214 {
215 ARMARX_WARNING << "Failed to cast node to sub skill node";
216 return std::nullopt;
217 }
218
219 if (subSkillNodePtr->skillPtr == nullptr)
220 {
221 ARMARX_WARNING << "SkillPtr for SubSkillNode is not set";
222 return std::nullopt;
223 }
224
225 const auto& subSkillParams = subSkillNodePtr->skillPtr->parameters;
227 FluxioParameter::FromFluxioIdentificatorAron(i.fromParameterId, subSkillParams);
228 }
229 else if (fromNodePtr->nodeType == FluxioNodeType::PARAMETER)
230 {
232 FluxioParameter::FromFluxioIdentificatorAron(i.fromParameterId, parametersMap);
233 }
234 else if (fromNodePtr->nodeType == FluxioNodeType::CONTROL)
235 {
236 const auto& controlNodePtr = std::experimental::make_observer(
237 dynamic_cast<const FluxioControlNode*>(fromNodePtr.get()));
238 if (controlNodePtr == nullptr)
239 {
240 ARMARX_WARNING << "Failed to cast node to control node";
241 return std::nullopt;
242 }
243
245 i.fromParameterId, controlNodePtr->parametersMap);
246 }
247 else
248 {
249 ARMARX_WARNING << "Unknown from node type";
250 return std::nullopt;
251 }
252
253 // Check if toNode is a SubSkillNode
254 if (toNodePtr->nodeType == FluxioNodeType::SUBSKILL)
255 {
256 const auto& subSkillNodePtr = std::experimental::make_observer(
257 dynamic_cast<const FluxioSubSkillNode*>(toNodePtr.get()));
258 if (subSkillNodePtr == nullptr)
259 {
260 ARMARX_WARNING << "Failed to cast node to sub skill node";
261 return std::nullopt;
262 }
263
264 if (subSkillNodePtr->skillPtr == nullptr)
265 {
266 ARMARX_WARNING << "SkillPtr for SubSkillNode is not set";
267 return std::nullopt;
268 }
269
270 const auto& subSkillParams = subSkillNodePtr->skillPtr->parameters;
272 FluxioParameter::FromFluxioIdentificatorAron(i.toParameterId, subSkillParams);
273 }
274 else if (toNodePtr->nodeType == FluxioNodeType::CONTROL)
275 {
276 const auto& controlNodePtr = std::experimental::make_observer(
277 dynamic_cast<const FluxioControlNode*>(toNodePtr.get()));
278 if (controlNodePtr == nullptr)
279 {
280 ARMARX_WARNING << "Failed to cast node to control node";
281 return std::nullopt;
282 }
283
285 i.toParameterId, controlNodePtr->parametersMap);
286 }
287 else if (toNodePtr->nodeType == FluxioNodeType::PARAMETER)
288 {
290 FluxioParameter::FromFluxioIdentificatorAron(i.toParameterId, parametersMap);
291 }
292 else
293 {
294 ARMARX_WARNING << "Unknown to node type";
295 return std::nullopt;
296 }
297
298 if (fromParameterPtr == nullptr || toParameterPtr == nullptr)
299 {
300 ARMARX_WARNING << "Failed to convert parameter(s)";
301 return std::nullopt;
302 }
303
304 return FluxioEdge{.fromNodePtr = fromNodePtr,
305 .fromParameterPtr = fromParameterPtr,
306 .toNodePtr = toNodePtr,
307 .toParameterPtr = toParameterPtr};
308 }
309 } // namespace skills
310} // namespace armarx
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
observer_ptr< _Tp > make_observer(_Tp *__p) noexcept
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)
std::optional< manager::arondto::FluxioEdge > toAron() const
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::optional< manager::dto::FluxioEdge > toManagerIce() const
std::experimental::observer_ptr< const FluxioNode > fromNodePtr
Definition FluxioEdge.h:17
std::experimental::observer_ptr< const FluxioNode > toNodePtr
Definition FluxioEdge.h:19
static std::experimental::observer_ptr< const FluxioNode > FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator &i, const std::map< const std::string, const std::unique_ptr< FluxioNode > > &nodesMap)
static std::experimental::observer_ptr< const FluxioNode > FromFluxioIdentificatorAron(const manager::arondto::FluxioIdentificator &i, const std::map< const std::string, const std::unique_ptr< FluxioNode > > &nodesMap)
static std::experimental::observer_ptr< const FluxioParameter > FromFluxioIdentificatorAron(const manager::arondto::FluxioIdentificator &i, const std::map< std::string, FluxioParameter > &parametersMap)
static std::experimental::observer_ptr< const FluxioParameter > FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator &i, const std::map< std::string, FluxioParameter > &parametersMap)