YARP
Yet Another Robot Platform
Drivers.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef YARP_DRIVERS_H
8#define YARP_DRIVERS_H
9
10#include <yarp/os/Network.h>
11#include <yarp/os/Property.h>
13
14namespace yarp::dev {
15template <class T>
16class DriverCreatorOf;
17class DriverCreator;
18class Drivers;
19class PolyDriver;
20class StubDriverCreator;
21}
22
28public:
32 virtual ~DriverCreator() {}
33
38 virtual std::string toString() const = 0;
39
43 virtual DeviceDriver *create() const = 0;
44
49 virtual std::string getName() const = 0;
50
57 virtual std::string getWrapper() const = 0;
58
64 virtual std::string getCode() const = 0;
65
72 virtual PolyDriver *owner() {
73 return nullptr;
74 }
75};
76
80template <class T>
82private:
83 std::string desc, wrap, code;
84public:
98 DriverCreatorOf(const char *name, const char *wrap, const char *code) :
99 desc(name), wrap(wrap), code(code)
100 {
101 }
102
103 std::string toString() const override {
104 return desc;
105 }
106
107 std::string getName() const override {
108 return desc;
109 }
110
111 std::string getWrapper() const override {
112 return wrap;
113 }
114
115 std::string getCode() const override {
116 return code;
117 }
118
119 DeviceDriver *create() const override {
120 return new T;
121 }
122};
123
124
125
130private:
131 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) desc, wrap, code, libname, fnname;
132public:
133 StubDriverCreator(const char *name, const char *wrap, const char *code,
134 const char *libname, const char *fnname) :
135 desc(name), wrap(wrap), code(code), libname(libname), fnname(fnname)
136 {
137 }
138
139 std::string toString() const override {
140 return desc;
141 }
142
143 std::string getName() const override {
144 return desc;
145 }
146
147 std::string getWrapper() const override {
148 return wrap;
149 }
150
151 std::string getCode() const override {
152 return code;
153 }
154
155 DeviceDriver *create() const override;
156};
157
158
159
172public:
177 static Drivers& factory();
189 DeviceDriver *open(const char *device) {
191 p.put("device",device);
192 return open(p);
193 }
194
208 virtual DeviceDriver *open(yarp::os::Searchable& config);
209
214 virtual std::string toString() const;
215
219 virtual ~Drivers();
220
227 void add(DriverCreator *creator);
228
229
235 DriverCreator *find(const char *name);
236
242 bool remove(const char *name);
243
250 static int yarpdev(int argc, char *argv[]);
251
252private:
253 Drivers();
254
255#ifndef DOXYGEN_SHOULD_SKIP_THIS
256private:
257 class Private;
258 Private* mPriv;
259#endif // DOXYGEN_SHOULD_SKIP_THIS
260};
261
262#endif // YARP_DRIVERS_H
Interface implemented by all device drivers.
Definition: DeviceDriver.h:30
A factory for creating driver objects of a particular type.
Definition: Drivers.h:81
DriverCreatorOf(const char *name, const char *wrap, const char *code)
Constructor.
Definition: Drivers.h:98
std::string getName() const override
Get the common name of the device.
Definition: Drivers.h:107
std::string getWrapper() const override
Get the common name of a device that can wrap this one.
Definition: Drivers.h:111
std::string toString() const override
Returns a simple description of devices the factory can make.
Definition: Drivers.h:103
std::string getCode() const override
Get the name of the C++ class associated with this device.
Definition: Drivers.h:115
DeviceDriver * create() const override
Create a device.
Definition: Drivers.h:119
A base class for factories that create driver objects.
Definition: Drivers.h:27
virtual std::string getName() const =0
Get the common name of the device.
virtual std::string getCode() const =0
Get the name of the C++ class associated with this device.
virtual PolyDriver * owner()
For "links" to other devices.
Definition: Drivers.h:72
virtual std::string getWrapper() const =0
Get the common name of a device that can wrap this one.
virtual ~DriverCreator()
Destructor.
Definition: Drivers.h:32
virtual std::string toString() const =0
Returns a simple description of devices the factory can make.
virtual DeviceDriver * create() const =0
Create a device.
Global factory for devices.
Definition: Drivers.h:171
DeviceDriver * open(const char *device)
Create and configure a device, by name.
Definition: Drivers.h:189
A container for a device driver.
Definition: PolyDriver.h:23
A factory for creating driver objects from DLLs / shared libraries.
Definition: Drivers.h:129
std::string toString() const override
Returns a simple description of devices the factory can make.
Definition: Drivers.h:139
StubDriverCreator(const char *name, const char *wrap, const char *code, const char *libname, const char *fnname)
Definition: Drivers.h:133
std::string getCode() const override
Get the name of the C++ class associated with this device.
Definition: Drivers.h:151
std::string getName() const override
Get the common name of the device.
Definition: Drivers.h:143
std::string getWrapper() const override
Get the common name of a device that can wrap this one.
Definition: Drivers.h:147
A class for storing options and configuration information.
Definition: Property.h:33
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition: Property.cpp:1015
A base class for nested structures that can be searched.
Definition: Searchable.h:56
For streams capable of holding different kinds of content, check what they actually have.
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:338
#define YARP_dev_API
Definition: api.h:18