From d31b6b8dab33e2dcf2e1d499c78a573ef98350ce Mon Sep 17 00:00:00 2001
From: Firat Yusuf Duran <uzivy@student.kit.edu>
Date: Tue, 25 Jun 2024 03:40:10 +0200
Subject: [PATCH] change type to variant and add add getTypesOfSkill

---
 .../skills/SkillManagerInterface.ice          |  5 +-
 .../libraries/skills/core/FluxioParameter.cpp |  8 +--
 .../libraries/skills/core/FluxioParameter.h   |  4 +-
 .../core/executor/FluxioCompositeExecutor.cpp | 14 ++--
 .../manager/SkillManagerComponentPlugin.cpp   | 66 +++++++++++--------
 .../manager/SkillManagerComponentPlugin.h     |  2 +
 .../SkillManagerComponentPluginUser.cpp       |  8 +++
 .../manager/SkillManagerComponentPluginUser.h |  4 ++
 8 files changed, 71 insertions(+), 40 deletions(-)

diff --git a/source/RobotAPI/interface/skills/SkillManagerInterface.ice b/source/RobotAPI/interface/skills/SkillManagerInterface.ice
index bfa5113d1..d87c9035e 100644
--- a/source/RobotAPI/interface/skills/SkillManagerInterface.ice
+++ b/source/RobotAPI/interface/skills/SkillManagerInterface.ice
@@ -141,7 +141,7 @@ module armarx
                     string id;
                     string name;
                     string description;
-                    aron::type::dto::AronObject type;
+                    aron::type::dto::GenericType type;
                     bool required;
                     bool isInput;
                     FluxioValueList values;
@@ -239,6 +239,9 @@ module armarx
                     aron::type::dto::AronObject
                     getTypes();
 
+                    aron::type::dto::AronObject
+                    getTypesOfSkill(string skillId);
+
                     optional(3) string
                     executeFluxioSkill(string skillId); // executes a fluxio skill
                     
diff --git a/source/RobotAPI/libraries/skills/core/FluxioParameter.cpp b/source/RobotAPI/libraries/skills/core/FluxioParameter.cpp
index b93835ee1..93085404a 100644
--- a/source/RobotAPI/libraries/skills/core/FluxioParameter.cpp
+++ b/source/RobotAPI/libraries/skills/core/FluxioParameter.cpp
@@ -2,7 +2,7 @@
 
 #include <ArmarXCore/core/logging/Logging.h>
 
-#include "RobotAPI/libraries/aron/core/type/variant/container/Object.h"
+#include "RobotAPI/libraries/aron/core/type/variant/Variant.h"
 #include "RobotAPI/libraries/skills/core/FluxioProfile.h"
 #include <RobotAPI/interface/skills/SkillManagerInterface.h>
 
@@ -20,7 +20,7 @@ namespace armarx
             ret.id = id;
             ret.name = name;
             ret.description = description;
-            ret.type = type->toAronObjectDTO();
+            ret.type = type->toAronDTO();
             ret.required = required;
             ret.isInput = isInput;
 
