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
80  isAvailable() const
81  {
82  ARMARX_CHECK_NOT_NULL(armemPlugin);
83  return armemPlugin->isMemoryNameSystemEnabled();
84  }
85 
86  T&
87  get()
88  {
89  ARMARX_CHECK_NOT_NULL(armemPlugin);
91  return readerWriter;
92  }
93 
94  const T&
95  get() const
96  {
97  ARMARX_CHECK_NOT_NULL(armemPlugin);
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
armarx::armem::client::plugins::ReaderWriterPlugin::isAvailable
bool isAvailable() const
Definition: ReaderWriterPlugin.h:80
Plugin.h
armarx::ManagedIceObjectPlugin::addPluginDependency
void addPluginDependency(ManagedIceObjectPlugin *dependedOn)
Definition: ManagedIceObjectPlugin.cpp:42
armarx::armem::client::plugins::Plugin::isMemoryNameSystemEnabled
bool isMemoryNameSystemEnabled()
Indicate whether the Memory Name System (MNS) is enabled.
Definition: Plugin.cpp:69
armarx::armem::client::plugins::Plugin::getMemoryNameSystemClient
MemoryNameSystem & getMemoryNameSystemClient()
Get the MNS client.
Definition: Plugin.cpp:92
armarx::ManagedIceObjectPlugin::parent
ManagedIceObject & parent()
Definition: ManagedIceObjectPlugin.cpp:69
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
armarx::armem::client::plugins::ReaderWriterPlugin
A component plugin offering client-side access to a reader or writer and manages the lifecycle,...
Definition: ReaderWriterPlugin.h:44
armarx::armem::client::plugins::ReaderWriterPlugin::get
const T & get() const
Definition: ReaderWriterPlugin.h:95
armarx::armem::client::plugins::ReaderWriterPlugin::postCreatePropertyDefinitions
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
Definition: ReaderWriterPlugin.h:60
armarx::ManagedIceObjectPlugin::addPlugin
PluginT * addPlugin(const std::string prefix="", ParamsT &&...params)
Definition: ManagedIceObjectPlugin.h:104
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::ComponentPlugin
Definition: ComponentPlugin.h:38
armarx::armem::client::plugins::ReaderWriterPlugin::preOnConnectComponent
void preOnConnectComponent() override
Definition: ReaderWriterPlugin.h:66
armarx::armem::client::plugins::ReaderWriterPlugin::get
T & get()
Definition: ReaderWriterPlugin.h:87
ExpressionException.h
armarx::armem::client::plugins::ReaderWriterPlugin::ReaderWriterPlugin
ReaderWriterPlugin(ManagedIceObject &parent, const std::string &pre)
Definition: ReaderWriterPlugin.h:47
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::client::plugins
This file is part of ArmarX.
Definition: forward_declarations.h:24
armarx::armem::client::plugins::ReaderWriterPlugin::~ReaderWriterPlugin
~ReaderWriterPlugin() override=default
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
ComponentPlugin.h
MemoryNameSystem.h
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::armem::client::plugins::Plugin
A component plugin offering client-side access to to the working memory system by providing a Memory ...
Definition: Plugin.h:20