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::os {
16 
21 {
22 public:
26  YarpPluginSettings() = default;
27 
39  void setLibraryMethodName(const std::string& dll_name,
40  const std::string& fn_name)
41  {
42  this->dll_name = dll_name;
43  this->fn_name = fn_name;
44  }
45 
53  void setPluginName(const std::string& name)
54  {
55  this->name = name;
56  }
57 
65  void setClassInfo(const std::string& class_name,
66  const std::string& baseclass_name)
67  {
68  this->class_name = class_name;
69  this->baseclass_name = baseclass_name;
70  }
71 
72 
83  {
84  this->selector = &selector;
85  if (name != "") {
86  return readFromSelector(name);
87  }
88  return false;
89  }
90 
91 #ifndef YARP_NO_DEPRECATED // Since YARP 3.4
98  YARP_DEPRECATED_MSG("Use log components instead")
99  void setVerboseMode(bool verbose);
100 #endif // YARP_NO_DEPRECATED
101 
111  bool readFromSearchable(Searchable& options, const std::string& name)
112  {
113  std::string iname = options.find("library").toString();
114  std::string pname = options.find("part").toString();
115 
116  if (iname == "") {
117  iname = name;
118  }
119  if (pname == "") {
120  pname = name;
121  }
122 
123  if (this->name == "") {
124  this->name = iname;
125  }
126  this->dll_name = iname;
127  this->fn_name = pname;
128  this->wrapper_name = options.find("wrapper").toString();
129  return true;
130  }
131 
135  std::string getPluginName() const
136  {
137  return name;
138  }
139 
143  std::string getLibraryName() const
144  {
145  return dll_name;
146  }
147 
151  std::string getMethodName() const
152  {
153  return fn_name;
154  }
155 
160  {
161  return selector;
162  }
163 
167  std::string getWrapperName() const
168  {
169  return wrapper_name;
170  }
171 
175  std::string getClassName() const
176  {
177  return class_name;
178  }
179 
183  std::string getBaseClassName() const
184  {
185  return class_name;
186  }
187 
195  bool open(SharedLibraryFactory& factory);
196 
202  void reportStatus(SharedLibraryFactory& factory) const;
203 
208  void reportFailure() const;
209 
210 private:
211  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) name;
212  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) dll_name;
213  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) fn_name;
214  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) wrapper_name {"unknown"};
215  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) class_name;
216  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) baseclass_name;
217  YarpPluginSelector* selector {nullptr};
218 
219  bool subopen(SharedLibraryFactory& factory,
220  const std::string& dll_name,
221  const std::string& fn_name);
222 
223  bool open(SharedLibraryFactory& factory,
224  const std::string& dll_name,
225  const std::string& fn_name);
226 
227  bool readFromSelector(const std::string& name);
228 };
229 
230 } // namespace yarp::os
231 
232 #endif // YARP_OS_YARPPLUGINSELECTOR_H
A base class for nested structures that can be searched.
Definition: Searchable.h:63
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
An interface to the operating system, including Port based communication.
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:338
#define YARP_os_API
Definition: api.h:18