@@ -57,7 +57,7 @@ namespace armarx
         {
             name = i.name;
             description = i.description;
-            type = aron::type::Object::FromAronObjectDTO(i.type);
+            type = aron::type::Variant::FromAronDTO(*i.type);
             required = i.required;
             isInput = i.isInput;
 
@@ -101,7 +101,7 @@ namespace armarx
             ret.id = i.id;
             ret.name = i.name;
             ret.description = i.description;
-            ret.type = aron::type::Object::FromAronObjectDTO(i.type);
+            ret.type = aron::type::Variant::FromAronDTO(*i.type);
             ret.required = i.required;
             ret.isInput = i.isInput;
 
diff --git a/source/RobotAPI/libraries/skills/core/FluxioParameter.h b/source/RobotAPI/libraries/skills/core/FluxioParameter.h
index 2358a6d60..0f60bdafa 100644
--- a/source/RobotAPI/libraries/skills/core/FluxioParameter.h
+++ b/source/RobotAPI/libraries/skills/core/FluxioParameter.h
@@ -3,8 +3,8 @@
 #include <list>
 #include <string>
 
+#include "RobotAPI/libraries/aron/core/type/variant/Variant.h"
 #include <RobotAPI/interface/skills/SkillManagerInterface.h>
-#include "RobotAPI/libraries/aron/core/type/variant/container/Object.h"
 
 
 #include "FluxioValue.h"
@@ -18,7 +18,7 @@ namespace armarx
             std::string id;
             std::string name;
             std::string description = "";
-            aron::type::ObjectPtr type = std::make_shared<aron::type::Object>();
+            aron::type::VariantPtr type;
             bool required = true;
             bool isInput;
             std::list<FluxioValue> values;
diff --git a/source/RobotAPI/libraries/skills/core/executor/FluxioCompositeExecutor.cpp b/source/RobotAPI/libraries/skills/core/executor/FluxioCompositeExecutor.cpp
index ccbe84769..d1c96ee4a 100644
--- a/source/RobotAPI/libraries/skills/core/executor/FluxioCompositeExecutor.cpp
+++ b/source/RobotAPI/libraries/skills/core/executor/FluxioCompositeExecutor.cpp
@@ -187,9 +187,9 @@ namespace armarx::skills
         }
 
         // make sure it is an event parameter
-        if (parameterNode->parameterPtr->type->getObjectName() != "Event")
+        if (parameterNode->parameterPtr->type->getShortName() != "Event")
         {
-            ARMARX_WARNING << "Unexpected parameter type " << parameterNode->parameterPtr->type->getObjectName();
+            ARMARX_WARNING << "Unexpected parameter type " << parameterNode->parameterPtr->type->getShortName();
             setStatus(skills::SkillStatus::Failed);
             return;
         }
@@ -296,7 +296,7 @@ namespace armarx::skills
             subSkillNode->skillPtr->parameters.end(),
             [&outputEventName](const std::pair<std::string, skills::FluxioParameter>& param)
             {
-                return (param.second.type->getObjectName() == "Event" && !param.second.isInput &&
+                return (param.second.type->getShortName() == "Event" && !param.second.isInput &&
                         param.second.name == outputEventName);
             });
 
@@ -551,7 +551,7 @@ namespace armarx::skills
             std::find_if(skill->parameters.begin(),
                          skill->parameters.end(),
                          [](const std::pair<std::string, skills::FluxioParameter>& param) {
-                             return (param.second.type->getObjectName() == "Event" && param.second.isInput &&
+                             return (param.second.type->getShortName() == "Event" && param.second.isInput &&
                                      param.second.name == "Start");
                          });
 
@@ -604,7 +604,7 @@ namespace armarx::skills
                          skill->parameters.end(),
                          [](const std::pair<std::string, skills::FluxioParameter>& param)
                          {
-                             return (param.second.type->getObjectName() == "Event" && !param.second.isInput &&
+                             return (param.second.type->getShortName() == "Event" && !param.second.isInput &&
                                      param.second.name == "Succeeded");
                          });
         const auto& outputParamsFailed =
@@ -612,7 +612,7 @@ namespace armarx::skills
                          skill->parameters.end(),
                          [](const std::pair<std::string, skills::FluxioParameter>& param)
                          {
-                             return (param.second.type->getObjectName() == "Event" && !param.second.isInput &&
+                             return (param.second.type->getShortName() == "Event" && !param.second.isInput &&
                                      param.second.name == "Failed");
                          });
         const auto& outputParamsAborted =
@@ -620,7 +620,7 @@ namespace armarx::skills
                          skill->parameters.end(),
                          [](const std::pair<std::string, skills::FluxioParameter>& param)
                          {
-                             return (param.second.type->getObjectName() == "Event" && !param.second.isInput &&
+                             return (param.second.type->getShortName() == "Event" && !param.second.isInput &&
                                      param.second.name == "Aborted");
                          });
 
diff --git a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp
index be0755ed5..f0966583a 100644
--- a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp
+++ b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp
@@ -833,10 +833,7 @@ namespace armarx::plugins
             p.name = name;
             // Full type name may contain some extra info like dimensions etc.
             p.description = typeInfo->getFullName();
-            const auto& type = std::make_shared<aron::type::Object>();
-            type->setObjectName(typeInfo->getShortName());
-            type->addMemberType("typeInfo", typeInfo);
-            p.type = type;
+            p.type = typeInfo;
             p.required = (typeInfo->getMaybe() == 0);
             p.isInput = isInput;
             p.values = {}; // these are inserted later
@@ -914,14 +911,14 @@ namespace armarx::plugins
             }
 
             s.parameters = {};
