SkillWithContextBlueprint.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI
17  * @author Christoph Pohl ( christoph dot pohl at kit dot edu )
18  * @date 05.12.23
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <atomic>
26 
28 
29 namespace armarx
30 {
31  namespace skills
32  {
33  // template <typename T>
34  // concept takesContext = requires(typename T::Context cntxt) {
35  // { T::connectTo(cntxt) } -> void;
36  // };
37 
38 
39  template <typename SkillT>
41  {
42  public:
43  using ContextT = typename SkillT::Context;
44 
45  template <typename... Args>
46  SkillWithContextBlueprint(Args&&... args) :
47  SkillBlueprint(*SkillBlueprint::ForSkill<SkillT>(std::forward<Args>(args)...))
48  {
49  }
50 
51  virtual std::unique_ptr<Skill>
52  createSkill(const ProviderID& pid) const override
53  {
54  if (not isConnected_)
55  {
56  return nullptr;
57  }
58  auto s = _createSkill();
59  s->setProviderId(pid);
60  static_cast<SkillT*>(s.get())->connectTo(context_);
61  return s;
62  }
63 
64  virtual SkillDescription
66  {
67  auto s = _createSkill();
68  s->setProviderId(pid);
69  return s->getSkillDescription();
70  }
71 
72  void
73  connectTo(const ContextT& context)
74  {
75  context_ = context;
76  isConnected_ = true;
77  }
78 
79  private:
80  std::atomic_bool isConnected_ = false;
81  ContextT context_;
82  };
83  } // namespace skills
84 } // namespace armarx
armarx::skills::SkillWithContextBlueprint::createSkill
virtual std::unique_ptr< Skill > createSkill(const ProviderID &pid) const override
Definition: SkillWithContextBlueprint.h:52
skills
This file is part of ArmarX.
armarx::skills::SkillDescription
Definition: SkillDescription.h:17
SkillFactory.h
armarx::skills::SkillWithContextBlueprint
Definition: SkillWithContextBlueprint.h:40
armarx::skills::ProviderID
Definition: ProviderID.h:12
armarx::skills::SkillWithContextBlueprint::connectTo
void connectTo(const ContextT &context)
Definition: SkillWithContextBlueprint.h:73
armarx::skills::SkillBlueprint::ForSkill
requires static isSkill< _Skill > std::unique_ptr< SkillBlueprint > ForSkill(Args &&... args)
Definition: SkillFactory.h:32
armarx::skills::SkillBlueprint::_createSkill
FunctionTypeToCreateSkill _createSkill
Definition: SkillFactory.h:61
armarx::skills::SkillBlueprint
Definition: SkillFactory.h:11
armarx::skills::SkillWithContextBlueprint::SkillWithContextBlueprint
SkillWithContextBlueprint(Args &&... args)
Definition: SkillWithContextBlueprint.h:46
std
Definition: Application.h:66
armarx::skills::SkillWithContextBlueprint::ContextT
typename SkillT::Context ContextT
Definition: SkillWithContextBlueprint.h:43
armarx::skills::SkillWithContextBlueprint::createSkillDescription
virtual SkillDescription createSkillDescription(const skills::ProviderID &pid) const
Definition: SkillWithContextBlueprint.h:65
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27