Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • sw/armarx/robot-api
  • uwkce_singer/robot-api
  • untcg_hofmann/robot-api
  • ulqba_korosakov/RobotAPI
4 results
Show changes
Commits on Source (5)
Showing
with 335 additions and 361 deletions
#include "FluxioEdge.h"
#include <memory>
#include <optional>
#include <ArmarXCore/core/logging/Logging.h>
......@@ -35,14 +36,14 @@ namespace armarx
}
std::optional<FluxioEdge>
FluxioEdge::FromIce(const manager::dto::FluxioEdge& i,
std::map<std::string, FluxioNode*>& nodesMap,
std::map<std::string, FluxioParameter>& parametersMap)
FluxioEdge::FromIce(
const manager::dto::FluxioEdge& i,
const std::map<const std::string, const std::unique_ptr<FluxioNode>>& nodesMap,
const std::map<std::string, FluxioParameter>& parametersMap)
{
skills::FluxioNode* fromNodePtr =
const auto& fromNodePtr =
FluxioNode::FromFluxioIdentificatorIce(i.fromNodeId, nodesMap);
skills::FluxioNode* toNodePtr =
FluxioNode::FromFluxioIdentificatorIce(i.toNodeId, nodesMap);
const auto& toNodePtr = FluxioNode::FromFluxioIdentificatorIce(i.toNodeId, nodesMap);
if (fromNodePtr == nullptr || toNodePtr == nullptr)
{
......@@ -50,25 +51,24 @@ namespace armarx
return std::nullopt;
}
skills::FluxioParameter* fromParameterPtr = nullptr;
skills::FluxioParameter* toParameterPtr = nullptr;
std::experimental::observer_ptr<const skills::FluxioParameter> fromParameterPtr =
nullptr;
std::experimental::observer_ptr<const skills::FluxioParameter> toParameterPtr = nullptr;
// Check if fromNode is a SubSkillNode
if (fromNodePtr->nodeType == FluxioNodeType::SUBSKILL)
{
const auto* subSkillNodePtr = dynamic_cast<FluxioSubSkillNode*>(fromNodePtr);
try
{
auto& subSkillParams = subSkillNodePtr->skillPtr->parameters;
fromParameterPtr = FluxioParameter::FromFluxioIdentificatorIce(
i.fromParameterId, subSkillParams);
}
catch (...)
const auto* subSkillNodePtr =
dynamic_cast<const FluxioSubSkillNode*>(fromNodePtr.get());
if (subSkillNodePtr == nullptr)
{
ARMARX_WARNING << "Failed to retrieve parameters of skill in subskill node";
ARMARX_WARNING << "Failed to cast node to sub skill node";
return std::nullopt;
}
const auto& subSkillParams = subSkillNodePtr->skillPtr->parameters;
fromParameterPtr =
FluxioParameter::FromFluxioIdentificatorIce(i.fromParameterId, subSkillParams);
}
else if (fromNodePtr->nodeType == FluxioNodeType::PARAMETER)
{
......@@ -77,7 +77,8 @@ namespace armarx
}
else if (fromNodePtr->nodeType == FluxioNodeType::CONTROL)
{
auto* controlNodePtr = dynamic_cast<FluxioControlNode*>(fromNodePtr);
const auto* controlNodePtr =
dynamic_cast<const FluxioControlNode*>(fromNodePtr.get());
if (controlNodePtr == nullptr)
{
ARMARX_WARNING << "Failed to cast node to control node";
......@@ -96,23 +97,22 @@ namespace armarx
// Check if toNode is a SubSkillNode
if (toNodePtr->nodeType == FluxioNodeType::SUBSKILL)
{
const auto* subSkillNodePtr = dynamic_cast<FluxioSubSkillNode*>(toNodePtr);
try
{
auto& subSkillParams = subSkillNodePtr->skillPtr->parameters;
toParameterPtr = FluxioParameter::FromFluxioIdentificatorIce(i.toParameterId,
subSkillParams);
}
catch (...)
const auto* subSkillNodePtr =
dynamic_cast<const FluxioSubSkillNode*>(toNodePtr.get());
if (subSkillNodePtr == nullptr)
{
ARMARX_WARNING << "Failed to retrieve parameters of skill in subskill node";
ARMARX_WARNING << "Failed to cast node to sub skill node";
return std::nullopt;
}
const auto& subSkillParams = subSkillNodePtr->skillPtr->parameters;
toParameterPtr =
FluxioParameter::FromFluxioIdentificatorIce(i.toParameterId, subSkillParams);
}
else if (toNodePtr->nodeType == FluxioNodeType::CONTROL)
{
auto* controlNodePtr = dynamic_cast<FluxioControlNode*>(toNodePtr);
const auto* controlNodePtr =
dynamic_cast<const FluxioControlNode*>(toNodePtr.get());
if (controlNodePtr == nullptr)
{
ARMARX_WARNING << "Failed to cast node to control node";
......@@ -141,9 +141,9 @@ namespace armarx
FluxioEdge ret;
ret.fromNodePtr = fromNodePtr;
ret.fromNodePtr = std::experimental::make_observer(fromNodePtr.get());
ret.fromParameterPtr = fromParameterPtr;
ret.toNodePtr = toNodePtr;
ret.toNodePtr = std::experimental::make_observer(toNodePtr.get());
ret.toParameterPtr = toParameterPtr;
return ret;
......
#pragma once
#include <experimental/memory>
#include <RobotAPI/interface/skills/SkillManagerInterface.h>
#include "FluxioNode.h"
......@@ -11,17 +13,17 @@ namespace armarx
{
struct FluxioEdge
{
FluxioNode* fromNodePtr;
FluxioParameter* fromParameterPtr;
FluxioNode* toNodePtr;
FluxioParameter* toParameterPtr;
std::experimental::observer_ptr<const FluxioNode> fromNodePtr;
std::experimental::observer_ptr<const FluxioParameter> fromParameterPtr;
std::experimental::observer_ptr<const FluxioNode> toNodePtr;
std::experimental::observer_ptr<const FluxioParameter> toParameterPtr;
std::optional<manager::dto::FluxioEdge> toManagerIce() const;
static std::optional<FluxioEdge>
FromIce(const manager::dto::FluxioEdge& i,
std::map<std::string, FluxioNode*>& nodesMap,
std::map<std::string, FluxioParameter>& parametersMap);
const std::map<const std::string, const std::unique_ptr<FluxioNode>>& nodesMap,
const std::map<std::string, FluxioParameter>& parametersMap);
};
} // namespace skills
} // namespace armarx
#include "FluxioNode.h"
#include <experimental/memory>
#include <ArmarXCore/core/logging/Logging.h>
#include <RobotAPI/interface/skills/SkillManagerInterface.h>
......@@ -86,9 +88,10 @@ namespace armarx
return ret;
}
FluxioNode*
FluxioNode::FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator& i,
std::map<std::string, FluxioNode*>& nodesMap)
std::experimental::observer_ptr<const FluxioNode>
FluxioNode::FromFluxioIdentificatorIce(
const manager::dto::FluxioIdentificator& i,
const std::map<const std::string, const std::unique_ptr<FluxioNode>>& nodesMap)
{
const auto& nodeIt = nodesMap.find(i.id);
......@@ -98,7 +101,7 @@ namespace armarx
return nullptr;
}
return nodesMap[nodeIt->first];
return std::experimental::make_observer(nodeIt->second.get());
}
FluxioNode
......
#pragma once
#include <experimental/memory>
#include <optional>
#include <string>
......@@ -29,9 +30,9 @@ namespace armarx
virtual std::optional<manager::dto::FluxioNode> toManagerIce() const;
manager::dto::FluxioIdentificator toFluxioIdentificatorIce() const;
static FluxioNode*
FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator& i,
std::map<std::string, FluxioNode*>& nodesMap);
static std::experimental::observer_ptr<const FluxioNode> FromFluxioIdentificatorIce(
const manager::dto::FluxioIdentificator& i,
const std::map<const std::string, const std::unique_ptr<FluxioNode>>& nodesMap);
static FluxioNode FromIce(const manager::dto::FluxioNode& i);
};
......
#include "FluxioParameter.h"
#include <memory>
#include <ArmarXCore/core/logging/Logging.h>
#include "RobotAPI/libraries/skills/core/FluxioProfile.h"
......@@ -75,10 +77,10 @@ namespace armarx
}
}
FluxioParameter*
std::experimental::observer_ptr<const FluxioParameter>
FluxioParameter::FromFluxioIdentificatorIce(
const manager::dto::FluxioIdentificator& i,
std::map<std::string, FluxioParameter>& parametersMap)
const std::map<std::string, FluxioParameter>& parametersMap)
{
const auto& parameterIt = parametersMap.find(i.id);
......@@ -88,7 +90,7 @@ namespace armarx
return nullptr;
}
return &(parametersMap[parameterIt->first]);
return std::experimental::make_observer(&parameterIt->second);
}
FluxioParameter
......
#pragma once
#include <experimental/memory>
#include <list>
#include <string>
......@@ -26,9 +27,9 @@ namespace armarx
void updateFromIce(const manager::dto::FluxioParameter& i,
std::map<std::string, FluxioProfile>& profilesMap);
static FluxioParameter*
static std::experimental::observer_ptr<const FluxioParameter>
FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator& i,
std::map<std::string, FluxioParameter>& parametersMap);
const std::map<std::string, FluxioParameter>& parametersMap);
static FluxioParameter FromIce(const manager::dto::FluxioParameter& i,
std::map<std::string, FluxioProfile>& profilesMap);
};
......
......@@ -4,10 +4,10 @@
#include <ArmarXCore/core/logging/Logging.h>
#include "RobotAPI/libraries/skills/core/FluxioNode.h"
#include <RobotAPI/interface/skills/SkillManagerInterface.h>
#include "FluxioParameter.h"
#include "RobotAPI/libraries/skills/core/FluxioNode.h"
namespace armarx
{
......@@ -23,7 +23,7 @@ namespace armarx
}
const auto& nt = FluxioNodeTypeToString(nodeType);
if(!nt.has_value())
if (!nt.has_value())
{
return std::nullopt;
}
......@@ -53,7 +53,7 @@ namespace armarx
ARMARX_WARNING << "Parameters id is dummy id in ParameterNode with id " << i.nodeId;
return std::nullopt;
}
skills::FluxioParameter* parameterPtr =
const auto& parameterPtr =
FluxioParameter::FromFluxioIdentificatorIce(i.parameterId, parametersMap);
if (parameterPtr == nullptr)
......
#pragma once
#include <experimental/memory>
#include <RobotAPI/interface/skills/SkillManagerInterface.h>
#include "FluxioNode.h"
......@@ -11,7 +13,7 @@ namespace armarx
{
struct FluxioParameterNode : public FluxioNode
{
FluxioParameter* parameterPtr;
std::experimental::observer_ptr<const FluxioParameter> parameterPtr;
std::optional<manager::dto::FluxioNode> toManagerIce() const override;
......
#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
......
#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);
......
#include "FluxioSkill.h"
#include <algorithm>
#include <memory>
#include <optional>
#include <utility>
#include <ArmarXCore/core/logging/Logging.h>
#include <ArmarXCore/core/time/DateTime.h>
......@@ -125,8 +128,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
......@@ -175,11 +179,11 @@ namespace armarx
nodes.clear(); // create all nodes anew
for (const manager::dto::FluxioNode& node : i.nodes)
{
FluxioNode* n = CreateNode(node, parameters, skillsMap, profilesMap);
auto n = CreateNode(node, parameters, skillsMap, profilesMap);
if (n != nullptr)
{
nodes[n->nodeId] = n;
nodes.emplace(n->nodeId, std::move(n));
}
}
}
......@@ -225,16 +229,17 @@ namespace armarx
std::list<std::string> subSkillNodeIds;
for (const auto& [nodeId, nodePtr] : nodes)
{
// TODO: check nodePtr for nullptr
if (nodePtr->nodeType != FluxioNodeType::SUBSKILL)
if (nodePtr == nullptr || nodePtr->nodeType != FluxioNodeType::SUBSKILL)
{
continue;
}
// get subskillnode from pointer // TODO: check for nullptr
auto* subSkillNode = dynamic_cast<FluxioSubSkillNode*>(nodePtr);
const auto* subSkillNodePtr =
dynamic_cast<const FluxioSubSkillNode*>(nodePtr.get());
if (subSkillNode->skillPtr->id == skillId)
if (subSkillNodePtr->skillPtr != nullptr &&
subSkillNodePtr->skillPtr->id == skillId)
{
subSkillNodeIds.push_back(nodeId);
}
......@@ -276,8 +281,10 @@ namespace armarx
continue;
}
const auto* subSkillNodePtr = dynamic_cast<FluxioSubSkillNode*>(nodePtr);
if (subSkillNodePtr != nullptr && subSkillNodePtr->skillPtr->id == skillId)
const auto& subSkillNodePtr =
dynamic_cast<const FluxioSubSkillNode*>(nodePtr.get());
if (subSkillNodePtr != nullptr && subSkillNodePtr->skillPtr != nullptr &&
subSkillNodePtr->skillPtr->id == skillId)
{
edges.remove_if(
[nodeId](const FluxioEdge& e) {
......@@ -288,13 +295,13 @@ namespace armarx
}
}
for(const auto& id: nodeIdsToDelete)
for (const auto& id : nodeIdsToDelete)
{
nodes.erase(id);
}
}
FluxioSkill*
std::experimental::observer_ptr<FluxioSkill>
FluxioSkill::FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator& i,
std::map<std::string, FluxioSkill>& skillsMap)
{
......@@ -306,10 +313,10 @@ namespace armarx
return nullptr;
}
return &(skillsMap[skillIt->first]);
return std::experimental::observer_ptr<FluxioSkill>(&skillsMap[skillIt->first]);
}
std::optional<FluxioSkill>
std::unique_ptr<FluxioSkill>
FluxioSkill::FromIce(const manager::dto::FluxioSkill& i,
std::map<std::string, FluxioProvider>& providersMap,
std::map<std::string, FluxioProfile>& profilesMap,
......@@ -320,7 +327,7 @@ namespace armarx
if (providerPtr == nullptr)
{
ARMARX_WARNING << "Provider for Skill with id " << i.id << " not found";
return std::nullopt;
return nullptr;
}
FluxioSkill ret;
......@@ -332,6 +339,9 @@ namespace armarx
ret.executable = i.executable;
ret.native = i.native;
ret.skillProviderPtr = providerPtr;
ret.parameters = std::map<std::string, FluxioParameter>();
ret.nodes = std::map<const std::string, const std::unique_ptr<FluxioNode>>();
ret.edges = std::list<FluxioEdge>();
for (const manager::dto::FluxioParameter& parameter : i.parameters)
{
......@@ -339,22 +349,20 @@ namespace armarx
ret.parameters[param.id] = param;
}
ret.nodes = {};
ret.edges = {};
if (i.native)
{
return ret; // return early (native skills have no nodes and edges)
return std::make_unique<FluxioSkill>(std::move(ret));
}
if (i.nodesHasValue)
{
for (const manager::dto::FluxioNode& node : i.nodes)
{
FluxioNode* n = CreateNode(node, ret.parameters, skillsMap, profilesMap);
auto n = CreateNode(node, ret.parameters, skillsMap, profilesMap);
if (n != nullptr)
{
ret.nodes[n->nodeId] = n;
ret.nodes.emplace(n->nodeId, std::move(n));
}
}
}
......@@ -372,10 +380,10 @@ namespace armarx
}
}
return ret;
return std::make_unique<FluxioSkill>(std::move(ret));
}
skills::FluxioNode*
std::unique_ptr<FluxioNode>
FluxioSkill::CreateNode(const manager::dto::FluxioNode& i,
std::map<std::string, FluxioParameter>& parametersMap,
std::map<std::string, FluxioSkill>& skillsMap,
......@@ -389,7 +397,7 @@ namespace armarx
if (n.has_value())
{
return new FluxioParameterNode(*n);
return std::make_unique<FluxioParameterNode>(n.value());
}
ARMARX_WARNING << "ParameterNode with id " << i.nodeId << " could not be converted";
......@@ -400,7 +408,7 @@ namespace armarx
if (n.has_value())
{
return new FluxioSubSkillNode(*n);
return std::make_unique<FluxioSubSkillNode>(n.value());
}
ARMARX_WARNING << "SubSkillNode with id " << i.nodeId << " could not be converted";
}
......@@ -410,7 +418,7 @@ namespace armarx
if (n.has_value())
{
return new FluxioControlNode(*n);
return std::make_unique<FluxioControlNode>(n.value());
}
ARMARX_WARNING << "controlNode with id " << i.nodeId << " could not be converted";
}
......
#pragma once
#include <list>
#include <memory>
#include <optional>
#include <string>
......@@ -19,16 +20,21 @@ namespace armarx
{
std::string id;
std::string name;
std::string description = "";
std::string description;
std::string lastChanged;
bool executable =
false; // TODO: change from explicit to implicit storing of executable state
bool native = true;
FluxioProvider* skillProviderPtr;
std::experimental::observer_ptr<const FluxioProvider> skillProviderPtr;
std::map<std::string, FluxioParameter> parameters;
std::map<std::string, FluxioNode*> nodes;
std::map<const std::string, const std::unique_ptr<FluxioNode>> nodes;
std::list<FluxioEdge> edges;
FluxioSkill(const FluxioSkill&) = delete;
FluxioSkill& operator=(const FluxioSkill&) = delete;
FluxioSkill(FluxioSkill&&) = default;
FluxioSkill() = default;
std::optional<manager::dto::FluxioSkill> toManagerIce() const;
manager::dto::FluxioIdentificator toFluxioIdentificatorIce() const;
bool updateFromIce(const manager::dto::FluxioSkill& i,
......@@ -38,15 +44,15 @@ namespace armarx
void deleteParameter(const std::string& parameterId, const std::string& skillId);
void removeSubSkillNodesAndEdges(const std::string& skillId);
static FluxioSkill*
static std::experimental::observer_ptr<FluxioSkill>
FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator& i,
std::map<std::string, FluxioSkill>& skillsMap);
static std::optional<FluxioSkill>
static std::unique_ptr<FluxioSkill>
FromIce(const manager::dto::FluxioSkill& i,
std::map<std::string, FluxioProvider>& providersMap,
std::map<std::string, FluxioProfile>& profilesMap,
std::map<std::string, FluxioSkill>& skillsMap);
static skills::FluxioNode*
static std::unique_ptr<skills::FluxioNode>
CreateNode(const manager::dto::FluxioNode& i,
std::map<std::string, FluxioParameter>& parametersMap,
std::map<std::string, FluxioSkill>& skillsMap,
......
......@@ -2,10 +2,10 @@
#include <ArmarXCore/core/logging/Logging.h>
#include "RobotAPI/libraries/skills/core/FluxioNode.h"
#include <RobotAPI/interface/skills/SkillManagerInterface.h>
#include "FluxioSkill.h"
#include "RobotAPI/libraries/skills/core/FluxioNode.h"
namespace armarx
{
......@@ -52,8 +52,7 @@ namespace armarx
ARMARX_WARNING << "Skills id is dummy id in SubSkillNode with id " << i.nodeId;
return std::nullopt;
}
skills::FluxioSkill* skillPtr =
FluxioSkill::FromFluxioIdentificatorIce(i.skillId, skillsMap);
const auto& skillPtr = FluxioSkill::FromFluxioIdentificatorIce(i.skillId, skillsMap);
if (skillPtr == nullptr)
{
......
#pragma once
#include <experimental/memory>
#include <RobotAPI/interface/skills/SkillManagerInterface.h>
#include "FluxioNode.h"
......@@ -11,7 +13,7 @@ namespace armarx
{
struct FluxioSubSkillNode : public FluxioNode
{
FluxioSkill* skillPtr;
std::experimental::observer_ptr<FluxioSkill> skillPtr;
std::optional<manager::dto::FluxioNode> toManagerIce() const override;
......
#include "FluxioCompositeExecutor.h"
#include <algorithm>
#include <memory>
#include <optional>
#include <string>
#include <thread>
......@@ -19,10 +20,10 @@ namespace armarx::skills
{
FluxioCompositeExecutor::FluxioCompositeExecutor(
std::string& id,
skills::FluxioSkill* skill,
const skills::FluxioSkill& skill,
const std::function<void(const std::string& executionId)>&& abortFluxioSkillFunc,
const std::function<FluxioExecutor*(const std::string& skillId,
const std::string& executorName)>&&
const std::function<std::shared_ptr<FluxioExecutor>(const std::string& skillId,
const std::string& executorName)>&&
executeFluxioSkillFunc) :
FluxioExecutor(id, false),
skill(skill),
......@@ -35,14 +36,14 @@ namespace armarx::skills
FluxioCompositeExecutor::run(const std::string executorName,
armarx::aron::data::DictPtr parameters)
{
if (skill == nullptr)
{
ARMARX_WARNING << "Skill is not set";
setStatus(skills::SkillStatus::Failed);
return;
}
ARMARX_INFO << "Running skill " << skill->name;
// if (skill == nullptr)
// {
// ARMARX_WARNING << "Skill is not set";
// setStatus(skills::SkillStatus::Failed);
// return;
// }
ARMARX_INFO << "Running skill " << skill.name;
setStatus(skills::SkillStatus::Constructing);
skills::FluxioEdge startEdge;
......@@ -73,9 +74,9 @@ namespace armarx::skills
.detach();
// thread for the sub routines
const std::string newExecutorName = executorName + "/" + skill->name;
const std::string newExecutorName = executorName + "/" + skill.name;
std::thread(
[this, &startEdge, &skillRunning, &newExecutorName]
[this, &startEdge, &skillRunning, newExecutorName]
{
this->startSubRoutine(
startEdge.toNodePtr, startEdge.toParameterPtr, skillRunning, newExecutorName);
......@@ -108,10 +109,11 @@ namespace armarx::skills
}
void
FluxioCompositeExecutor::startSubRoutine(const skills::FluxioNode* startNode,
const skills::FluxioParameter* startParameter,
std::atomic_bool& running,
const std::string& executorName)
FluxioCompositeExecutor::startSubRoutine(
const std::experimental::observer_ptr<const skills::FluxioNode>& startNode,
const std::experimental::observer_ptr<const skills::FluxioParameter>& startParameter,
std::atomic_bool& running,
const std::string& executorName)
{
if (!running)
{
......@@ -128,7 +130,8 @@ namespace armarx::skills
if (startNode->nodeType == skills::FluxioNodeType::PARAMETER)
{
// cast to parameter node
const auto* paramNodePtr = dynamic_cast<const skills::FluxioParameterNode*>(startNode);
const auto* paramNodePtr =
dynamic_cast<const skills::FluxioParameterNode*>(startNode.get());
if (paramNodePtr == nullptr)
{
ARMARX_WARNING << "Unexpected nullptr.Dynamic cast from FluxioNodePtr to "
......@@ -142,7 +145,8 @@ namespace armarx::skills
else if (startNode->nodeType == skills::FluxioNodeType::CONTROL)
{
// cast to control node
const auto* controlNodePtr = dynamic_cast<const skills::FluxioControlNode*>(startNode);
const auto* controlNodePtr =
dynamic_cast<const skills::FluxioControlNode*>(startNode.get());
if (controlNodePtr == nullptr)
{
......@@ -158,7 +162,7 @@ namespace armarx::skills
{
// cast to subskill node
const auto* subSkillNodePtr =
dynamic_cast<const skills::FluxioSubSkillNode*>(startNode);
dynamic_cast<const skills::FluxioSubSkillNode*>(startNode.get());
if (subSkillNodePtr == nullptr || subSkillNodePtr->skillPtr == nullptr)
{
ARMARX_WARNING << "Unexpected nullptr. Dynamic cast from FluxioNodePtr to "
......@@ -236,7 +240,7 @@ namespace armarx::skills
}
// start skill execution
auto* executorPtr = executeFluxioSkill(subSkillNode->skillPtr->id, executorName);
auto executorPtr = executeFluxioSkill(subSkillNode->skillPtr->id, executorName);
if (executorPtr == nullptr)
{
ARMARX_WARNING << "Failed to execute subskill " << subSkillNode->skillPtr->id;
......@@ -244,7 +248,7 @@ namespace armarx::skills
return;
}
subExecutionsMap.insert({subSkillNode->nodeId, executorPtr});
subExecutionsMap[subSkillNode->nodeId] = executorPtr;
// wait until the skill has finished (or the super skill is finished)
skills::FluxioSkillStatusUpdate statusUpdate;
......@@ -317,17 +321,17 @@ namespace armarx::skills
// find the connected edge
const auto& edge =
std::find_if(skill->edges.begin(),
skill->edges.end(),
std::find_if(skill.edges.begin(),
skill.edges.end(),
[&subSkillNode, &outputParam](const skills::FluxioEdge& edge)
{
return (edge.fromNodePtr->nodeId == subSkillNode->nodeId &&
edge.fromParameterPtr->id == outputParam->second.id);
});
if (edge == skill->edges.end())
if (edge == skill.edges.end())
{
ARMARX_WARNING << "Skill " << skill->name
ARMARX_WARNING << "Skill " << skill.name
<< " has no edge connected to the output event parameter "
<< outputEventName;
setStatus(skills::SkillStatus::Failed);
......@@ -340,10 +344,11 @@ namespace armarx::skills
}
void
FluxioCompositeExecutor::handleControlRoutine(const skills::FluxioControlNode* controlNode,
const skills::FluxioParameter* startParameter,
std::atomic_bool& running,
const std::string& executorName)
FluxioCompositeExecutor::handleControlRoutine(
const skills::FluxioControlNode* controlNode,
const std::experimental::observer_ptr<const skills::FluxioParameter>& startParameter,
std::atomic_bool& running,
const std::string& executorName)
{
if (controlNode == nullptr)
{
......@@ -365,7 +370,7 @@ namespace armarx::skills
continue;
}
for (const auto& edge : skill->edges)
for (const auto& edge : skill.edges)
{
if (edge.fromParameterPtr != nullptr && edge.fromParameterPtr->id == id)
{
......@@ -380,7 +385,7 @@ namespace armarx::skills
for (const skills::FluxioEdge* edgePtr : edgePtrs)
{
std::thread(
[this, edgePtr, &running, &newExecutorName] {
[this, edgePtr, &running, newExecutorName] {
startSubRoutine(
edgePtr->toNodePtr, edgePtr->toParameterPtr, running, newExecutorName);
})
......@@ -390,7 +395,7 @@ namespace armarx::skills
else if (controlNode->controlType == skills::FluxioControlNodeType::AND_MERGER)
{
// check the list of subexecutions for the node id
FluxioMergerExecutor* mergerExecutorPtr = nullptr;
std::shared_ptr<FluxioMergerExecutor> mergerExecutorPtr = nullptr;
const auto& executorPtr = subExecutionsMap.find(controlNode->nodeId);
if (executorPtr == subExecutionsMap.end())
{
......@@ -405,15 +410,16 @@ namespace armarx::skills
}
// there is no execution for the merger yet, let´s start one
subExecutionsMap[controlNode->nodeId] =
new FluxioMergerExecutor(IceUtil::generateUUID(), paramIds);
subExecutionsMap[controlNode->nodeId] = std::make_shared<FluxioMergerExecutor>(
FluxioMergerExecutor(IceUtil::generateUUID(), paramIds));
mergerExecutorPtr =
dynamic_cast<FluxioMergerExecutor*>(subExecutionsMap[controlNode->nodeId]);
mergerExecutorPtr = std::dynamic_pointer_cast<FluxioMergerExecutor>(
subExecutionsMap[controlNode->nodeId]);
}
else
{
mergerExecutorPtr = dynamic_cast<FluxioMergerExecutor*>(executorPtr->second);
mergerExecutorPtr =
std::dynamic_pointer_cast<FluxioMergerExecutor>(executorPtr->second);
}
if (mergerExecutorPtr == nullptr)
......@@ -451,18 +457,18 @@ namespace armarx::skills
// find the connected edge
const auto& edge =
std::find_if(skill->edges.begin(),
skill->edges.end(),
std::find_if(skill.edges.begin(),
skill.edges.end(),
[&controlNode, &outputParam](const skills::FluxioEdge& edge)
{
return (edge.fromNodePtr->nodeId == controlNode->nodeId &&
edge.fromParameterPtr->id == outputParam->second.id);
});
if (edge == skill->edges.end())
if (edge == skill.edges.end())
{
ARMARX_WARNING
<< "Skill " << skill->name
<< "Skill " << skill.name
<< " has no edge connected to the output event parameter of the AND merger";
setStatus(skills::SkillStatus::Failed);
return;
......@@ -482,7 +488,7 @@ namespace armarx::skills
void
FluxioCompositeExecutor::abort()
{
ARMARX_INFO << "Aborting skill " << skill->name;
ARMARX_INFO << "Aborting skill " << skill.name;
setStatus(skills::SkillStatus::Aborted);
abortSubExecutions();
}
......@@ -509,7 +515,7 @@ namespace armarx::skills
std::optional<std::vector<skills::FluxioSkillStatusUpdate>>
FluxioCompositeExecutor::getStatusUpdate()
{
ARMARX_INFO << "Getting status updates for skill " << skill->name;
ARMARX_INFO << "Getting status updates for skill " << skill.name;
// convert statusupdates list to vector
auto ret = std::vector<skills::FluxioSkillStatusUpdate>(statusUpdates.begin(),
statusUpdates.end());
......@@ -546,46 +552,41 @@ namespace armarx::skills
bool
FluxioCompositeExecutor::validateSkill(skills::FluxioEdge& ret)
{
// check if skill is not null
if (skill == nullptr)
{
ARMARX_WARNING << "Skill is not set";
return false;
}
// get start parameter
const auto& startParam =
std::find_if(skill->parameters.begin(),
skill->parameters.end(),
std::find_if(skill.parameters.begin(),
skill.parameters.end(),
[](const std::pair<std::string, skills::FluxioParameter>& param) {
return (param.second.type == "Event" && param.second.isInput &&
param.second.name == "Start");
});
if (startParam == skill->parameters.end())
if (startParam == skill.parameters.end())
{
ARMARX_WARNING << "Skill has no start parameter";
return false;
}
// get all parameter nodes for the start parameter
const auto& startNode =
std::find_if(skill->nodes.begin(),
skill->nodes.end(),
[startParam](const std::pair<std::string, skills::FluxioNode*>& nodeEntry)
{
if (nodeEntry.second->nodeType != skills::FluxioNodeType::PARAMETER)
{
return false;
}
const auto& startNode = std::find_if(
skill.nodes.begin(),
skill.nodes.end(),
[startParam](const std::pair<const std::string,
const std::unique_ptr<skills::FluxioNode>>& nodeEntry)
{
if (nodeEntry.second->nodeType != skills::FluxioNodeType::PARAMETER)
{
return false;
}
const auto* paramNode =
dynamic_cast<const skills::FluxioParameterNode*>(nodeEntry.second);
return (paramNode->parameterPtr->id == startParam->second.id);
});
const auto* paramNode =
dynamic_cast<const skills::FluxioParameterNode*>(nodeEntry.second.get());
return (paramNode->parameterPtr->id == startParam->second.id);
});
// there can only be one
if (startNode == skill->nodes.end())
if (startNode == skill.nodes.end())
{
ARMARX_WARNING << "Skill has no start node";
return false;
......@@ -593,13 +594,13 @@ namespace armarx::skills
// check if the start node is connected
const auto& startEdge =
std::find_if(skill->edges.begin(),
skill->edges.end(),
std::find_if(skill.edges.begin(),
skill.edges.end(),
[startNode](const skills::FluxioEdge& edge)
{ return (edge.fromNodePtr->nodeId == startNode->second->nodeId); });
// there can only be one
if (startEdge == skill->edges.end())
if (startEdge == skill.edges.end())
{
ARMARX_WARNING << "Skill has noedge connected to the start node";
return false;
......@@ -607,33 +608,33 @@ namespace armarx::skills
// get the output event parameters
const auto& outputParamsSuccess =
std::find_if(skill->parameters.begin(),
skill->parameters.end(),
std::find_if(skill.parameters.begin(),
skill.parameters.end(),
[](const std::pair<std::string, skills::FluxioParameter>& param)
{
return (param.second.type == "Event" && !param.second.isInput &&
param.second.name == "Succeeded");
});
const auto& outputParamsFailed =
std::find_if(skill->parameters.begin(),
skill->parameters.end(),
std::find_if(skill.parameters.begin(),
skill.parameters.end(),
[](const std::pair<std::string, skills::FluxioParameter>& param)
{
return (param.second.type == "Event" && !param.second.isInput &&
param.second.name == "Failed");
});
const auto& outputParamsAborted =
std::find_if(skill->parameters.begin(),
skill->parameters.end(),
std::find_if(skill.parameters.begin(),
skill.parameters.end(),
[](const std::pair<std::string, skills::FluxioParameter>& param)
{
return (param.second.type == "Event" && !param.second.isInput &&
param.second.name == "Aborted");
});
if (outputParamsSuccess == skill->parameters.end() ||
outputParamsFailed == skill->parameters.end() ||
outputParamsAborted == skill->parameters.end())
if (outputParamsSuccess == skill.parameters.end() ||
outputParamsFailed == skill.parameters.end() ||
outputParamsAborted == skill.parameters.end())
{
ARMARX_WARNING << "Skill is missing one or more output event parameters";
return false;
......@@ -650,7 +651,7 @@ namespace armarx::skills
FluxioCompositeExecutor::setStatus(skills::SkillStatus status)
{
const skills::FluxioSkillStatusUpdate update = {
armarx::DateTime::Now(), id, skill->id, status};
armarx::DateTime::Now(), id, skill.id, status};
this->status = update;
this->statusUpdates.push_front(update);
}
......
#pragma once
#include <atomic>
#include <experimental/memory>
#include <memory>
#include <optional>
#include <string>
......@@ -21,10 +23,10 @@ namespace armarx::skills
public:
FluxioCompositeExecutor(
std::string& id,
skills::FluxioSkill* skill,
const skills::FluxioSkill& skill,
const std::function<void(const std::string& executionId)>&& abortFluxioSkillFunc,
const std::function<FluxioExecutor*(const std::string& skillId,
const std::string& executorName)>&&
const std::function<std::shared_ptr<FluxioExecutor>(const std::string& skillId,
const std::string& executorName)>&&
executeFluxioSkillFunc);
void run(const std::string executorName, armarx::aron::data::DictPtr parameters) override;
void abort() override;
......@@ -32,10 +34,11 @@ namespace armarx::skills
bool validateSkill(skills::FluxioEdge& ret);
private:
void startSubRoutine(const skills::FluxioNode* startNode,
const skills::FluxioParameter* startParameter,
std::atomic_bool& running,
const std::string& executorName);
void startSubRoutine(
const std::experimental::observer_ptr<const skills::FluxioNode>& startNode,
const std::experimental::observer_ptr<const skills::FluxioParameter>& startParameter,
std::atomic_bool& running,
const std::string& executorName);
void handleParameterRoutine(const skills::FluxioParameterNode* parameterNode,
std::atomic_bool& running,
......@@ -43,20 +46,21 @@ namespace armarx::skills
void handleSubSkillRoutine(const skills::FluxioSubSkillNode* subSkillNode,
std::atomic_bool& running,
const std::string& executorName);
void handleControlRoutine(const skills::FluxioControlNode* controlNode,
const skills::FluxioParameter* startParameter,
std::atomic_bool& running,
const std::string& executorName);
void handleControlRoutine(
const skills::FluxioControlNode* controlNode,
const std::experimental::observer_ptr<const skills::FluxioParameter>& startParameter,
std::atomic_bool& running,
const std::string& executorName);
void abortSubExecutions();
std::optional<skills::SkillExecutionID> executionId = std::nullopt;
skills::FluxioSkill* skill;
const skills::FluxioSkill& skill;
void setStatus(skills::SkillStatus status) override;
void pollSubStatuses();
std::map<std::string, FluxioExecutor*> subExecutionsMap; // key is node id
std::map<std::string, std::shared_ptr<FluxioExecutor>> subExecutionsMap; // key is node id
const std::function<void(const std::string& executionId)> abortFluxioSkill;
const std::function<FluxioExecutor*(const std::string& skillId,
const std::string& executorName)>
const std::function<std::shared_ptr<FluxioExecutor>(const std::string& skillId,
const std::string& executorName)>
executeFluxioSkill;
};
} // namespace armarx::skills
#include "SkillManagerComponentPlugin.h"
#include <experimental/memory>
#include <list>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
......@@ -59,13 +61,13 @@ namespace armarx::plugins
}
template <typename S, typename T>
std::vector<T>
std::vector<std::experimental::observer_ptr<const T>>
SkillManagerComponentPlugin::convertMapValuesToVector(std::map<S, T>& map)
{
std::vector<T> ret;
std::vector<std::experimental::observer_ptr<const T>> ret;
for (const auto& [k, v] : map)
{
ret.push_back(v);
ret.push_back(std::experimental::make_observer(&v));
}
return ret;
}
......@@ -620,12 +622,12 @@ namespace armarx::plugins
//** Fluxio related methods **//
//****************************//
skills::FluxioExecutor*
std::shared_ptr<skills::FluxioExecutor>
SkillManagerComponentPlugin::executeFluxioSkill(const std::string& skillId,
const std::string& executorName)
{
const auto& skill = getSkill(skillId);
if (!skill.has_value())
if (skill == nullptr)
{
ARMARX_WARNING << "Skill with id '" << skillId << "' not found.";
return nullptr;
......@@ -633,7 +635,7 @@ namespace armarx::plugins
std::string executionId = IceUtil::generateUUID();
if (!skill.value().native)
if (!skill->native)
{
// currently empty parameters
armarx::aron::data::DictPtr emptyParameters = {};
......@@ -646,10 +648,11 @@ namespace armarx::plugins
{ this->abortFluxioSkill(executionId); };
fluxioDC.fluxioExecutors[executionId] =
new skills::FluxioCompositeExecutor(executionId,
&fluxioDC.skills[skillId],
std::make_shared<skills::FluxioCompositeExecutor>(
skills::FluxioCompositeExecutor(executionId,
fluxioDC.skills[skillId],
std::move(abortFluxioSkill),
std::move(executeFluxioSkillFunc));
std::move(executeFluxioSkillFunc)));
std::thread(
[this, executionId, executorName, emptyParameters]()
......@@ -680,16 +683,14 @@ namespace armarx::plugins
[this](const skills::SkillExecutionID& executionId)
{ return this->getSkillExecutionStatus(executionId); };
// FIXME: do not use new, instead use smart pointer
std::string fluxioSkillUUID = skill->id;
fluxioDC.fluxioExecutors[executionId] =
new skills::FluxioNativeExecutor(executionId,
sID,
fluxioSkillUUID,
std::move(abortSkillFunc),
std::move(executeSkillAsyncFunc),
std::move(getSkillExecutionStatusFunc));
fluxioDC.fluxioExecutors[executionId] = std::make_shared<skills::FluxioNativeExecutor>(
skills::FluxioNativeExecutor(executionId,
sID,
fluxioSkillUUID,
std::move(abortSkillFunc),
std::move(executeSkillAsyncFunc),
std::move(getSkillExecutionStatusFunc)));
fluxioDC.fluxioExecutors[executionId]->run(executorName,
skillDescr->rootProfileDefaults);
}
......@@ -707,51 +708,7 @@ namespace armarx::plugins
return;
}
skills::FluxioExecutor* executorPtr = executorIt->second;
if (executorPtr->native)
{
skills::FluxioNativeExecutor* castedExecutor = nullptr;
try
{
castedExecutor = dynamic_cast<skills::FluxioNativeExecutor*>(executorPtr);
if (castedExecutor == nullptr)
{
ARMARX_WARNING << "Executor with id '" << executionId
<< "' is not a FluxioNativeExecutor.";
return;
}
}
catch (const std::bad_cast& e)
{
ARMARX_WARNING << "Error while getting execution runner for fluxio skill with id "
<< executionId << ": " << e.what();
return;
}
castedExecutor->abort();
}
else
{
skills::FluxioCompositeExecutor* castedExecutor = nullptr;
try
{
castedExecutor = dynamic_cast<skills::FluxioCompositeExecutor*>(executorPtr);
if (castedExecutor == nullptr)
{
ARMARX_WARNING << "Executor with id '" << executionId
<< "' is not a FluxioCompositeExecutor.";
return;
}
}
catch (const std::bad_cast& e)
{
ARMARX_WARNING << "Error while getting execution runner for fluxio skill with id "
<< executionId << ": " << e.what();
return;
}
castedExecutor->abort();
}
executorIt->second->abort();
}
std::optional<std::vector<skills::FluxioSkillStatusUpdate>>
......@@ -764,50 +721,8 @@ namespace armarx::plugins
return std::nullopt;
}
skills::FluxioExecutor* executorPtr = executorIt->second;
if (executorPtr->native)
{
skills::FluxioNativeExecutor* castedExecutor = nullptr;
try
{
castedExecutor = dynamic_cast<skills::FluxioNativeExecutor*>(executorPtr);
if (castedExecutor == nullptr)
{
ARMARX_WARNING << "Executor with id '" << executionId
<< "' is not a FluxioNativeExecutor.";
return std::nullopt;
}
}
catch (const std::bad_cast& e)
{
ARMARX_WARNING << "Error while getting execution runner for fluxio skill with id "
<< executionId << ": " << e.what();
return std::nullopt;
}
return castedExecutor->getStatusUpdate();
}
skills::FluxioCompositeExecutor* castedExecutor = nullptr;
try
{
castedExecutor = dynamic_cast<skills::FluxioCompositeExecutor*>(executorPtr);
if (castedExecutor == nullptr)
{
ARMARX_WARNING << "Executor with id '" << executionId
<< "' is not a FluxioCompositeExecutor.";
return std::nullopt;
}
}
catch (const std::bad_cast& e)
{
ARMARX_WARNING << "Error while getting execution runner for fluxio skill with id "
<< executionId << ": " << e.what();
return std::nullopt;
}
return castedExecutor->getStatusUpdate();
auto statusUpdate = executorIt->second->getStatusUpdate();
return statusUpdate;
}
/**
......@@ -861,7 +776,7 @@ namespace armarx::plugins
return generator(str);
}
std::vector<skills::FluxioSkill>
std::vector<std::experimental::observer_ptr<const skills::FluxioSkill>>
SkillManagerComponentPlugin::getSkillList()
{
std::map<skills::SkillID, skills::SkillDescription> skillDescriptions =
......@@ -892,18 +807,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);
const auto p = addFluxioProvider(skillId.providerId->providerName);
if (p == nullptr)
{
ARMARX_WARNING << "Could not add provider '" << skillId.providerId->providerName
<< "'.";
continue;
ARMARX_WARNING << "Failed to add provider with name '"
<< skillId.providerId->providerName << "'.";
}
s.skillProviderPtr = &fluxioDC.providers[p->id];
s.skillProviderPtr = p;
}
s.parameters = {};
......@@ -984,24 +898,26 @@ namespace armarx::plugins
// left empty because native skills have neither nodes nor edges
s.edges = {};
s.nodes = {};
// s.nodes = {};
fluxioDC.skills[s.id] = s;
fluxioDC.skills.emplace(s.id, std::move(s));
}
return convertMapValuesToVector(fluxioDC.skills);
}
std::optional<skills::FluxioSkill>
std::experimental::observer_ptr<skills::FluxioSkill>
SkillManagerComponentPlugin::getSkill(const std::string& id)
{
const auto& skillsEntry = fluxioDC.skills.find(id);
if (skillsEntry != fluxioDC.skills.end())
{
return skillsEntry->second;
return std::experimental::make_observer(&skillsEntry->second);
}
return std::nullopt;
ARMARX_WARNING << "Skill with id '" << id << "' not found.";
return nullptr;
}
std::optional<std::vector<skills::FluxioSkill*>>
......@@ -1045,14 +961,16 @@ namespace armarx::plugins
if (node->nodeType == skills::FluxioNodeType::SUBSKILL)
{
// cast to the right node type
const auto& subSkillNodeptr = dynamic_cast<skills::FluxioSubSkillNode*>(node);
const auto& subSkillNodeptr =
dynamic_cast<skills::FluxioSubSkillNode*>(node.get());
if (subSkillNodeptr == nullptr)
{
ARMARX_WARNING << "Error while casting node to FluxioSubSkillNode.";
continue;
}
if (subSkillNodeptr->skillPtr->id == skillId)
if (subSkillNodeptr->skillPtr != nullptr &&
subSkillNodeptr->skillPtr->id == skillId)
{
affectedSkills.push_back(&s);
break;
......@@ -1132,7 +1050,7 @@ namespace armarx::plugins
// TODO: check if mutex is held by user
}
std::vector<skills::FluxioProfile>
std::vector<std::experimental::observer_ptr<const skills::FluxioProfile>>
SkillManagerComponentPlugin::getProfileList()
{
return convertMapValuesToVector(fluxioDC.profiles);
......@@ -1174,7 +1092,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));
......@@ -1182,7 +1100,7 @@ namespace armarx::plugins
if (fluxioDC.providers.find(providerId) != fluxioDC.providers.end())
{
ARMARX_WARNING << "Provider with name '" << name << "' already exists.";
return nullptr;
return std::experimental::make_observer(&fluxioDC.providers[providerId]);
}
skills::FluxioProvider p;
......@@ -1190,10 +1108,10 @@ 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<skills::FluxioProvider>
std::vector<std::experimental::observer_ptr<const skills::FluxioProvider>>
SkillManagerComponentPlugin::getProviderList()
{
for (const auto& [providerID, providerPrx] : skillProviderMap)
......@@ -1226,7 +1144,7 @@ namespace armarx::plugins
return std::nullopt;
}
std::optional<std::vector<skills::FluxioSkill>>
std::optional<std::vector<std::experimental::observer_ptr<const skills::FluxioSkill>>>
SkillManagerComponentPlugin::getSkillsOfProvider(const std::string& id)
{
getProviderList();
......@@ -1237,30 +1155,37 @@ namespace armarx::plugins
return std::nullopt;
}
std::vector<skills::FluxioSkill> allSkills = getSkillList();
std::vector<skills::FluxioSkill> ret;
for (const auto& skill : allSkills)
{
if (skill.skillProviderPtr->id == id)
{
ret.push_back(skill);
}
}
return ret;
auto allSkills = getSkillList();
// std::vector<std::experimental::observer_ptr<const skills::FluxioSkill>> ret;
//
// for (const auto skillPtr : allSkills)
// {
// if (skillPtr->skillProviderPtr->id == id) // TODO: Sanatize this
// {
// ret.push_back(skillPtr);
// }
// }
allSkills.erase(std::remove_if(allSkills.begin(),
allSkills.end(),
[id](const auto& skillPtr)
{ return skillPtr->skillProviderPtr->id != id; }),
allSkills.end());
return allSkills;
}
std::optional<skills::FluxioSkill>
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())
{
return std::nullopt;
ARMARX_WARNING << "Provider with id '" << providerId << "' not found.";
return nullptr;
}
if (skill.id == "")
......@@ -1322,12 +1247,13 @@ namespace armarx::plugins
skill.lastChanged = armarx::DateTime::Now().toDateTimeString();
// store in data collector
fluxioDC.skills[skill.id] = skill;
const auto skillId = skill.id;
fluxioDC.skills.emplace(skillId, std::move(skill));
// set mutex
setEditFluxioSkillMutex(true, userId, skill.id);
return fluxioDC.skills[skill.id];
return std::experimental::make_observer(&(fluxioDC.skills[skillId]));
}
bool // TODO: add armarx info messages
......
#pragma once
#include <memory>
#include <mutex>
#include <optional>
#include <string>
......@@ -75,17 +76,17 @@ namespace armarx::plugins
//** Fluxio related methods **//
//****************************//
skills::FluxioExecutor* executeFluxioSkill(const std::string& skillId,
const std::string& executorName);
std::shared_ptr<skills::FluxioExecutor> executeFluxioSkill(const std::string& skillId,
const std::string& executorName);
void abortFluxioSkill(const std::string& executionId);
std::optional<std::vector<skills::FluxioSkillStatusUpdate>>
getFluxioSkillExecutionStatus(const std::string& executionId);
std::vector<skills::FluxioSkill> getSkillList();
std::vector<std::experimental::observer_ptr<const skills::FluxioSkill>> getSkillList();
std::optional<skills::FluxioSkill> getSkill(const std::string& id);
std::experimental::observer_ptr<skills::FluxioSkill> getSkill(const std::string& id);
std::optional<std::vector<skills::FluxioSkill*>>
deleteSkill(const std::string& skillId, const std::string& userId, bool dryRun);
......@@ -98,7 +99,7 @@ namespace armarx::plugins
const std::string& skillId,
const std::string& parameterId);
std::vector<skills::FluxioProfile> getProfileList();
std::vector<std::experimental::observer_ptr<const skills::FluxioProfile>> getProfileList();
std::optional<skills::FluxioProfile> getProfile(const std::string& id);
......@@ -106,17 +107,21 @@ namespace armarx::plugins
void updateProfile(const skills::FluxioProfile& profile);
std::vector<skills::FluxioProvider> getProviderList();
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);
std::optional<std::vector<skills::FluxioSkill>> getSkillsOfProvider(const std::string& id);
std::optional<std::vector<std::experimental::observer_ptr<const skills::FluxioSkill>>>
getSkillsOfProvider(const std::string& id);
std::optional<skills::FluxioSkill> addSkillToProvider(const std::string& userId,
const std::string& providerId,
skills::FluxioSkill& skill);
std::experimental::observer_ptr<skills::FluxioSkill>
addSkillToProvider(const std::string& userId,
const std::string& providerId,
skills::FluxioSkill&& skill);
private:
struct FluxioDataCollector
......@@ -126,7 +131,7 @@ namespace armarx::plugins
std::map<std::string, skills::FluxioProvider> providers;
std::map<std::string, std::tuple<std::string, armarx::DateTime>> skillMutexMap;
const std::int64_t mutexTimeout = 30; // minutes
std::map<std::string, skills::FluxioExecutor*> fluxioExecutors;
std::map<std::string, std::shared_ptr<skills::FluxioExecutor>> fluxioExecutors;
};
FluxioDataCollector fluxioDC = {};
......@@ -138,7 +143,8 @@ namespace armarx::plugins
skillProviderMap;
template <typename S, typename T>
std::vector<T> convertMapValuesToVector(std::map<S, T>& map);
std::vector<std::experimental::observer_ptr<const T>>
convertMapValuesToVector(std::map<S, T>& map);
static boost::uuids::uuid
createUuidWithString(const std::string& str,
......
......@@ -207,12 +207,12 @@ namespace armarx
for (const auto& s : l)
{
const auto& skill = s.toManagerIce();
const auto& skill = s->toManagerIce(); // TODO: sanatize this
if (!skill.has_value())
{
ARMARX_WARNING << "SkillManagerComponentPluginUser::getSkillList: Skill with id "
<< s.id << " could not be converted";
<< s->id << " could not be converted";
continue;
}
......@@ -227,7 +227,7 @@ namespace armarx
{
auto skill = this->plugin->getSkill(id);
if (skill.has_value())
if (skill != nullptr)
{
const auto& s = skill->toManagerIce();
if (s.has_value())
......@@ -325,7 +325,7 @@ namespace armarx
for (const auto& profile : l)
{
ret.push_back(profile.toManagerIce());
ret.push_back(profile->toManagerIce()); // TODO: sanatize this
}
return ret;
......@@ -373,7 +373,7 @@ namespace armarx
for (const auto& s : l)
{
ret.push_back(s.toManagerIce());
ret.push_back(s->toManagerIce()); // TODO: sanatize this
}
return ret;
......@@ -406,13 +406,13 @@ namespace armarx
for (const auto& s : *l)
{
const auto& skill = s.toManagerIce();
const auto& skill = s->toManagerIce(); // TODO: sanatize this
if (!skill.has_value())
{
ARMARX_WARNING
<< "SkillManagerComponentPluginUser::getSkillsOfProvider: Skill with id "
<< s.id << " could not be converted";
<< s->id << " could not be converted";
continue;
}
......@@ -436,24 +436,31 @@ namespace armarx
std::map<std::string, skills::FluxioProfile>& profilesMap = this->plugin->fluxioDC.profiles;
auto skillBO = skills::FluxioSkill::FromIce(skill, providersMap, profilesMap, skillsMap);
if (!skillBO.has_value())
if (skillBO == nullptr)
{
ARMARX_WARNING << "Skill with id " << skill.id << " could not be converted";
return {};
}
auto s = this->plugin->addSkillToProvider(userId, providerId, *skillBO);
if (s.has_value())
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