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