YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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
16namespace yarp::os {
17
26{
27private:
28 Bottle plugins;
29 Bottle search_path;
30 Property config;
31 mutable std::mutex mutex;
32
33public:
37 virtual ~YarpPluginSelector() = default;
38
44 virtual bool select(Searchable& options)
45 {
46 YARP_UNUSED(options);
47 return true;
48 }
49
50
55 void scan();
56
62 {
63 std::lock_guard<std::mutex> guard(mutex);
64 return plugins;
65 }
66
72 {
73 std::lock_guard<std::mutex> guard(mutex);
74 return search_path;
75 }
76
80 static bool checkPlugin(const std::string& name, const std::string& type = {})
81 {
83 selector.scan();
84 const yarp::os::Bottle lst = selector.getSelectedPlugins();
85 for (size_t i = 0; i < lst.size(); i++) {
86 const yarp::os::Value& options = lst.get(i);
87 if (name == options.check("name", yarp::os::Value("untitled")).asString()) {
88 if (!type.empty()) {
89 return true;
90 }
91 if (type == options.check("type", yarp::os::Value("untitled")).asString()) {
92 return true;
93 }
94 }
95 }
96 return false;
97 }
98};
99
100} // namespace yarp::os
101
102#endif // YARP_OS_YARPPLUGINSELECTOR_H
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
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 mini-server for performing network communication in the background.
A class for storing options and configuration information.
Definition Property.h:33
A base class for nested structures that can be searched.
Definition Searchable.h:31
A single value (typically within a Bottle).
Definition Value.h:43
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.
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.
An interface to the operating system, including Port based communication.
#define YARP_UNUSED(var)
Definition api.h:162
#define YARP_os_API
Definition api.h:18