From 1e42d3c944b4a1484c6c752b1dcf6fac8c4c2e44 Mon Sep 17 00:00:00 2001
From: Fabian Peller <fabian.peller-konrad@kit.edu>
Date: Wed, 24 May 2023 14:51:45 +0200
Subject: [PATCH] add aron marshalling warnings.

---
 .../aron/core/data/variant/Factory.cpp        | 56 ++++++++---
 .../aron/core/type/variant/Factory.cpp        | 99 ++++++++++++++-----
 2 files changed, 118 insertions(+), 37 deletions(-)

diff --git a/source/RobotAPI/libraries/aron/core/data/variant/Factory.cpp b/source/RobotAPI/libraries/aron/core/data/variant/Factory.cpp
index f458e3d99..3b7418fe5 100644
--- a/source/RobotAPI/libraries/aron/core/data/variant/Factory.cpp
+++ b/source/RobotAPI/libraries/aron/core/data/variant/Factory.cpp
@@ -33,7 +33,8 @@ namespace armarx::aron::data
 {
 
     // Access method
-    std::unique_ptr<data::Variant> VariantFactory::create(const data::dto::GenericDataPtr& aron, const Path& path) const
+    std::unique_ptr<data::Variant>
+    VariantFactory::create(const data::dto::GenericDataPtr& aron, const Path& path) const
     {
         // if aron is null ==> e.g. optional or ptr not set
         if (!aron)
@@ -41,20 +42,47 @@ namespace armarx::aron::data
             return nullptr;
         };
 
+        // compare versions
+        auto aronVersion = aron->VERSION;
+        if (aronVersion != armarx::aron::VERSION)
+        {
+            ARMARX_WARNING
+                << "Found inconsistencies in aron versions. This may lead to ice marshalling "
+                   "exceptions. Please make sure to update the sender and receiver packages. "
+                << aronVersion << " != " << armarx::aron::VERSION;
+        }
+
         auto descriptor = data::Aron2Descriptor(*aron);
-        switch(descriptor)
+        switch (descriptor)
         {
-            case data::Descriptor::LIST: return std::make_unique<data::List>(data::dto::ListPtr::dynamicCast(aron), path);
-            case data::Descriptor::DICT: return std::make_unique<data::Dict>(data::dto::DictPtr::dynamicCast(aron), path);
-            case data::Descriptor::NDARRAY: return std::make_unique<data::NDArray>(data::dto::NDArrayPtr::dynamicCast(aron), path);
-            case data::Descriptor::INT: return std::make_unique<data::Int>(data::dto::AronIntPtr::dynamicCast(aron), path);
-            case data::Descriptor::LONG: return std::make_unique<data::Long>(data::dto::AronLongPtr::dynamicCast(aron), path);
-            case data::Descriptor::FLOAT: return std::make_unique<data::Float>(data::dto::AronFloatPtr::dynamicCast(aron), path);
-            case data::Descriptor::DOUBLE: return std::make_unique<data::Double>(data::dto::AronDoublePtr::dynamicCast(aron), path);
-            case data::Descriptor::STRING: return std::make_unique<data::String>(data::dto::AronStringPtr::dynamicCast(aron), path);
-            case data::Descriptor::BOOL: return std::make_unique<data::Bool>(data::dto::AronBoolPtr::dynamicCast(aron), path);
-            case data::Descriptor::UNKNOWN: break;
+            case data::Descriptor::LIST:
+                return std::make_unique<data::List>(data::dto::ListPtr::dynamicCast(aron), path);
+            case data::Descriptor::DICT:
+                return std::make_unique<data::Dict>(data::dto::DictPtr::dynamicCast(aron), path);
+            case data::Descriptor::NDARRAY:
+                return std::make_unique<data::NDArray>(data::dto::NDArrayPtr::dynamicCast(aron),
+                                                       path);
+            case data::Descriptor::INT:
+                return std::make_unique<data::Int>(data::dto::AronIntPtr::dynamicCast(aron), path);
+            case data::Descriptor::LONG:
+                return std::make_unique<data::Long>(data::dto::AronLongPtr::dynamicCast(aron),
+                                                    path);
+            case data::Descriptor::FLOAT:
+                return std::make_unique<data::Float>(data::dto::AronFloatPtr::dynamicCast(aron),
+                                                     path);
+            case data::Descriptor::DOUBLE:
+                return std::make_unique<data::Double>(data::dto::AronDoublePtr::dynamicCast(aron),
+                                                      path);
+            case data::Descriptor::STRING:
+                return std::make_unique<data::String>(data::dto::AronStringPtr::dynamicCast(aron),
+                                                      path);
+            case data::Descriptor::BOOL:
+                return std::make_unique<data::Bool>(data::dto::AronBoolPtr::dynamicCast(aron),
+                                                    path);
+            case data::Descriptor::UNKNOWN:
+                break;
         }
-        throw error::ValueNotValidException(__PRETTY_FUNCTION__, "", std::to_string((int) descriptor), path);
+        throw error::ValueNotValidException(
+            __PRETTY_FUNCTION__, "", std::to_string((int)descriptor), path);
     }
