From 015068195e4bb02e34579c0d428a271b23dfe72a Mon Sep 17 00:00:00 2001
From: Rainer Kartmann <rainer.kartmann@kit.edu>
Date: Tue, 22 Mar 2022 13:42:58 +0100
Subject: [PATCH] Add to/fromAron() for IceUtil::Time and move to correct
 namespace

---
 .../aron/common/aron_conversions/armarx.cpp   | 192 +++++++++---------
 .../aron/common/aron_conversions/armarx.h     |  16 +-
 2 files changed, 112 insertions(+), 96 deletions(-)

diff --git a/source/RobotAPI/libraries/aron/common/aron_conversions/armarx.cpp b/source/RobotAPI/libraries/aron/common/aron_conversions/armarx.cpp
index 13535b244..402236902 100644
--- a/source/RobotAPI/libraries/aron/common/aron_conversions/armarx.cpp
+++ b/source/RobotAPI/libraries/aron/common/aron_conversions/armarx.cpp
@@ -1,116 +1,126 @@
 #include "armarx.h"
 
+#include <IceUtil/Time.h>
 
 #include <RobotAPI/libraries/aron/common/aron_conversions/core.h>
 #include <RobotAPI/libraries/aron/common/aron_conversions/stl.h>
 
-namespace armarx
+
+void IceUtil::fromAron(const long& dto, IceUtil::Time& bo)
 {
+    bo = IceUtil::Time::microSeconds(dto);
+}
 
-    /* PackagePath */
+void IceUtil::toAron(long& dto, const IceUtil::Time& bo)
+{
+    dto = bo.toMicroSeconds();
+}
 
-    void fromAron(const arondto::PackagePath& dto, PackagePath& bo)
-    {
-        bo = {dto.package, dto.path};
-    }
 
-    void toAron(arondto::PackagePath& dto, const PackagePath& bo)
-    {
-        const data::PackagePath icedto = bo.serialize();
-        dto.package                    = icedto.package;
-        dto.path                       = icedto.path;
-    }
+void IceUtil::fromAron(const IceUtil::Time& dto, armarx::DateTime& bo)
+{
+    bo = armarx::DateTime(armarx::Duration::MicroSeconds(dto.toMicroSeconds()));
+}
 
-    void fromAron(const long& dto, IceUtil::Time& bo)
-    {
-        bo = IceUtil::Time::microSeconds(dto);
-    }
+void IceUtil::toAron(IceUtil::Time& dto, const armarx::DateTime& bo)
+{
+    dto = IceUtil::Time::microSeconds(bo.toMicroSecondsSinceEpoch());
+}
 
-    void toAron(long& dto, const IceUtil::Time& bo)
-    {
-        dto = bo.toMicroSeconds();
-    }
 
-    void fromAron(const arondto::ClockType& dto, ClockType& bo)
-    {
-        switch (dto.value)
-        {
-            case arondto::ClockType::Realtime:
-                bo = ClockType::Realtime;
-                break;
-            case arondto::ClockType::Monotonic:
-                bo = ClockType::Monotonic;
-                break;
-            case arondto::ClockType::Virtual:
-                bo = ClockType::Virtual;
-                break;
-            case arondto::ClockType::Unknown:
-                bo = ClockType::Unknown;
-                break;
-        }
-    }
+/* PackagePath */
 
-    void toAron(arondto::ClockType& dto, const ClockType& bo)
-    {
-        switch (bo)
-        {
-            case ClockType::Realtime:
-                dto = arondto::ClockType::Realtime;
-                break;
-            case ClockType::Monotonic:
-                dto = arondto::ClockType::Monotonic;
-                break;
-            case ClockType::Virtual:
-                dto = arondto::ClockType::Virtual;
-                break;
-            case ClockType::Unknown:
-                dto = arondto::ClockType::Unknown;
-                break;
-        }
-    }
+void armarx::fromAron(const arondto::PackagePath& dto, PackagePath& bo)
+{
+    bo = {dto.package, dto.path};
+}
 
-    void fromAron(const arondto::Duration& dto, Duration& bo)
-    {
-        bo = Duration::MicroSeconds(dto.microSeconds);
-    }
+void armarx::toAron(arondto::PackagePath& dto, const PackagePath& bo)
+{
+    const data::PackagePath icedto = bo.serialize();
+    dto.package                    = icedto.package;
+    dto.path                       = icedto.path;
+}
 
-    void toAron(arondto::Duration& dto, const Duration& bo)
-    {
-        dto.microSeconds = bo.toMicroSeconds();
-    }
 
-    void fromAron(const arondto::Frequency& dto, Frequency& bo)
+void armarx::fromAron(const arondto::ClockType& dto, ClockType& bo)
+{
+    switch (dto.value)
     {
-        Duration cycleDuration;
-        fromAron(dto.cycleDuration, cycleDuration);
-        bo = Frequency(cycleDuration);
+        case arondto::ClockType::Realtime:
+            bo = ClockType::Realtime;
+            break;
+        case arondto::ClockType::Monotonic:
+            bo = ClockType::Monotonic;
+            break;
+        case arondto::ClockType::Virtual:
+            bo = ClockType::Virtual;
+            break;
+        case arondto::ClockType::Unknown:
+            bo = ClockType::Unknown;
+            break;
     }
+}
 
