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#include <map>
16
17namespace yarp::os {
18
27{
28private:
29 Bottle plugins;
30 Bottle search_path;
31 Property config;
32 mutable std::mutex mutex;
33
34 // Populated during scan() from "deprecated_alias" fields in .ini files
35 std::map<std::string, std::string> deprecated_aliases;
36
37public:
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
61 // Returns the map of deprecated alias -> canonical name,
62 // populated from "deprecated_alias" fields in plugin .ini files.
63 std::map<std::string, std::string> getDeprecatedAliases() const
64 {
65 return deprecated_aliases;
66 }
67
73 {
74 std::lock_guard<std::mutex> guard(mutex);
75 return plugins;
76 }
77
83 {
84 std::lock_guard<std::mutex> guard(mutex);
85 return search_path;
86 }
87
91 static bool checkPlugin(const std::string& name, const std::string& type = {})
92 {
94 selector.scan();
95 const yarp::os::Bottle lst = selector.getSelectedPlugins();
96 for (size_t i = 0; i < lst.size(); i++) {
97 const yarp::os::Value& options = lst.get(i);
98 if (name == options.check("name", yarp::os::Value("untitled")).asString()) {
99 if (!type.empty()) {
100 return true;
101 }
102 if (type == options.check("type", yarp::os::Value("untitled")).asString()) {
103 return true;
104 }
105 }
106 }
107 return false;
108 }
109};
110
111} // namespace yarp::os
112
113#endif // YARP_OS_YARPPLUGINSELECTOR_H
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:65
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:257
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:252
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:44
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition Value.cpp:333
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.
std::map< std::string, std::string > getDeprecatedAliases() const
An interface to the operating system, including Port based communication.
Definition OSTestMsg.cpp:13
#define YARP_UNUSED(var)
Definition api.h:162
#define YARP_os_API
Definition api.h:18