ReaderWriterPlugin.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 * @author Fabian Reister ( fabian dot reister at kit dot edu )
17 * @date 2022
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <string>
25
28
29#include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h>
32
34{
35
36 /**
37 * @brief A component plugin offering client-side access to a reader or writer
38 * and manages the lifecycle, e.g. connecting to the memory.
39 * Access to the working memory system is provided by a Memory Name System (MNS) client.
40 *
41 * @see MemoryNameSystem
42 */
43 template <typename T>
45 {
46 public:
47 ReaderWriterPlugin(ManagedIceObject& parent, const std::string& pre) :
49 {
50 if (armemPlugin == nullptr)
51 {
52 addPlugin(armemPlugin);
53 }
54 addPluginDependency(armemPlugin);
55 }
56
57 ~ReaderWriterPlugin() override = default;
58
59 void
61 {
62 readerWriter.registerPropertyDefinitions(properties);
63 }
64
65 void
67 {
68 ARMARX_CHECK_NOT_NULL(armemPlugin);
69 if (not armemPlugin->isMemoryNameSystemEnabled())
70 {
71 ARMARX_INFO << "The memory name system is disabled by user choice via the property."
72 << "Reader and writer will not be able to connect to the memory.";
73 return;
74 }
75
76 readerWriter.connect(memoryNameSystem());
77 }
78
79 bool
81 {
82 ARMARX_CHECK_NOT_NULL(armemPlugin);
83 return armemPlugin->isMemoryNameSystemEnabled();
84 }
85
86 T&
88 {
89 ARMARX_CHECK_NOT_NULL(armemPlugin);
90 ARMARX_CHECK(armemPlugin->isMemoryNameSystemEnabled());
91 return readerWriter;
92 }
93
94 const T&
95 get() const
96 {
97 ARMARX_CHECK_NOT_NULL(armemPlugin);
98 ARMARX_CHECK(armemPlugin->isMemoryNameSystemEnabled());
99 return readerWriter;
100 }
101
102 private:
104 memoryNameSystem()
105 {
106 if (armemPlugin == nullptr)
107 {
108 addPlugin(armemPlugin);
109 }
110
111 ARMARX_CHECK_NOT_NULL(armemPlugin);
112 return armemPlugin->getMemoryNameSystemClient();
113 }
114
115 armarx::armem::client::plugins::Plugin* armemPlugin = nullptr;
116
117 T readerWriter;
118 };
119
120} // namespace armarx::armem::client::plugins
void addPluginDependency(ManagedIceObjectPlugin *dependedOn)
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
The memory name system (MNS) client.
A component plugin offering client-side access to to the working memory system by providing a Memory ...
Definition Plugin.h:20
MemoryNameSystem & getMemoryNameSystemClient()
Get the MNS client.
Definition Plugin.cpp:89
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
ReaderWriterPlugin(ManagedIceObject &parent, const std::string &pre)
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file is part of ArmarX.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.