+            const auto& eventType = std::make_shared<aron::type::Object>();
+            eventType->setObjectName("Event");
 
             // add default control flow parameters
             skills::FluxioParameter start;
             start.name = "Start";
-            const auto& startType = std::make_shared<aron::type::Object>();
-            startType->setObjectName("Event");
-            start.type = startType;
-            const auto& startIdStr = start.name + start.type->getObjectName() + "isInput";
+            start.type = eventType;
+            const auto& startIdStr = start.name + start.type->getFullName() + "isInput";
             start.id = boost::uuids::to_string(createUuidWithString(startIdStr, id));
             start.description = "Start the skill";
             start.required = true;
@@ -929,10 +926,9 @@ namespace armarx::plugins
 
             skills::FluxioParameter succeeded;
             succeeded.name = "Succeeded";
-            const auto& succeededType = std::make_shared<aron::type::Object>();
-            succeededType->setObjectName("Event");
-            succeeded.type = succeededType;
-            const auto& successIdStr = succeeded.name + succeeded.type->getObjectName() + "isOutput";
+            succeeded.type = eventType;
+            const auto& successIdStr =
+                succeeded.name + succeeded.type->getFullName() + "isOutput";
             succeeded.id = boost::uuids::to_string(createUuidWithString(successIdStr, id));
             succeeded.description = "Skill has been executed successfully";
             succeeded.required = false;
@@ -940,10 +936,8 @@ namespace armarx::plugins
 
             skills::FluxioParameter failed;
             failed.name = "Failed";
-            const auto& failedType = std::make_shared<aron::type::Object>();
-            failedType->setObjectName("Event");
-            failed.type = failedType;
-            const auto& failedIdStr = failed.name + failed.type->getObjectName() + "isOutput";
+            failed.type = eventType;
+            const auto& failedIdStr = failed.name + failed.type->getShortName() + "isOutput";
             failed.id = boost::uuids::to_string(createUuidWithString(failedIdStr, id));
             failed.description = "Skill has failed";
             failed.required = false;
@@ -951,10 +945,8 @@ namespace armarx::plugins
 
             skills::FluxioParameter aborted;
             aborted.name = "Aborted";
-            const auto& abortedType = std::make_shared<aron::type::Object>();
-            abortedType->setObjectName("Event");
-            aborted.type = abortedType;
-            const auto& abortedIdStr = aborted.name + aborted.type->getObjectName() + "isOutput";
+            aborted.type = eventType;
+            const auto& abortedIdStr = aborted.name + aborted.type->getShortName() + "isOutput";
             aborted.id = boost::uuids::to_string(createUuidWithString(abortedIdStr, id));
             aborted.description = "Skill has been aborted";
             aborted.required = false;
@@ -1180,7 +1172,7 @@ namespace armarx::plugins
             return std::nullopt;
         }
 
