SkillManagerComponentPlugin.h
Go to the documentation of this file.
1#pragma once
2
3#include <exception>
4#include <memory>
5#include <mutex>
6#include <optional>
7#include <shared_mutex>
8#include <string>
9#include <vector>
10
11#include <boost/uuid/uuid.hpp>
12
13#include <SimoxUtility/json/json.hpp>
14
18
23#include <RobotAPI/interface/aron/Aron.h>
24#include <RobotAPI/interface/skills/SkillManagerInterface.h>
39
41
42namespace armarx
43{
44 class SkillManagerComponentPluginUser; // forward declaration
45}
46
47namespace armarx::plugins
48{
50 {
51 public:
52 using ComponentPlugin::ComponentPlugin;
53
54 void preOnInitComponent() override;
55
56 void preOnConnectComponent() override;
57
59
60 void addProvider(const skills::ProviderInfo& info);
61
62 void removeProvider(const skills::ProviderID& id);
63
65
67
70
72
74
75 std::optional<skills::SkillDescription> getSkillDescription(const skills::SkillID& id);
76
77 std::map<skills::SkillID, skills::SkillDescription> getSkillDescriptions();
78
79 std::optional<skills::SkillStatusUpdate>
81
82 std::map<skills::SkillExecutionID, skills::SkillStatusUpdate> getSkillExecutionStatuses();
83
84 protected:
86
87 //****************************//
88 //** Fluxio related methods **//
89 //****************************//
90
92
95 executeFluxioSkill(const std::string& skillId,
96 const std::string& profileId,
97 const std::string& executorName,
98 armarx::aron::data::DictPtr parameters = nullptr);
99
100 void abortFluxioSkill(const std::string& executionId);
101
103 getFluxioSkillExecutionStatus(const std::string& executionId);
104
107 getSkillList();
108
111 getSkill(const std::string& id);
112
113 std::optional<std::vector<std::experimental::observer_ptr<const skills::FluxioSkill>>>
114 deleteSkill(const std::string& skillId, const std::string& userId, bool dryRun);
115
117 getSkillMutex(const std::string& skillId, const std::string& userId);
118
119 void deleteSkillMutex(const std::string& skillId, const std::string& userId);
120
123 deleteSkillParameter(const std::string& skillId,
124 const std::string& parameterId,
125 const std::string& userId,
126 bool dryRun);
127
130 updateSkillParameter(const std::string& skillId,
131 const skills::manager::dto::FluxioParameter& parameter,
132 const std::string& userId,
133 bool dryRun);
134
138
140 getProfile(const std::string& id);
141
143 createProfile(const skills::FluxioProfile& profile);
144
145 void updateProfile(const skills::FluxioProfile& profile);
146
150
152 getProvider(const std::string& id);
153
156 addFluxioProvider(const std::string& name);
157
160 getSkillsOfProvider(const std::string& id);
161
164 addSkillToProvider(const std::string& userId,
165 const std::string& providerId,
166 skills::FluxioSkill&& skill);
167
168 private:
169 struct FluxioDataCollector
170 {
171 std::map<std::string, skills::FluxioSkill> skills;
172 std::shared_mutex skillsMutex;
173
174 std::map<std::string, skills::FluxioProfile> profiles;
175 std::shared_mutex profilesMutex;
176
177 std::map<std::string, skills::FluxioProvider> providers;
178 std::shared_mutex providersMutex;
179
180 std::map<std::string, std::tuple<std::string, armarx::DateTime>> skillMutexMap;
181 std::shared_mutex skillMutexMapMutex;
182 const std::int64_t mutexTimeout = 30; // minutes
183
184 std::map<std::string, std::unique_ptr<skills::FluxioExecutor>> fluxioExecutors;
185 std::shared_mutex fluxioExecutorsMutex;
186
187 std::map<std::string, aron::type::ObjectPtr> types;
188 std::shared_mutex typesMutex;
189 };
190
191 FluxioDataCollector fluxioDC = {};
192 [[noreturn]] void handleExceptionNonLockingThrow(const char* funcName,
193 const std::exception& e,
194 skills::ProviderID providerId,
195 bool eraseSkillProvider = true);
196
197 std::optional<std::map<skills::ProviderID,
198 skills::provider::dti::SkillProviderInterfacePrx>::iterator>
199 handleExceptionNonLocking(const char* funcName,
200 const std::exception& e,
201 skills::ProviderID providerId,
202 bool eraseSkillProvider = true);
203
204 skills::manager::dti::SkillManagerInterfacePrx myPrx;
205
206 std::mutex skillProviderMapMutex;
207 std::map<skills::ProviderID, skills::provider::dti::SkillProviderInterfacePrx>
208 skillProviderMap;
209
210 template <typename S, typename T>
211 std::vector<std::experimental::observer_ptr<const T>>
212 convertMapValuesToObserverVector(std::map<S, T>& map);
213
214 static boost::uuids::uuid
215 createUuidWithString(const std::string& str,
216 std::optional<const boost::uuids::uuid> namespaceUUID = std::nullopt);
217
218 void
219 convertAronObjectPtrToFluxioParameters(std::map<std::string, skills::FluxioParameter>& ret,
220 const aron::type::ObjectPtr& ptr,
221 bool isInput,
222 const boost::uuids::uuid& skillId);
223
224 template <typename T>
225 void replaceVectorContent(std::vector<T>& originalVector,
226 const std::vector<T>& replacementVector);
227
228 bool setEditFluxioSkillMutex(bool aquireMutex,
229 const std::string& userId,
230 const std::string& skillId);
231
232 void descriptionIdToFluxioSkill(skills::SkillID skillId,
233 skills::SkillDescription skillDescription);
234
237 updateFluxioParameter(
238 const std::string& skillId,
239 const std::string& parameterId,
240 const std::string& userId,
241 bool dryRun,
242 bool deleteParameter,
243 const std::optional<skills::manager::dto::FluxioParameter>& parameterDT = std::nullopt);
244
246 };
247} // namespace armarx::plugins
std::string str(const T &t)
std::map< skills::SkillID, skills::SkillDescription > getSkillDescriptions()
bool abortSkill(const skills::SkillExecutionID &id)
skills::SkillStatusUpdate executeSkill(const skills::SkillExecutionRequest &req)
skills::Result< std::vector< std::experimental::observer_ptr< const skills::FluxioSkill > >, skills::error::FluxioException > getSkillList()
skills::SkillExecutionID executeSkillAsync(const skills::SkillExecutionRequest &req)
skills::Result< std::vector< std::experimental::observer_ptr< const skills::FluxioProfile > >, skills::error::FluxioException > getProfileList()
void updateProfile(const skills::FluxioProfile &profile)
skills::ProviderID getFirstProviderNameThatHasSkill(const skills::SkillID &skillid)
skills::Result< std::vector< std::experimental::observer_ptr< const skills::FluxioSkill > >, skills::error::FluxioException > deleteSkillParameter(const std::string &skillId, const std::string &parameterId, const std::string &userId, bool dryRun)
skills::Result< std::vector< std::experimental::observer_ptr< const skills::FluxioSkill > >, skills::error::FluxioException > updateSkillParameter(const std::string &skillId, const skills::manager::dto::FluxioParameter &parameter, const std::string &userId, bool dryRun)
skills::Result< std::experimental::observer_ptr< skills::FluxioExecutor >, skills::error::FluxioException > executeFluxioSkill(const std::string &skillId, const std::string &profileId, const std::string &executorName, armarx::aron::data::DictPtr parameters=nullptr)
skills::Result< std::experimental::observer_ptr< const skills::FluxioProvider >, skills::error::FluxioException > addFluxioProvider(const std::string &name)
void deleteSkillMutex(const std::string &skillId, const std::string &userId)
skills::Result< std::experimental::observer_ptr< const skills::FluxioSkill >, skills::error::FluxioException > addSkillToProvider(const std::string &userId, const std::string &providerId, skills::FluxioSkill &&skill)
skills::Result< std::vector< std::experimental::observer_ptr< const skills::FluxioProvider > >, skills::error::FluxioException > getProviderList()
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
skills::Result< std::experimental::observer_ptr< const skills::FluxioSkill >, skills::error::FluxioException > getSkill(const std::string &id)
bool updateSkillParameters(const skills::SkillExecutionID &id, const aron::data::DictPtr &data)
std::optional< skills::SkillStatusUpdate > getSkillExecutionStatus(const skills::SkillExecutionID &id)
skills::Result< std::vector< skills::FluxioSkillStatusUpdate >, skills::error::FluxioException > getFluxioSkillExecutionStatus(const std::string &executionId)
skills::Result< skills::FluxioProvider, skills::error::FluxioException > getProvider(const std::string &id)
bool abortSkillAsync(const skills::SkillExecutionID &id)
skills::Result< skills::FluxioProfile, skills::error::FluxioException > getProfile(const std::string &id)
std::map< skills::SkillExecutionID, skills::SkillStatusUpdate > getSkillExecutionStatuses()
skills::Result< bool, skills::error::FluxioException > getSkillMutex(const std::string &skillId, const std::string &userId)
std::optional< skills::SkillDescription > getSkillDescription(const skills::SkillID &id)
std::optional< std::vector< std::experimental::observer_ptr< const skills::FluxioSkill > > > deleteSkill(const std::string &skillId, const std::string &userId, bool dryRun)
skills::Result< skills::FluxioProfile, skills::error::FluxioException > createProfile(const skills::FluxioProfile &profile)
skills::Result< std::vector< std::experimental::observer_ptr< const skills::FluxioSkill > >, skills::error::FluxioException > getSkillsOfProvider(const std::string &id)
A base class for skill exceptions.
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
std::shared_ptr< Object > ObjectPtr
Definition Object.h:36
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
This file is part of ArmarX.