diff --git a/source/RobotAPI/libraries/skills/core/FluxioProvider.cpp b/source/RobotAPI/libraries/skills/core/FluxioProvider.cpp index 4151de3b440ec1d10a11aac4d8f40e70e3742197..65628a8d30a6094640066d9a4857b6112972b51a 100644 --- a/source/RobotAPI/libraries/skills/core/FluxioProvider.cpp +++ b/source/RobotAPI/libraries/skills/core/FluxioProvider.cpp @@ -1,5 +1,8 @@ #include "FluxioProvider.h" +#include <experimental/memory> +#include <memory> + #include <ArmarXCore/core/logging/Logging.h> namespace armarx @@ -28,7 +31,7 @@ namespace armarx return ret; } - FluxioProvider* + std::experimental::observer_ptr<FluxioProvider> FluxioProvider::FromFluxioIdentificatorIce( const manager::dto::FluxioIdentificator& i, std::map<std::string, FluxioProvider>& providersMap) @@ -41,7 +44,7 @@ namespace armarx return nullptr; } - return &(providersMap[providerIt->first]); + return std::experimental::make_observer(&(providersMap[providerIt->first])); } FluxioProvider diff --git a/source/RobotAPI/libraries/skills/core/FluxioProvider.h b/source/RobotAPI/libraries/skills/core/FluxioProvider.h index 500affcea1a1e81fa8bfd79bce0601ddc03c1d31..20d2d97d24cbf6094c91139cb812e506d454fae7 100644 --- a/source/RobotAPI/libraries/skills/core/FluxioProvider.h +++ b/source/RobotAPI/libraries/skills/core/FluxioProvider.h @@ -1,5 +1,6 @@ #pragma once +#include <experimental/memory> #include <string> #include <RobotAPI/interface/skills/SkillManagerInterface.h> @@ -16,7 +17,7 @@ namespace armarx manager::dto::FluxioProvider toManagerIce() const; manager::dto::FluxioIdentificator toFluxioIdentificatorIce() const; - static FluxioProvider* + static std::experimental::observer_ptr<FluxioProvider> FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator& i, std::map<std::string, FluxioProvider>& providersMap); static FluxioProvider FromIce(const manager::dto::FluxioProvider& i); diff --git a/source/RobotAPI/libraries/skills/core/FluxioSkill.cpp b/source/RobotAPI/libraries/skills/core/FluxioSkill.cpp index c1031c988acae2c24f45130019e17d1afb11e192..14727b45f95712cffbabf47eb5eb3af2856a32c4 100644 --- a/source/RobotAPI/libraries/skills/core/FluxioSkill.cpp +++ b/source/RobotAPI/libraries/skills/core/FluxioSkill.cpp @@ -21,31 +21,6 @@ namespace armarx { namespace skills { - // FluxioSkill::FluxioSkill( - // std::string& id, - // std::string& name, - // std::string& description, - // std::string& lastChanged, - // bool executable, - // bool native, - // FluxioProvider* skillProviderPtr, - // std::map<std::string, FluxioParameter> parameters, - // std::map<const std::string, const std::unique_ptr<FluxioNode>>&& nodes, - // std::list<FluxioEdge> edges) : - // - // id(id), - // name(name), - // description(description), - // lastChanged(lastChanged), - // executable(executable), - // native(native), - // skillProviderPtr(skillProviderPtr), - // parameters(std::move(parameters)), - // nodes(nodes), - // edges(std::move(edges)) - // { - // } - std::optional<manager::dto::FluxioSkill> FluxioSkill::toManagerIce() const { @@ -152,8 +127,9 @@ namespace armarx description = i.description; lastChanged = armarx::DateTime::Now().toDateTimeString(); executable = i.executable; - skillProviderPtr = + const auto skillProviderPtr = skills::FluxioProvider::FromFluxioIdentificatorIce(i.skillProviderId, providersMap); + this->skillProviderPtr = skillProviderPtr; // parameters // create a parameter dto map for convenience diff --git a/source/RobotAPI/libraries/skills/core/FluxioSkill.h b/source/RobotAPI/libraries/skills/core/FluxioSkill.h index db08d5617ac4226ab4843073329eee55da392e7d..8bb4afc2679e753c130a104900bdf515bbbfd2e2 100644 --- a/source/RobotAPI/libraries/skills/core/FluxioSkill.h +++ b/source/RobotAPI/libraries/skills/core/FluxioSkill.h @@ -25,7 +25,7 @@ namespace armarx bool executable = false; // TODO: change from explicit to implicit storing of executable state bool native; - FluxioProvider* skillProviderPtr; + std::experimental::observer_ptr<const FluxioProvider> skillProviderPtr; std::map<std::string, FluxioParameter> parameters; std::map<const std::string, const std::unique_ptr<FluxioNode>> nodes; std::list<FluxioEdge> edges; diff --git a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp index 641a603a0c10f4508f6f406c4a6982d41bef1a30..aa913ade84488afe0674d55a1ba6c3f81b13dd78 100644 --- a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp +++ b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.cpp @@ -805,12 +805,17 @@ namespace armarx::plugins fluxioDC.providers.find(boost::uuids::to_string(providerId)); if (providersEntry != fluxioDC.providers.end()) { - s.skillProviderPtr = &(providersEntry->second); + s.skillProviderPtr = std::experimental::make_observer(&(providersEntry->second)); } else { - const auto& p = addFluxioProvider(skillId.providerId->providerName); - s.skillProviderPtr = &fluxioDC.providers[p.id]; + const auto p = addFluxioProvider(skillId.providerId->providerName); + if (p == nullptr) + { + ARMARX_WARNING << "Failed to add provider with name '" + << skillId.providerId->providerName << "'."; + } + s.skillProviderPtr = p; } s.parameters = {}; @@ -908,6 +913,8 @@ namespace armarx::plugins return std::experimental::make_observer(&skillsEntry->second); } + ARMARX_WARNING << "Skill with id '" << id << "' not found."; + return nullptr; } @@ -981,7 +988,7 @@ namespace armarx::plugins } } - skills::FluxioProvider& + std::experimental::observer_ptr<const skills::FluxioProvider> SkillManagerComponentPlugin::addFluxioProvider(const std::string& name) { const std::string& providerId = boost::uuids::to_string(createUuidWithString(name)); @@ -989,7 +996,7 @@ namespace armarx::plugins if (fluxioDC.providers.find(providerId) != fluxioDC.providers.end()) { ARMARX_WARNING << "Provider with name '" << name << "' already exists."; - return fluxioDC.providers[providerId]; + return std::experimental::make_observer(&fluxioDC.providers[providerId]); } skills::FluxioProvider p; @@ -997,7 +1004,7 @@ namespace armarx::plugins p.name = name; fluxioDC.providers[p.id] = p; - return fluxioDC.providers[p.id]; + return std::experimental::make_observer(&fluxioDC.providers[p.id]); } std::vector<std::experimental::observer_ptr<const skills::FluxioProvider>> @@ -1067,12 +1074,13 @@ namespace armarx::plugins std::experimental::observer_ptr<skills::FluxioSkill> SkillManagerComponentPlugin::addSkillToProvider(const std::string& userId, const std::string& providerId, - skills::FluxioSkill& skill) + skills::FluxioSkill&& skill) { // check if the provider exists const auto& providerIt = fluxioDC.providers.find(providerId); if (providerIt == fluxioDC.providers.end()) { + ARMARX_WARNING << "Provider with id '" << providerId << "' not found."; return nullptr; } @@ -1135,12 +1143,13 @@ namespace armarx::plugins skill.lastChanged = armarx::DateTime::Now().toDateTimeString(); // store in data collector - fluxioDC.skills.emplace(skill.id, std::move(skill)); + const auto skillId = skill.id; + fluxioDC.skills.emplace(skillId, std::move(skill)); // set mutex setEditFluxioSkillMutex(true, userId, skill.id); - return std::experimental::make_observer(&fluxioDC.skills[skill.id]); + return std::experimental::make_observer(&(fluxioDC.skills[skillId])); } bool // TODO: add armarx info messages diff --git a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.h b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.h index 5fa8ed804a93f2df224611e0d37f0098140b41bc..85fc56af154f5e2fc1f0239f34f9390eba1585cc 100644 --- a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.h +++ b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPlugin.h @@ -109,7 +109,8 @@ namespace armarx::plugins std::vector<std::experimental::observer_ptr<const skills::FluxioProvider>> getProviderList(); - skills::FluxioProvider& addFluxioProvider(const std::string& name); + std::experimental::observer_ptr<const skills::FluxioProvider> + addFluxioProvider(const std::string& name); std::optional<skills::FluxioProvider> getProvider(const std::string& id); @@ -119,7 +120,7 @@ namespace armarx::plugins std::experimental::observer_ptr<skills::FluxioSkill> addSkillToProvider(const std::string& userId, const std::string& providerId, - skills::FluxioSkill& skill); + skills::FluxioSkill&& skill); private: struct FluxioDataCollector diff --git a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPluginUser.cpp b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPluginUser.cpp index 9df07a129e45d8fcbcf2d6bb5993a02831b86db8..bfe66b33510ec281c82da4b46e9bf46955825ff6 100644 --- a/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPluginUser.cpp +++ b/source/RobotAPI/libraries/skills/manager/SkillManagerComponentPluginUser.cpp @@ -425,18 +425,25 @@ namespace armarx return {}; } - auto s = this->plugin->addSkillToProvider(userId, providerId, *skillBO); - if (s != nullptr) + auto& skillReleesed = *skillBO.release(); + + const auto s = + this->plugin->addSkillToProvider(userId, providerId, std::move(skillReleesed)); + if (s == nullptr) { - const auto& ret = s->toManagerIce(); - if (ret.has_value()) - { - return *ret; - } + ARMARX_WARNING << "Skill with id " << skill.id + << " could not be added to provider with id " << providerId; + return {}; } + auto test = (s->skillProviderPtr == nullptr) ? "nullptr" : s->skillProviderPtr->id; + const auto& ret = s->toManagerIce(); - ARMARX_WARNING << "Skill with id " << skill.id << " could not be added to provider with id " - << providerId; - return {}; + if (!ret.has_value()) + { + ARMARX_WARNING << "Skill with id " << skill.id << " could not be converted"; + return {}; + } + + return *ret; } } // namespace armarx