SkillProviderComponentPlugin.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <experimental/memory>
4 #include <functional>
5 #include <queue>
6 #include <shared_mutex>
7 #include <thread>
8 #include <type_traits>
9 
13 
14 #include <RobotAPI/interface/skills/SkillManagerInterface.h>
16 
17 // Include all types of skills
21 
22 #include "LambdaSkill.h"
23 #include "PeriodicSkill.h"
25 #include "SkillFactory.h"
26 #include "SpecializedSkill.h"
27 
28 // Helper wrapper for execution
30 
31 namespace armarx
32 {
33  class SkillProviderComponentPluginUser; // forward declaration
34 }
35 
36 namespace armarx::plugins
37 {
39  {
40  public:
41  using ComponentPlugin::ComponentPlugin;
42 
43  void preOnInitComponent() override;
44 
45  void preOnConnectComponent() override;
46  void postOnConnectComponent() override;
47 
48  void postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties) override;
49 
50  void preOnDisconnectComponent() override;
51 
52  void addSkillFactory(std::unique_ptr<skills::SkillBlueprint>&&);
53 
56 
57  template <class SkillT, typename... Args>
58 
59  requires skills::isSkill<SkillT> skills::SkillBlueprint*
60  addSkillFactory(Args&&... args)
61  {
62  auto fac = skills::SkillBlueprint::ForSkill<SkillT>(std::forward<Args>(args)...);
63  auto* facPtr = fac.get();
64  addSkillFactory(std::move(fac));
65  return static_cast<skills::SkillBlueprint*>(facPtr);
66  }
67 
68  template <typename FactoryT, typename... Args>
69 
70  requires skills::isSkillBlueprint<FactoryT> FactoryT*
71  addCustomSkillFactory(Args&&... args)
72  {
73  auto fac = std::make_unique<FactoryT>(std::forward<Args>(args)...);
74  auto* facPtr = fac.get();
75  addSkillFactory(std::move(fac));
76  return static_cast<FactoryT*>(facPtr);
77  }
78 
79  // Ice forwards
80  std::optional<skills::SkillStatusUpdate>
82  std::map<skills::SkillExecutionID, skills::SkillStatusUpdate>
84 
85  std::optional<skills::SkillDescription> getSkillDescription(const skills::SkillID&) const;
86  std::map<skills::SkillID, skills::SkillDescription> getSkillDescriptions() const;
87 
89 
92 
94  const armarx::aron::data::DictPtr& params);
95 
96  bool abortSkill(const skills::SkillExecutionID& execId);
97 
98  bool abortSkillAsync(const skills::SkillExecutionID& execId);
99 
100  private:
101  skills::SkillBlueprint* getSkillFactory(const armarx::skills::SkillID& name);
102 
103 
104  skills::manager::dti::SkillManagerInterfacePrx manager;
105  skills::provider::dti::SkillProviderInterfacePrx myPrx;
106 
107  mutable std::shared_mutex skillFactoriesMutex;
108  std::map<skills::SkillID, std::unique_ptr<skills::SkillBlueprint>> skillFactories;
109 
110  mutable std::shared_mutex skillExecutionsMutex;
111  std::map<skills::SkillExecutionID, skills::detail::SkillRuntime> skillExecutions;
112 
114  };
115 } // namespace armarx::plugins
116 
117 namespace armarx
118 
119 {
121  virtual public ManagedIceObject,
122  virtual public skills::provider::dti::SkillProviderInterface
123  {
124  public:
126 
127  // Ice Implementations
128  IceUtil::Optional<skills::provider::dto::SkillDescription>
129  getSkillDescription(const skills::provider::dto::SkillID& skill,
130  const Ice::Current& current = Ice::Current()) override;
131 
132  skills::provider::dto::SkillDescriptionMap
133  getSkillDescriptions(const Ice::Current& current = Ice::Current()) override;
134 
135  IceUtil::Optional<skills::provider::dto::SkillStatusUpdate>
136  getSkillExecutionStatus(const skills::provider::dto::SkillExecutionID& executionId,
137  const Ice::Current& current = Ice::Current()) override;
138 
139  skills::provider::dto::SkillStatusUpdateMap
140  getSkillExecutionStatuses(const Ice::Current& current = Ice::Current()) override;
141 
142  skills::provider::dto::SkillStatusUpdate
143  executeSkill(const skills::provider::dto::SkillExecutionRequest& executionInfo,
144  const Ice::Current& current = Ice::Current()) override;
145 
146  skills::provider::dto::SkillExecutionID
147  executeSkillAsync(const skills::provider::dto::SkillExecutionRequest& executionInfo,
148  const Ice::Current& current = Ice::Current()) override;
149 
150  skills::provider::dto::ParameterUpdateResult
151  updateSkillParameters(const skills::provider::dto::SkillExecutionID& executionId,
152  const armarx::aron::data::dto::DictPtr& parameters,
153  const Ice::Current& current = Ice::Current()) override;
154 
155  skills::provider::dto::AbortSkillResult
156  abortSkill(const skills::provider::dto::SkillExecutionID& skill,
157  const Ice::Current& current = Ice::Current()) override;
158 
159  skills::provider::dto::AbortSkillResult
160  abortSkillAsync(const skills::provider::dto::SkillExecutionID& skill,
161  const Ice::Current& current = Ice::Current()) override;
162 
163  // Plugin
165  getSkillProviderPlugin() const;
166 
167  protected:
168  // -----------------------------------------------------------------------------------------
169  // New
170  // -----------------------------------------------------------------------------------------
174  {
175  auto ret = plugin->addSkillFactory(desc, f);
176  return ret;
177  }
178 
179  template <class SkillT, typename... Args>
180 
181  requires skills::isSkill<SkillT> skills::SkillBlueprint*
182  addSkillFactory(Args&&... args)
183  {
184  return plugin->addSkillFactory<SkillT>(std::forward<Args>(args)...);
185  }
186 
187  template <typename FacT, typename... Args>
188 
189  requires skills::isSkillBlueprint<FacT> FacT*
190  addCustomSkillFactory(Args&&... args)
191  {
192  return plugin->addCustomSkillFactory<FacT>(std::forward<Args>(args)...);
193  }
194 
195  private:
197  };
198 } // namespace armarx
armarx::skills::SkillExecutionID
Definition: SkillExecutionID.h:19
armarx::SkillProviderComponentPluginUser::getSkillProviderPlugin
const std::experimental::observer_ptr< plugins::SkillProviderComponentPlugin > & getSkillProviderPlugin() const
Definition: SkillProviderComponentPlugin.cpp:527
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
armarx::plugins::SkillProviderComponentPlugin::preOnDisconnectComponent
void preOnDisconnectComponent() override
Definition: SkillProviderComponentPlugin.cpp:38
armarx::SkillProviderComponentPluginUser::getSkillDescriptions
skills::provider::dto::SkillDescriptionMap getSkillDescriptions(const Ice::Current &current=Ice::Current()) override
Definition: SkillProviderComponentPlugin.cpp:429
armarx::SkillProviderComponentPluginUser::getSkillDescription
IceUtil::Optional< skills::provider::dto::SkillDescription > getSkillDescription(const skills::provider::dto::SkillID &skill, const Ice::Current &current=Ice::Current()) override
Definition: SkillProviderComponentPlugin.cpp:415
armarx::plugins::SkillProviderComponentPlugin::getSkillDescription
std::optional< skills::SkillDescription > getSkillDescription(const skills::SkillID &) const
Definition: SkillProviderComponentPlugin.cpp:151
armarx::plugins::SkillProviderComponentPlugin::executeSkill
skills::SkillStatusUpdate executeSkill(const skills::SkillExecutionRequest &executionInfo)
Definition: SkillProviderComponentPlugin.cpp:189
armarx::plugins::SkillProviderComponentPlugin::preOnConnectComponent
void preOnConnectComponent() override
Definition: SkillProviderComponentPlugin.cpp:16
armarx::plugins::SkillProviderComponentPlugin::addSkillFactory
void addSkillFactory(std::unique_ptr< skills::SkillBlueprint > &&)
Definition: SkillProviderComponentPlugin.cpp:59
armarx::skills::SkillDescription
Definition: SkillDescription.h:18
armarx::plugins::SkillProviderComponentPlugin::addSkillFactory
requires skills::isSkill< SkillT > skills::SkillBlueprint * addSkillFactory(Args &&... args)
Definition: SkillProviderComponentPlugin.h:60
armarx::SkillProviderComponentPluginUser::updateSkillParameters
skills::provider::dto::ParameterUpdateResult updateSkillParameters(const skills::provider::dto::SkillExecutionID &executionId, const armarx::aron::data::dto::DictPtr &parameters, const Ice::Current &current=Ice::Current()) override
Definition: SkillProviderComponentPlugin.cpp:489
LambdaSkill.h
SkillFactory.h
SkillImplementationWrapper.h
armarx::requires
requires(!aron::detail::DtoAndBoAreSame< DtoT, BoT >) void toAron(std
Definition: aron_conversions.h:346
armarx::skills::LambdaSkill::FunctionType
std::function< TerminatedSkillStatus()> FunctionType
Definition: LambdaSkill.h:12
armarx::SkillProviderComponentPluginUser::abortSkillAsync
skills::provider::dto::AbortSkillResult abortSkillAsync(const skills::provider::dto::SkillExecutionID &skill, const Ice::Current &current=Ice::Current()) override
Definition: SkillProviderComponentPlugin.cpp:515
armarx::SkillProviderComponentPluginUser::executeSkillAsync
skills::provider::dto::SkillExecutionID executeSkillAsync(const skills::provider::dto::SkillExecutionRequest &executionInfo, const Ice::Current &current=Ice::Current()) override
Definition: SkillProviderComponentPlugin.cpp:478
RunningTask.h
std::experimental::fundamentals_v2::observer_ptr
Definition: ManagedIceObject.h:53
Dict.h
armarx::plugins::SkillProviderComponentPlugin::abortSkillAsync
bool abortSkillAsync(const skills::SkillExecutionID &execId)
Definition: SkillProviderComponentPlugin.cpp:388
armarx::plugins::SkillProviderComponentPlugin
Definition: SkillProviderComponentPlugin.h:38
armarx::plugins::SkillProviderComponentPlugin::getSkillExecutionStatus
std::optional< skills::SkillStatusUpdate > getSkillExecutionStatus(const skills::SkillExecutionID &) const
Definition: SkillProviderComponentPlugin.cpp:119
armarx::skills::SkillExecutionRequest
Definition: SkillExecutionRequest.h:21
armarx::SkillProviderComponentPluginUser
Definition: SkillProviderComponentPlugin.h:120
armarx::plugins::SkillProviderComponentPlugin::abortSkill
bool abortSkill(const skills::SkillExecutionID &execId)
Definition: SkillProviderComponentPlugin.cpp:354
armarx::plugins::SkillProviderComponentPlugin::updateSkillParameters
bool updateSkillParameters(const skills::SkillExecutionID &id, const armarx::aron::data::DictPtr &params)
Definition: SkillProviderComponentPlugin.cpp:327
armarx::skills::SkillStatusUpdate
Definition: SkillStatusUpdate.h:139
ManagedIceObject.h
Skill.h
armarx::plugins
This file is part of ArmarX.
Definition: DebugObserverComponentPlugin.cpp:28
armarx::ComponentPlugin
Definition: ComponentPlugin.h:38
armarx::plugins::SkillProviderComponentPlugin::postOnConnectComponent
void postOnConnectComponent() override
Definition: SkillProviderComponentPlugin.cpp:23
armarx::SkillProviderComponentPluginUser::abortSkill
skills::provider::dto::AbortSkillResult abortSkill(const skills::provider::dto::SkillExecutionID &skill, const Ice::Current &current=Ice::Current()) override
Definition: SkillProviderComponentPlugin.cpp:504
armarx::SkillProviderComponentPluginUser::executeSkill
skills::provider::dto::SkillStatusUpdate executeSkill(const skills::provider::dto::SkillExecutionRequest &executionInfo, const Ice::Current &current=Ice::Current()) override
Definition: SkillProviderComponentPlugin.cpp:467
armarx::SkillProviderComponentPluginUser::addCustomSkillFactory
requires skills::isSkillBlueprint< FacT > FacT * addCustomSkillFactory(Args &&... args)
Definition: SkillProviderComponentPlugin.h:190
armarx::plugins::SkillProviderComponentPlugin::getSkillDescriptions
std::map< skills::SkillID, skills::SkillDescription > getSkillDescriptions() const
Definition: SkillProviderComponentPlugin.cpp:176
armarx::SkillProviderComponentPluginUser::getSkillExecutionStatus
IceUtil::Optional< skills::provider::dto::SkillStatusUpdate > getSkillExecutionStatus(const skills::provider::dto::SkillExecutionID &executionId, const Ice::Current &current=Ice::Current()) override
Definition: SkillProviderComponentPlugin.cpp:440
armarx::SkillProviderComponentPluginUser::addSkillFactory
skills::SkillBlueprint * addSkillFactory(const skills::SkillDescription &desc, const skills::LambdaSkill::FunctionType &f)
Definition: SkillProviderComponentPlugin.h:172
SkillExecutionRequest.h
armarx::plugins::SkillProviderComponentPlugin::addCustomSkillFactory
requires skills::isSkillBlueprint< FactoryT > FactoryT * addCustomSkillFactory(Args &&... args)
Definition: SkillProviderComponentPlugin.h:71
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
armarx::skills::SkillBlueprint
Definition: SkillFactory.h:11
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::plugins::SkillProviderComponentPlugin::executeSkillAsync
skills::SkillExecutionID executeSkillAsync(const skills::SkillExecutionRequest &executionInfo)
Definition: SkillProviderComponentPlugin.cpp:255
armarx::plugins::SkillProviderComponentPlugin::postCreatePropertyDefinitions
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
Definition: SkillProviderComponentPlugin.cpp:48
SpecializedSkill.h
SkillPreparationInput.h
ComponentPlugin.h
armarx::SkillProviderComponentPluginUser::addSkillFactory
requires skills::isSkill< SkillT > skills::SkillBlueprint * addSkillFactory(Args &&... args)
Definition: SkillProviderComponentPlugin.h:182
armarx::plugins::SkillProviderComponentPlugin::getSkillExecutionStatuses
std::map< skills::SkillExecutionID, skills::SkillStatusUpdate > getSkillExecutionStatuses() const
Definition: SkillProviderComponentPlugin.cpp:137
armarx::plugins::SkillProviderComponentPlugin::preOnInitComponent
void preOnInitComponent() override
Definition: SkillProviderComponentPlugin.cpp:11
PeriodicSpecializedSkill.h
armarx::skills::SkillID
Definition: SkillID.h:17
armarx::SkillProviderComponentPluginUser::getSkillExecutionStatuses
skills::provider::dto::SkillStatusUpdateMap getSkillExecutionStatuses(const Ice::Current &current=Ice::Current()) override
Definition: SkillProviderComponentPlugin.cpp:455
PeriodicSkill.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::SkillProviderComponentPluginUser::SkillProviderComponentPluginUser
SkillProviderComponentPluginUser()
Definition: SkillProviderComponentPlugin.cpp:409