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
29namespace 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 std::unique_ptr<Skill>
52 createSkill(const ProviderID& pid, MessageTypeT logLevel) const override
53 {
54 if (not isConnected_)
55 {
56 return nullptr;
57 }
58 auto s = _createSkill();
59 s->setProviderId(pid);
60 s->setLocalMinimumLoggingLevel(logLevel);
61 static_cast<SkillT*>(s.get())->connectTo(context_);
62 return s;
63 }
64
66 createSkillDescription(const skills::ProviderID& pid) const override
67 {
68 auto s = _createSkill();
69 s->setProviderId(pid);
70 return s->getSkillDescription();
71 }
72
73 void
74 connectTo(const ContextT& context)
75 {
76 context_ = context;
77 isConnected_ = true;
78 }
79
80 private:
81 std::atomic_bool isConnected_ = false;
82 ContextT context_;
83 };
84 } // namespace skills
85} // namespace armarx
SkillBlueprint(const FunctionTypeToCreateSkill &s)
FunctionTypeToCreateSkill _createSkill
static std::unique_ptr< SkillBlueprint > ForSkill(Args &&... args)
std::unique_ptr< Skill > createSkill(const ProviderID &pid, MessageTypeT logLevel) const override
SkillDescription createSkillDescription(const skills::ProviderID &pid) const override
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
MessageTypeT
Definition LogSender.h:46