YARP
Yet Another Robot Platform
YarpPluginSettings.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_OS_YARPPLUGINSETTINGS_H
7 #define YARP_OS_YARPPLUGINSETTINGS_H
8 
9 #include <yarp/os/api.h>
10 
11 #include <yarp/os/Log.h>
14 
15 namespace yarp {
16 namespace os {
17 
22 {
23 public:
27  YarpPluginSettings() = default;
28 
40  void setLibraryMethodName(const std::string& dll_name,
41  const std::string& fn_name)
42  {
43  this->dll_name = dll_name;
44  this->fn_name = fn_name;
45  }
46 
54  void setPluginName(const std::string& name)
55  {
56  this->name = name;
57  }
58 
66  void setClassInfo(const std::string& class_name,
67  const std::string& baseclass_name)
68  {
69  this->class_name = class_name;
70  this->baseclass_name = baseclass_name;
71  }
72 
73 
84  {
85  this->selector = &selector;
86  if (name != "") {
87  return readFromSelector(name);
88  }
89  return false;
90  }
91 
92 #ifndef YARP_NO_DEPRECATED // Since YARP 3.4
99  YARP_DEPRECATED_MSG("Use log components instead")
100  void setVerboseMode(bool verbose);
101 #endif // YARP_NO_DEPRECATED
102 
112  bool readFromSearchable(Searchable& options, const std::string& name)
113  {
114  std::string iname = options.find("library").toString();
115  std::string pname = options.find("part").toString();
116 
117  if (iname == "") {
118  iname = name;
119  }
120  if (pname == "") {
121  pname = name;
122  }
123 
124  if (this->name == "") {
125  this->name = iname;
126  }
127  this->dll_name = iname;
128  this->fn_name = pname;
129  this->wrapper_name = options.find("wrapper").toString();
130  return true;
131  }
132 
136  std::string getPluginName() const
137  {
138  return name;
139  }
140 
144  std::string getLibraryName() const
145  {
146  return dll_name;
147  }
148 
152  std::string getMethodName() const
153  {
154  return fn_name;
155  }
156 
161  {
162  return selector;
163  }
164 
168  std::string getWrapperName() const
169  {
170  return wrapper_name;
171  }
172 
176  std::string getClassName() const
177  {
178  return class_name;
179  }
180 
184  std::string getBaseClassName() const
185  {
186  return class_name;
187  }
188 
196  bool open(SharedLibraryFactory& factory);
197 
203  void reportStatus(SharedLibraryFactory& factory) const;
204 
209  void reportFailure() const;
210 
211 private:
212  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) name;
213  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) dll_name;
214  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) fn_name;
215  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) wrapper_name {"unknown"};
216  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) class_name;
217  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) baseclass_name;
218  YarpPluginSelector* selector {nullptr};
219 
220  bool subopen(SharedLibraryFactory& factory,
221  const std::string& dll_name,
222  const std::string& fn_name);
223 
224  bool open(SharedLibraryFactory& factory,
225  const std::string& dll_name,
226  const std::string& fn_name);
227 
228  bool readFromSelector(const std::string& name);
229 };
230 
231 } // namespace os
232 } // namespace yarp
233 
234 #endif // YARP_OS_YARPPLUGINSELECTOR_H
A base class for nested structures that can be searched.
Definition: Searchable.h:66
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
A wrapper for a named factory method in a named shared library.
std::string toString() const override
Return a standard text representation of the content of the object.
Definition: Value.cpp:356
Pick out a set of relevant plugins.
Collect hints for finding a particular plugin.
bool setSelector(YarpPluginSelector &selector)
Use a selector to find a plugin or plugins.
std::string getLibraryName() const
YarpPluginSettings()=default
Constructor.
void setLibraryMethodName(const std::string &dll_name, const std::string &fn_name)
Set the name of the library to load and the method name to use as a factory.
std::string getClassName() const
std::string getWrapperName() const
bool readFromSearchable(Searchable &options, const std::string &name)
Configure settings from a configuration file or other searchable object.
YarpPluginSelector * getSelector() const
void setPluginName(const std::string &name)
Set the name of the plugin to load.
std::string getMethodName() const
std::string getBaseClassName() const
void setClassInfo(const std::string &class_name, const std::string &baseclass_name)
Set the information about the class and the base class constructed by this plugin.
std::string getPluginName() const
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:336
#define YARP_os_API
Definition: api.h:18