YARP
Yet Another Robot Platform
YarpPluginSelector.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_YARPPLUGINSELECTOR_H
7 #define YARP_OS_YARPPLUGINSELECTOR_H
8 
9 #include <yarp/os/api.h>
10 
11 #include <yarp/os/Bottle.h>
12 #include <yarp/os/Property.h>
13 
14 #include <mutex>
15 
16 namespace yarp {
17 namespace os {
18 
27 {
28 private:
29  Bottle plugins;
30  Bottle search_path;
31  Property config;
32  mutable std::mutex mutex;
33 
34 public:
38  virtual ~YarpPluginSelector() = default;
39 
45  virtual bool select(Searchable& options)
46  {
47  YARP_UNUSED(options);
48  return true;
49  }
50 
51 
56  void scan();
57 
63  {
64  std::lock_guard<std::mutex> guard(mutex);
65  return plugins;
66  }
67 
73  {
74  std::lock_guard<std::mutex> guard(mutex);
75  return search_path;
76  }
77 
81  static bool checkPlugin(const std::string& name, const std::string& type = {})
82  {
84  selector.scan();
85  const yarp::os::Bottle lst = selector.getSelectedPlugins();
86  for (size_t i = 0; i < lst.size(); i++) {
87  const yarp::os::Value& options = lst.get(i);
88  if (name == options.check("name", yarp::os::Value("untitled")).asString()) {
89  if (!type.empty()) {
90  return true;
91  }
92  if (type == options.check("type", yarp::os::Value("untitled")).asString()) {
93  return true;
94  }
95  }
96  }
97  return false;
98  }
99 };
100 
101 } // namespace os
102 } // namespace yarp
103 
104 #endif // YARP_OS_YARPPLUGINSELECTOR_H
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
size_type size() const
Gets the number of elements in the bottle.
Definition: Bottle.cpp:251
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:246
A class for storing options and configuration information.
Definition: Property.h:34
A base class for nested structures that can be searched.
Definition: Searchable.h:66
A single value (typically within a Bottle).
Definition: Value.h:45
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition: Value.cpp:321
Pick out a set of relevant plugins.
virtual ~YarpPluginSelector()=default
Destructor.
void scan()
Find plugin configuration files, and run [plugin] sections through the select method.
Definition: YarpPlugin.cpp:210
static bool checkPlugin(const std::string &name, const std::string &type={})
Checks if a pluigin of the given type is available.
virtual bool select(Searchable &options)
Determine whether a plugin is of interest.
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_UNUSED(var)
Definition: api.h:162
#define YARP_os_API
Definition: api.h:18