-        if (skill.id == "")
+        if (skill.id.empty())
         {
             // its a new skill, its a new world, ...
             skill.id = IceUtil::generateUUID();
@@ -1317,18 +1309,40 @@ namespace armarx::plugins
     SkillManagerComponentPlugin::getTypes()
     {
         auto ret = std::make_shared<aron::type::Object>();
-        const auto& skillDescriptions = getSkillDescriptions();
+        const std::vector<skills::FluxioSkill>& skills = getSkillList();
 
-        for (const auto& [skillId, skillDescription] : skillDescriptions)
+        for (const auto& skill : skills)
         {
-            if (skillDescription.parametersType == nullptr)
+            const auto& skillTypes = std::make_shared<aron::type::Object>();
+            for (const auto& [parameterId, parameter] : skill.parameters)
             {
-                continue;
+                skillTypes->addMemberType(parameterId, parameter.type);
             }
+            skillTypes->setObjectName(skill.id);
+            ret->addMemberType(skill.id, skillTypes);
+        }
+        ret->setObjectName("SkillTypes");
+        return ret;
+    }
+
+    aron::type::ObjectPtr
+    SkillManagerComponentPlugin::getTypesOfSkill(const std::string& skillId)
+    {
+        const std::optional<skills::FluxioSkill>& opt = getSkill(skillId);
+        if (!opt.has_value())
+        {
+            ARMARX_WARNING << "Skill with id '" << skillId << "' not found.";
+            return nullptr;
+        }
+        const skills::FluxioSkill& skill = opt.value();
 
-            ret->addMemberType(skillId.skillName, skillDescription.parametersType);
+        auto ret = std::make_shared<aron::type::Object>();
+        for (const auto& [parameterId, parameter] : skill.parameters)
+        {
+            ret->addMemberType(parameterId, parameter.type);
         }
         ret->setObjectName("SkillTypes");
         return ret;
     }
+
 } // namespace armarx::plugins
diff --git a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.h b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.h
index fb8c62e50..f9f543d6a 100644
--- a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.h
+++ b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.h
@@ -80,6 +80,8 @@ namespace armarx::plugins
         //** Fluxio related methods **//
         //****************************//
 
+        aron::type::ObjectPtr getTypesOfSkill(const std::string& skillId);
+
         aron::type::ObjectPtr getTypes();
 
         skills::FluxioExecutor* executeFluxioSkill(const std::string& skillId,
diff --git a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPluginUser.cpp b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPluginUser.cpp
index 06c0ea594..5b6e9ef4f 100644
--- a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPluginUser.cpp
+++ b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPluginUser.cpp
@@ -157,6 +157,14 @@ namespace armarx
     //** Fluxio related methods **//
     //****************************//
 
+    aron::type::dto::AronObjectPtr
+    SkillManagerComponentPluginUser::getTypesOfSkill(const std::string& skillId,
+                                                     const Ice::Current& current)
+    {
+        const auto res = this->plugin->getTypesOfSkill(skillId);
+        return res->toAronObjectDTO();
+    }
+
     aron::type::dto::AronObjectPtr
     SkillManagerComponentPluginUser::getTypes(const Ice::Current& current)
     {
diff --git a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPluginUser.h b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPluginUser.h
index a96866f59..fd960b903 100644
--- a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPluginUser.h
+++ b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPluginUser.h
@@ -1,5 +1,6 @@
 #pragma once
 
+#include <memory>
 #include <Ice/Current.h>
 
 #include <RobotAPI/interface/aron/Aron.h>
@@ -73,6 +74,9 @@ namespace armarx
 
         aron::type::dto::AronObjectPtr getTypes(const Ice::Current& current) override;
 
+        aron::type::dto::AronObjectPtr getTypesOfSkill(const std::string& skillId,
+                                                       const Ice::Current& current) override;
+
         IceUtil::Optional<std::string> executeFluxioSkill(const std::string& skillId,
                                                           const Ice::Current& current) override;
 
-- 
GitLab