SkillStatusUpdate.cpp
Go to the documentation of this file.
1 #include "SkillStatusUpdate.h"
2 
3 namespace armarx
4 {
5  namespace skills
6  {
9  {
10  switch (d)
11  {
13  return SkillStatus::Running;
15  return SkillStatus::Failed;
19  return SkillStatus::Aborted;
20  }
21  throw error::SkillException(__PRETTY_FUNCTION__, "Should not happen!");
22  }
23 
26  {
27  switch (d)
28  {
30  return SkillStatus::Failed;
34  return SkillStatus::Aborted;
35  }
36  throw error::SkillException(__PRETTY_FUNCTION__, "Should not happen!");
37  }
38 
41  {
42  // if both are equal
43  if (t1 == t2)
44  {
45  return t1;
46  }
47 
48  // if one is failed (most unspecific result)
50  {
52  }
53 
54  // else one must be aborted and the other one must be succeeded
56  }
57 
61  {
62  // if both are equal
63  if (t1 == t2)
64  {
65  return t1;
66  }
67 
68  // if one is failed (most unspecific result)
71  {
73  }
74 
75  // if none is failed and one is aborted (second most unspecific result)
78  {
80  }
81 
82  // else one must be running and the other one must be succeeded
84  }
85 
86  void
87  toIce(core::dto::Execution::Status& ret, const SkillStatus& status)
88  {
89  switch (status)
90  {
92  ret = core::dto::Execution::Status::Constructing;
93  return;
95  ret = core::dto::Execution::Status::Initializing;
96  return;
98  ret = core::dto::Execution::Status::Preparing;
99  return;
102  return;
103  case SkillStatus::Failed:
104  ret = core::dto::Execution::Status::Failed;
105  return;
107  ret = core::dto::Execution::Status::Succeeded;
108  return;
110  ret = core::dto::Execution::Status::Aborted;
111  return;
112  }
113  throw error::SkillException(__PRETTY_FUNCTION__, "Should not happen!");
114  }
115 
116  void
117  toIce(core::dto::Execution::Status& ret, const ActiveOrTerminatedSkillStatus& status)
118  {
119  switch (status)
120  {
123  return;
125  ret = core::dto::Execution::Status::Failed;
126  return;
128  ret = core::dto::Execution::Status::Succeeded;
129  return;
131  ret = core::dto::Execution::Status::Aborted;
132  return;
133  }
134  throw error::SkillException(__PRETTY_FUNCTION__, "Should not happen!");
135  }
136 
137  void
138  toIce(core::dto::Execution::Status& ret, const TerminatedSkillStatus& status)
139  {
140  switch (status)
141  {
143  ret = core::dto::Execution::Status::Failed;
144  return;
146  ret = core::dto::Execution::Status::Succeeded;
147  return;
149  ret = core::dto::Execution::Status::Aborted;
150  return;
151  }
152  throw error::SkillException(__PRETTY_FUNCTION__, "Should not happen!");
153  }
154 
155  void
156  fromIce(const core::dto::Execution::Status& status, TerminatedSkillStatus& ret)
157  {
158  switch (status)
159  {
160  case core::dto::Execution::Status::Constructing:
161  [[fallthrough]];
162  case core::dto::Execution::Status::Initializing:
163  [[fallthrough]];
164  case core::dto::Execution::Status::Preparing:
165  [[fallthrough]];
167  break;
168  case core::dto::Execution::Status::Failed:
170  return;
171  case core::dto::Execution::Status::Succeeded:
173  return;
174  case core::dto::Execution::Status::Aborted:
176  return;
177  }
178  throw error::SkillException(
179  __PRETTY_FUNCTION__,
180  "You entered an invalid execution status type to convert to a terminating status.");
181  }
182 
183  void
184  fromIce(const core::dto::Execution::Status& status, ActiveOrTerminatedSkillStatus& ret)
185  {
186  switch (status)
187  {
188  case core::dto::Execution::Status::Constructing:
189  [[fallthrough]];
190  case core::dto::Execution::Status::Initializing:
191  [[fallthrough]];
192  case core::dto::Execution::Status::Preparing:
193  break;
196  return;
197  case core::dto::Execution::Status::Failed:
199  return;
200  case core::dto::Execution::Status::Succeeded:
202  return;
203  case core::dto::Execution::Status::Aborted:
205  return;
206  }
207  throw error::SkillException(
208  __PRETTY_FUNCTION__,
209  "You entered an invalid execution status type to convert to a terminating status.");
210  }
211 
212  void
213  fromIce(const core::dto::Execution::Status& status, SkillStatus& ret)
214  {
215  switch (status)
216  {
217  case core::dto::Execution::Status::Constructing:
219  return;
220  case core::dto::Execution::Status::Initializing:
222  return;
223  case core::dto::Execution::Status::Preparing:
225  return;
228  return;
229  case core::dto::Execution::Status::Failed:
231  return;
232  case core::dto::Execution::Status::Succeeded:
234  return;
235  case core::dto::Execution::Status::Aborted:
237  return;
238  }
239  throw error::SkillException(__PRETTY_FUNCTION__, "Should not happen!");
240  }
241 
242  manager::dto::SkillStatusUpdate
244  {
245  manager::dto::SkillStatusUpdate ret;
246  ret.executionId.skillId = executionId.skillId.toManagerIce();
247  ret.executionId.executorName = executionId.executorName;
248  armarx::core::time::toIce(ret.executionId.executionStartedTime,
251  ret.callbackInterface = callbackInterface;
253  return ret;
254  }
255 
256  provider::dto::SkillStatusUpdate
258  {
259  provider::dto::SkillStatusUpdate ret;
260  ret.executionId.skillId = executionId.skillId.toProviderIce();
261  ret.executionId.executorName = executionId.executorName;
262  armarx::core::time::toIce(ret.executionId.executionStartedTime,
265  ret.callbackInterface = callbackInterface;
267  return ret;
268  }
269 
270  manager::dto::SkillStatusUpdate
272  {
273  manager::dto::SkillStatusUpdate ret = SkillStatusUpdateBase::toManagerIce();
274  skills::toIce(ret.status, status);
275  return ret;
276  }
277 
278  provider::dto::SkillStatusUpdate
280  {
281  provider::dto::SkillStatusUpdate ret = SkillStatusUpdateBase::toProviderIce();
282  skills::toIce(ret.status, status);
283  return ret;
284  }
285 
286  manager::dto::SkillStatusUpdate
288  {
289  manager::dto::SkillStatusUpdate ret = SkillStatusUpdateBase::toManagerIce();
290  skills::toIce(ret.status, status);
291  return ret;
292  }
293 
294  provider::dto::SkillStatusUpdate
296  {
297  provider::dto::SkillStatusUpdate ret = SkillStatusUpdateBase::toProviderIce();
298  skills::toIce(ret.status, status);
299  return ret;
300  }
301 
302  manager::dto::SkillStatusUpdate
304  {
305  manager::dto::SkillStatusUpdate ret = SkillStatusUpdateBase::toManagerIce();
306  skills::toIce(ret.status, status);
307  return ret;
308  }
309 
310  provider::dto::SkillStatusUpdate
312  {
313  provider::dto::SkillStatusUpdate ret = SkillStatusUpdateBase::toProviderIce();
314  skills::toIce(ret.status, status);
315  return ret;
316  }
317 
318  template <class BoT, class DtoT>
319  static void
320  setResultFromIce(BoT& bo, const DtoT& dto)
321  {
322  if (dto.result)
323  {
324  bo.result = aron::make_dict(dto.result);
325  }
326  }
327 
328  TerminatedSkillStatusUpdate
329  TerminatedSkillStatusUpdate::FromIce(const manager::dto::SkillStatusUpdate& update)
330  {
332  {.executionId = skills::SkillExecutionID::FromIce(update.executionId),
333  .parameters = armarx::aron::data::Dict::FromAronDictDTO(update.parameters),
334  .callbackInterface = update.callbackInterface}};
335  skills::fromIce(update.status, ret.status);
336  setResultFromIce(ret, update);
337  return ret;
338  }
339 
341  TerminatedSkillStatusUpdate::FromIce(const provider::dto::SkillStatusUpdate& update,
342  const std::optional<skills::ProviderID>& providerId)
343  {
345  {.executionId = skills::SkillExecutionID::FromIce(update.executionId, providerId),
346  .parameters = armarx::aron::data::Dict::FromAronDictDTO(update.parameters),
347  .callbackInterface = update.callbackInterface}};
348  skills::fromIce(update.status, ret.status);
349  setResultFromIce(ret, update);
350  return ret;
351  }
352 
354  SkillStatusUpdate::FromIce(const manager::dto::SkillStatusUpdate& update)
355  {
357  .executionId = skills::SkillExecutionID::FromIce(update.executionId),
358  .parameters = armarx::aron::data::Dict::FromAronDictDTO(update.parameters),
359  .callbackInterface = update.callbackInterface,
360  }};
361  skills::fromIce(update.status, ret.status);
362  setResultFromIce(ret, update);
363  return ret;
364  }
365 
367  SkillStatusUpdate::FromIce(const provider::dto::SkillStatusUpdate& update,
368  const std::optional<skills::ProviderID>& providerId)
369  {
371  .executionId = skills::SkillExecutionID::FromIce(update.executionId, providerId),
372  .parameters = armarx::aron::data::Dict::FromAronDictDTO(update.parameters),
373  .callbackInterface = update.callbackInterface,
375  }};
376  skills::fromIce(update.status, ret.status);
377  setResultFromIce(ret, update);
378  return ret;
379  }
380 
382  ActiveOrTerminatedSkillStatusUpdate::FromIce(const manager::dto::SkillStatusUpdate& update)
383  {
385  {.executionId = skills::SkillExecutionID::FromIce(update.executionId),
386  .parameters = armarx::aron::data::Dict::FromAronDictDTO(update.parameters),
387  .callbackInterface = update.callbackInterface}};
388  skills::fromIce(update.status, ret.status);
389  setResultFromIce(ret, update);
390  return ret;
391  }
392 
395  const provider::dto::SkillStatusUpdate& update,
396  const std::optional<skills::ProviderID>& providerId)
397  {
399  {.executionId = skills::SkillExecutionID::FromIce(update.executionId, providerId),
400  .parameters = armarx::aron::data::Dict::FromAronDictDTO(update.parameters),
401  .callbackInterface = update.callbackInterface}};
402  skills::fromIce(update.status, ret.status);
403  setResultFromIce(ret, update);
404  return ret;
405  }
406 
407  } // namespace skills
408 } // namespace armarx
armarx::skills::TerminatedSkillStatus
TerminatedSkillStatus
Definition: SkillStatusUpdate.h:39
armarx::skills::TerminatedSkillStatusUpdate::FromIce
static TerminatedSkillStatusUpdate FromIce(const provider::dto::SkillStatusUpdate &update, const std::optional< skills::ProviderID > &providerId=std::nullopt)
Definition: SkillStatusUpdate.cpp:341
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
armarx::skills::SkillStatusUpdateBase::toManagerIce
manager::dto::SkillStatusUpdate toManagerIce() const
Definition: SkillStatusUpdate.cpp:243
armarx::skills::TerminatedSkillStatus::Succeeded
@ Succeeded
skills
This file is part of ArmarX.
armarx::skills::SkillStatusUpdate::toManagerIce
manager::dto::SkillStatusUpdate toManagerIce() const
Definition: SkillStatusUpdate.cpp:287
armarx::skills::SkillExecutionID::executorName
std::string executorName
Definition: SkillExecutionID.h:22
armarx::skills::TerminatedSkillStatus::Aborted
@ Aborted
SkillStatusUpdate.h
armarx::skills::SkillStatus::Aborted
@ Aborted
armarx::skills::SkillStatusUpdate::FromIce
static SkillStatusUpdate FromIce(const provider::dto::SkillStatusUpdate &update, const std::optional< skills::ProviderID > &providerId=std::nullopt)
Definition: SkillStatusUpdate.cpp:367
armarx::skills::ActiveOrTerminatedSkillStatus::Succeeded
@ Succeeded
armarx::skills::ActiveOrTerminatedSkillStatus::Failed
@ Failed
armarx::aron::make_dict
aron::data::DictPtr make_dict(_Args &&... args)
Definition: Dict.h:107
KITProsthesis::ProsthesisState::Running
@ Running
Definition: KITProstheticHandInterface.ice:43
armarx::core::time::toIce
void toIce(dto::ClockType::ClockTypeEnum &dto, const ClockType &bo)
Definition: ice_conversions.cpp:33
armarx::skills::mergeSkillStatuseses
TerminatedSkillStatus mergeSkillStatuseses(const TerminatedSkillStatus t1, const TerminatedSkillStatus t2)
Definition: SkillStatusUpdate.cpp:40
armarx::skills::TerminatedSkillStatusUpdate::toManagerIce
manager::dto::SkillStatusUpdate toManagerIce() const
Definition: SkillStatusUpdate.cpp:271
armarx::skills::SkillExecutionID::executionStartedTime
armarx::core::time::DateTime executionStartedTime
Definition: SkillExecutionID.h:23
armarx::skills::SkillStatusUpdateBase::callbackInterface
callback::dti::SkillProviderCallbackInterfacePrx callbackInterface
Definition: SkillStatusUpdate.h:68
armarx::skills::SkillStatusUpdateBase::executionId
SkillExecutionID executionId
Definition: SkillStatusUpdate.h:66
armarx::skills::SkillID::toManagerIce
manager::dto::SkillID toManagerIce() const
Definition: SkillID.cpp:51
armarx::skills::SkillStatusUpdateBase::result
aron::data::DictPtr result
Definition: SkillStatusUpdate.h:71
armarx::aron::data::Dict::FromAronDictDTO
static PointerType FromAronDictDTO(const data::dto::DictPtr &aron)
Definition: Dict.cpp:129
armarx::skills::ActiveOrTerminatedSkillStatusUpdate::FromIce
static ActiveOrTerminatedSkillStatusUpdate FromIce(const provider::dto::SkillStatusUpdate &update, const std::optional< skills::ProviderID > &providerId=std::nullopt)
Definition: SkillStatusUpdate.cpp:394
armarx::skills::ActiveOrTerminatedSkillStatusUpdate::toProviderIce
provider::dto::SkillStatusUpdate toProviderIce() const
Definition: SkillStatusUpdate.cpp:311
armarx::skills::ActiveOrTerminatedSkillStatus
ActiveOrTerminatedSkillStatus
Definition: SkillStatusUpdate.h:31
armarx::status
status
Definition: FiniteStateMachine.h:259
armarx::skills::SkillStatusUpdate
Definition: SkillStatusUpdate.h:139
armarx::skills::TerminatedSkillStatusUpdate::toProviderIce
provider::dto::SkillStatusUpdate toProviderIce() const
Definition: SkillStatusUpdate.cpp:279
armarx::skills::SkillStatusUpdate::toProviderIce
provider::dto::SkillStatusUpdate toProviderIce() const
Definition: SkillStatusUpdate.cpp:295
armarx::skills::SkillStatus::Preparing
@ Preparing
armarx::skills::ActiveOrTerminatedSkillStatus::Aborted
@ Aborted
armarx::skills::error::SkillException
A base class for skill exceptions.
Definition: Exception.h:40
armarx::skills::toIce
void toIce(core::dto::Execution::Status &ret, const SkillStatus &status)
Definition: SkillStatusUpdate.cpp:87
armarx::aron::data::Dict::ToAronDictDTO
static data::dto::DictPtr ToAronDictDTO(const PointerType &navigator)
Definition: Dict.cpp:139
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
armarx::skills::ActiveOrTerminatedSkillStatus::Running
@ Running
armarx::skills::SkillStatusUpdateBase::toProviderIce
provider::dto::SkillStatusUpdate toProviderIce() const
Definition: SkillStatusUpdate.cpp:257
armarx::skills::TerminatedSkillStatusUpdate
Definition: SkillStatusUpdate.h:79
armarx::skills::SkillStatus::Initializing
@ Initializing
armarx::skills::TerminatedSkillStatus::Failed
@ Failed
armarx::skills::ActiveOrTerminatedSkillStatusUpdate::toManagerIce
manager::dto::SkillStatusUpdate toManagerIce() const
Definition: SkillStatusUpdate.cpp:303
armarx::skills::SkillStatusUpdateBase::parameters
aron::data::DictPtr parameters
Definition: SkillStatusUpdate.h:67
armarx::skills::SkillExecutionID::skillId
SkillID skillId
Definition: SkillExecutionID.h:21
armarx::skills::SkillExecutionID::FromIce
static SkillExecutionID FromIce(const skills::manager::dto::SkillExecutionID &)
Definition: SkillExecutionID.cpp:29
armarx::skills::SkillStatus::Running
@ Running
armarx::skills::SkillID::toProviderIce
provider::dto::SkillID toProviderIce() const
Definition: SkillID.cpp:58
armarx::skills::toSkillStatus
SkillStatus toSkillStatus(const ActiveOrTerminatedSkillStatus &d)
Definition: SkillStatusUpdate.cpp:8
armarx::skills::ActiveOrTerminatedSkillStatusUpdate
Definition: SkillStatusUpdate.h:108
armarx::skills::fromIce
void fromIce(const core::dto::Execution::Status &status, TerminatedSkillStatus &ret)
Definition: SkillStatusUpdate.cpp:156
armarx::skills::SkillStatus::Constructing
@ Constructing
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::aron::bo
const std::optional< BoT > & bo
Definition: aron_conversions.h:168
armarx::skills::SkillStatus
SkillStatus
Definition: SkillStatusUpdate.h:20
armarx::skills::SkillStatus::Succeeded
@ Succeeded
armarx::skills::SkillStatus::Failed
@ Failed