-}
+} // namespace armarx::aron::data
diff --git a/source/RobotAPI/libraries/aron/core/type/variant/Factory.cpp b/source/RobotAPI/libraries/aron/core/type/variant/Factory.cpp
index 405a5e748..fccc4e130 100644
--- a/source/RobotAPI/libraries/aron/core/type/variant/Factory.cpp
+++ b/source/RobotAPI/libraries/aron/core/type/variant/Factory.cpp
@@ -32,32 +32,85 @@
 namespace armarx::aron::type
 {
     // Access method
-    std::unique_ptr<type::Variant> VariantFactory::create(const type::dto::GenericType& aron, const Path& path) const
+    std::unique_ptr<type::Variant>
+    VariantFactory::create(const type::dto::GenericType& aron, const Path& path) const
     {
+
+        auto aronVersion = aron.VERSION;
+        if (aronVersion != armarx::aron::VERSION)
+        {
+            ARMARX_WARNING
+                << "Found inconsistencies in aron versions. This may lead to ice marshalling "
+                   "exceptions. Please make sure to update the sender and receiver packages. "
+                << aronVersion << " != " << armarx::aron::VERSION;
+        }
+
         auto descriptor = type::Aron2Descriptor(aron);
-        switch(descriptor)
+        switch (descriptor)
         {
-            case type::Descriptor::LIST: return std::make_unique<type::List>(dynamic_cast<const type::dto::List&>(aron), path);
-            case type::Descriptor::DICT: return std::make_unique<type::Dict>(dynamic_cast<const type::dto::Dict&>(aron), path);
-            case type::Descriptor::PAIR: return std::make_unique<type::Pair>(dynamic_cast<const type::dto::Pair&>(aron), path);
-            case type::Descriptor::TUPLE: return std::make_unique<type::Tuple>(dynamic_cast<const type::dto::Tuple&>(aron), path);
-            case type::Descriptor::OBJECT: return std::make_unique<type::Object>(dynamic_cast<const type::dto::AronObject&>(aron), path);
-            case type::Descriptor::NDARRAY: return std::make_unique<type::NDArray>(dynamic_cast<const type::dto::NDArray&>(aron), path);
-            case type::Descriptor::MATRIX: return std::make_unique<type::Matrix>(dynamic_cast<const type::dto::Matrix&>(aron), path);
-            case type::Descriptor::IMAGE: return std::make_unique<type::Image>(dynamic_cast<const type::dto::Image&>(aron), path);
-            case type::Descriptor::POINTCLOUD: return std::make_unique<type::PointCloud>(dynamic_cast<const type::dto::PointCloud&>(aron), path);
-            case type::Descriptor::QUATERNION: return std::make_unique<type::Quaternion>(dynamic_cast<const type::dto::Quaternion&>(aron), path);
-            case type::Descriptor::INT_ENUM: return std::make_unique<type::IntEnum>(dynamic_cast<const type::dto::IntEnum&>(aron), path);
-            case type::Descriptor::INT: return std::make_unique<type::Int>(dynamic_cast<const type::dto::AronInt&>(aron), path);
-            case type::Descriptor::LONG: return std::make_unique<type::Long>(dynamic_cast<const type::dto::AronLong&>(aron), path);
-            case type::Descriptor::FLOAT: return std::make_unique<type::Float>(dynamic_cast<const type::dto::AronFloat&>(aron), path);
-            case type::Descriptor::DOUBLE: return std::make_unique<type::Double>(dynamic_cast<const type::dto::AronDouble&>(aron), path);
-            case type::Descriptor::STRING: return std::make_unique<type::String>(dynamic_cast<const type::dto::AronString&>(aron), path);
-            case type::Descriptor::BOOL: return std::make_unique<type::Bool>(dynamic_cast<const type::dto::AronBool&>(aron), path);
-            case type::Descriptor::ANY_OBJECT: return std::make_unique<type::AnyObject>(dynamic_cast<const type::dto::AnyObject&>(aron), path);
-            case type::Descriptor::UNKNOWN: break;
+            case type::Descriptor::LIST:
+                return std::make_unique<type::List>(dynamic_cast<const type::dto::List&>(aron),
+                                                    path);
+            case type::Descriptor::DICT:
+                return std::make_unique<type::Dict>(dynamic_cast<const type::dto::Dict&>(aron),
+                                                    path);
+            case type::Descriptor::PAIR:
+                return std::make_unique<type::Pair>(dynamic_cast<const type::dto::Pair&>(aron),
+                                                    path);
+            case type::Descriptor::TUPLE:
+                return std::make_unique<type::Tuple>(dynamic_cast<const type::dto::Tuple&>(aron),
+                                                     path);
+            case type::Descriptor::OBJECT:
+                return std::make_unique<type::Object>(
+                    dynamic_cast<const type::dto::AronObject&>(aron), path);
+            case type::Descriptor::NDARRAY:
+                return std::make_unique<type::NDArray>(
+                    dynamic_cast<const type::dto::NDArray&>(aron), path);
+            case type::Descriptor::MATRIX:
+                return std::make_unique<type::Matrix>(dynamic_cast<const type::dto::Matrix&>(aron),
+                                                      path);
+            case type::Descriptor::IMAGE:
+                return std::make_unique<type::Image>(dynamic_cast<const type::dto::Image&>(aron),
+                                                     path);
+            case type::Descriptor::POINTCLOUD:
+                return std::make_unique<type::PointCloud>(
+                    dynamic_cast<const type::dto::PointCloud&>(aron), path);
+            case type::Descriptor::QUATERNION:
+                return std::make_unique<type::Quaternion>(
+                    dynamic_cast<const type::dto::Quaternion&>(aron), path);
+            case type::Descriptor::INT_ENUM:
+                return std::make_unique<type::IntEnum>(
+                    dynamic_cast<const type::dto::IntEnum&>(aron), path);
+            case type::Descriptor::INT:
+                return std::make_unique<type::Int>(dynamic_cast<const type::dto::AronInt&>(aron),
+                                                   path);
+            case type::Descriptor::LONG:
+                return std::make_unique<type::Long>(dynamic_cast<const type::dto::AronLong&>(aron),
+                                                    path);
+            case type::Descriptor::FLOAT:
+                return std::make_unique<type::Float>(
+                    dynamic_cast<const type::dto::AronFloat&>(aron), path);
+            case type::Descriptor::DOUBLE:
+                return std::make_unique<type::Double>(
+                    dynamic_cast<const type::dto::AronDouble&>(aron), path);
+            case type::Descriptor::STRING:
+                return std::make_unique<type::String>(
+                    dynamic_cast<const type::dto::AronString&>(aron), path);
+            case type::Descriptor::BOOL:
+                return std::make_unique<type::Bool>(dynamic_cast<const type::dto::AronBool&>(aron),
+                                                    path);
+            case type::Descriptor::ANY_OBJECT:
+                return std::make_unique<type::AnyObject>(
+                    dynamic_cast<const type::dto::AnyObject&>(aron), path);
+            case type::Descriptor::UNKNOWN:
+                break;
         }
-        throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Got an unknown descriptor", std::to_string((int) descriptor) + " aka " + defaultconversion::string::Descriptor2String.at(descriptor), path);
+        throw error::ValueNotValidException(
+            __PRETTY_FUNCTION__,
+            "Got an unknown descriptor",
+            std::to_string((int)descriptor) + " aka " +
+                defaultconversion::string::Descriptor2String.at(descriptor),
+            path);
     }
 
-}
+} // namespace armarx::aron::type
-- 
GitLab