-    void toAron(arondto::Frequency& dto, const Frequency& bo)
+void armarx::toAron(arondto::ClockType& dto, const ClockType& bo)
+{
+    switch (bo)
     {
-        arondto::Duration cycleDuration;
-        toAron(cycleDuration, bo.toCycleDuration());
-        dto.cycleDuration = cycleDuration;
+        case ClockType::Realtime:
+            dto = arondto::ClockType::Realtime;
+            break;
+        case ClockType::Monotonic:
+            dto = arondto::ClockType::Monotonic;
+            break;
+        case ClockType::Virtual:
+            dto = arondto::ClockType::Virtual;
+            break;
+        case ClockType::Unknown:
+            dto = arondto::ClockType::Unknown;
+            break;
     }
+}
 
-    void fromAron(const arondto::DateTime& dto, DateTime& bo)
-    {
-        Duration timeSinceEpoch;
-        fromAron(dto.timeSinceEpoch, timeSinceEpoch);
-        ClockType clockType;
-        fromAron(dto.clockType, clockType);
-        bo = DateTime(timeSinceEpoch, clockType, dto.hostname);
-    }
+void armarx::fromAron(const arondto::Duration& dto, Duration& bo)
+{
+    bo = Duration::MicroSeconds(dto.microSeconds);
+}
 
-    void toAron(arondto::DateTime& dto, const DateTime& bo)
-    {
-        arondto::Duration timeSinceEpoch;
-        toAron(timeSinceEpoch, bo.toDurationSinceEpoch());
-        dto.timeSinceEpoch = timeSinceEpoch;
-        arondto::ClockType clockType;
-        toAron(clockType, bo.clockType());
-        dto.clockType = clockType;
-        dto.hostname = bo.hostname();
-    }
+void armarx::toAron(arondto::Duration& dto, const Duration& bo)
+{
+    dto.microSeconds = bo.toMicroSeconds();
+}
+
+void armarx::fromAron(const arondto::Frequency& dto, Frequency& bo)
+{
+    Duration cycleDuration;
+    fromAron(dto.cycleDuration, cycleDuration);
+    bo = Frequency(cycleDuration);
+}
 
-} // namespace armarx
+void armarx::toAron(arondto::Frequency& dto, const Frequency& bo)
+{
+    arondto::Duration cycleDuration;
+    toAron(cycleDuration, bo.toCycleDuration());
+    dto.cycleDuration = cycleDuration;
+}
+
+void armarx::fromAron(const arondto::DateTime& dto, DateTime& bo)
+{
+    Duration timeSinceEpoch;
+    fromAron(dto.timeSinceEpoch, timeSinceEpoch);
+    ClockType clockType;
+    fromAron(dto.clockType, clockType);
+    bo = DateTime(timeSinceEpoch, clockType, dto.hostname);
+}
+
+void armarx::toAron(arondto::DateTime& dto, const DateTime& bo)
+{
+    arondto::Duration timeSinceEpoch;
+    toAron(timeSinceEpoch, bo.toDurationSinceEpoch());
+    dto.timeSinceEpoch = timeSinceEpoch;
+    arondto::ClockType clockType;
+    toAron(clockType, bo.clockType());
+    dto.clockType = clockType;
+    dto.hostname = bo.hostname();
+}
diff --git a/source/RobotAPI/libraries/aron/common/aron_conversions/armarx.h b/source/RobotAPI/libraries/aron/common/aron_conversions/armarx.h
index 3f66752a8..807605ec0 100644
--- a/source/RobotAPI/libraries/aron/common/aron_conversions/armarx.h
+++ b/source/RobotAPI/libraries/aron/common/aron_conversions/armarx.h
@@ -3,21 +3,27 @@
 #include <ArmarXCore/core/PackagePath.h>
 #include <ArmarXCore/core/time_minimal.h>
 
-#include <IceUtil/Time.h>
-
 #include <RobotAPI/libraries/aron/common/aron/PackagePath.aron.generated.h>
 #include <RobotAPI/libraries/aron/common/aron/time.aron.generated.h>
 #include <RobotAPI/libraries/aron/common/aron/framed.aron.generated.h>
 
+
+namespace IceUtil
+{
+    class Time;
+
+    void fromAron(const long& dto, IceUtil::Time& bo);
+    void toAron(long& dto, const IceUtil::Time& bo);
+
+    void fromAron(const IceUtil::Time& dto, armarx::DateTime& bo);
+    void toAron(IceUtil::Time& dto, const armarx::DateTime& bo);
+}
 namespace armarx
 {
 
     void fromAron(const arondto::PackagePath& dto, PackagePath& bo);
     void toAron(arondto::PackagePath& dto, const PackagePath& bo);
 
-    void fromAron(const long& dto, IceUtil::Time& bo);
-    void toAron(long& dto, const IceUtil::Time& bo);
-
     void fromAron(const arondto::ClockType& dto, ClockType& bo);
     void toAron(arondto::ClockType& dto, const ClockType& bo);
 
-- 
GitLab