YARP
Yet Another Robot Platform
YarpPluginSettings.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_OS_YARPPLUGINSETTINGS_H
10 #define YARP_OS_YARPPLUGINSETTINGS_H
11 
12 #include <yarp/os/api.h>
13 
14 #include <yarp/os/Log.h>
17 
18 namespace yarp {
19 namespace os {
20 
25 {
26 public:
31  wrapper_name("unknown")
32  {
33  selector = nullptr;
34  }
35 
47  void setLibraryMethodName(const std::string& dll_name,
48  const std::string& fn_name)
49  {
50  this->dll_name = dll_name;
51  this->fn_name = fn_name;
52  }
53 
61  void setPluginName(const std::string& name)
62  {
63  this->name = name;
64  }
65 
73  void setClassInfo(const std::string& class_name,
74  const std::string& baseclass_name)
75  {
76  this->class_name = class_name;
77  this->baseclass_name = baseclass_name;
78  }
79 
80 
91  {
92  this->selector = &selector;
93  if (name != "") {
94  return readFromSelector(name);
95  }
96  return false;
97  }
98 
99 #ifndef YARP_NO_DEPRECATED // Since YARP 3.4
100 
106  YARP_DEPRECATED_MSG("Use log components instead")
107  void setVerboseMode(bool verbose);
108 #endif // YARP_NO_DEPRECATED
109 
119  bool readFromSearchable(Searchable& options, const std::string& name)
120  {
121  std::string iname = options.find("library").toString();
122  std::string pname = options.find("part").toString();
123 
124  if (iname == "")
125  iname = name;
126  if (pname == "")
127  pname = name;
128 
129  if (this->name == "")
130  this->name = iname;
131  this->dll_name = iname;
132  this->fn_name = pname;
133  this->wrapper_name = options.find("wrapper").toString();
134  return true;
135  }
136 
140  std::string getPluginName() const
141  {
142  return name;
143  }
144 
148  std::string getLibraryName() const
149  {
150  return dll_name;
151  }
152 
156  std::string getMethodName() const
157  {
158  return fn_name;
159  }
160 
165  {
166  return selector;
167  }
168 
172  std::string getWrapperName() const
173  {
174  return wrapper_name;
175  }
176 
180  std::string getClassName() const
181  {
182  return class_name;
183  }
184 
188  std::string getBaseClassName() const
189  {
190  return class_name;
191  }
192 
200  bool open(SharedLibraryFactory& factory);
201 
207  void reportStatus(SharedLibraryFactory& factory) const;
208 
213  void reportFailure() const;
214 
215 private:
216  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) name;
217  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) dll_name;
218  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) fn_name;
219  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) wrapper_name;
220  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) class_name;
221  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) baseclass_name;
222  YarpPluginSelector* selector;
223 
224  bool subopen(SharedLibraryFactory& factory,
225  const std::string& dll_name,
226  const std::string& fn_name);
227 
228  bool open(SharedLibraryFactory& factory,
229  const std::string& dll_name,
230  const std::string& fn_name);
231 
232  bool readFromSelector(const std::string& name);
233 };
234 
235 } // namespace os
236 } // namespace yarp
237 
238 #endif // YARP_OS_YARPPLUGINSELECTOR_H
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:339
yarp::os::YarpPluginSettings::readFromSearchable
bool readFromSearchable(Searchable &options, const std::string &name)
Configure settings from a configuration file or other searchable object.
Definition: YarpPluginSettings.h:119
api.h
yarp::os::YarpPluginSettings::getClassName
std::string getClassName() const
Definition: YarpPluginSettings.h:180
YARP_os_API
#define YARP_os_API
Definition: api.h:19
yarp::os::YarpPluginSelector
Pick out a set of relevant plugins.
Definition: YarpPluginSelector.h:30
yarp::os::YarpPluginSettings::getWrapperName
std::string getWrapperName() const
Definition: YarpPluginSettings.h:172
yarp::os::YarpPluginSettings::setSelector
bool setSelector(YarpPluginSelector &selector)
Use a selector to find a plugin or plugins.
Definition: YarpPluginSettings.h:90
Log.h
yarp::os::YarpPluginSettings::getPluginName
std::string getPluginName() const
Definition: YarpPluginSettings.h:140
yarp::os::YarpPluginSettings::setLibraryMethodName
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.
Definition: YarpPluginSettings.h:47
yarp::os::YarpPluginSettings::setPluginName
void setPluginName(const std::string &name)
Set the name of the plugin to load.
Definition: YarpPluginSettings.h:61
yarp::os::YarpPluginSettings::getLibraryName
std::string getLibraryName() const
Definition: YarpPluginSettings.h:148
yarp::os::Searchable::find
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
yarp::os::YarpPluginSettings::setClassInfo
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.
Definition: YarpPluginSettings.h:73
yarp::os::YarpPluginSettings
Collect hints for finding a particular plugin.
Definition: YarpPluginSettings.h:25
yarp::os::SharedLibraryFactory
A wrapper for a named factory method in a named shared library.
Definition: SharedLibraryFactory.h:31
YarpPluginSelector.h
yarp::os::YarpPluginSettings::getMethodName
std::string getMethodName() const
Definition: YarpPluginSettings.h:156
yarp::os::YarpPluginSettings::getBaseClassName
std::string getBaseClassName() const
Definition: YarpPluginSettings.h:188
YARP_DEPRECATED_MSG
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2883
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::YarpPluginSettings::YarpPluginSettings
YarpPluginSettings()
Constructor.
Definition: YarpPluginSettings.h:30
yarp::os::Value::toString
std::string toString() const override
Return a standard text representation of the content of the object.
Definition: Value.cpp:359
SharedLibraryClass.h
yarp::os::YarpPluginSettings::getSelector
YarpPluginSelector * getSelector() const
Definition: YarpPluginSettings.h:164