YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
DeviceDriver.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_DEV_DEVICEDRIVER_H
8#define YARP_DEV_DEVICEDRIVER_H
9
13#include <yarp/os/Property.h>
14#include <yarp/os/IConfig.h>
15
16#include <yarp/dev/api.h>
17
18namespace yarp::dev {
19class DeviceDriver;
20class DeprecatedDeviceDriver;
21class DeviceResponder;
22}
23
30{
31public:
33 DeviceDriver(const DeviceDriver& other) = delete;
34 DeviceDriver(DeviceDriver&& other) noexcept = delete;
35 DeviceDriver& operator=(const DeviceDriver& other) = delete;
36 DeviceDriver& operator=(DeviceDriver&& other) noexcept = delete;
37
38 ~DeviceDriver() override;
39
53 bool open(yarp::os::Searchable& config) override { YARP_UNUSED(config); return true; }
54
59 bool close() override { return true; }
60
61
71 virtual std::string id() const;
72
76 virtual void setId(const std::string& id);
77
87 template <class T>
88 bool view(T *&x) {
89 x = nullptr;
90
91 // This is not super-portable; and it requires RTTI compiled
92 // in. For systems on which this is a problem, suggest:
93 // either replace it with a regular cast (and warn user) or
94 // implement own method for checking interface support.
95 T *v = dynamic_cast<T *>(getImplementation());
96
97 if (v != nullptr) {
98 x = v;
99 return true;
100 }
101
102 return false;
103 }
104
113 return this;
114 }
115
116#ifndef DOXYGEN_SHOULD_SKIP_THIS
117private:
118 class Private;
119 Private* mPriv = nullptr;
120#endif
121};
122
138
139
150 public yarp::os::TypedReaderCallback<yarp::os::Bottle>
151{
152
153private:
154 yarp::os::Bottle examples;
155 yarp::os::Bottle explains;
156 yarp::os::Bottle details;
157
158public:
163
170 void addUsage(const char *txt, const char *explain = nullptr);
171
178 void addUsage(const yarp::os::Bottle& bot, const char *explain = nullptr);
179
186 virtual bool respond(const yarp::os::Bottle& command,
187 yarp::os::Bottle& reply);
188
195 bool read(yarp::os::ConnectionReader& connection) override;
196
204 void onRead(yarp::os::Bottle& v) override {
205 yarp::os::Bottle reply;
206 respond(v,reply);
207 }
208
212 void makeUsage();
213
220 source.useCallback(*this);
221 source.setReplier(*this);
222 }
223};
224
225
226#endif // YARP_DEV_DEVICEDRIVER_H
Interface implemented by deprecated device drivers.
Interface implemented by all device drivers.
virtual void setId(const std::string &id)
Set the id for this device.
virtual DeviceDriver * getImplementation()
Some drivers are bureaucrats, pointing at others.
DeviceDriver & operator=(DeviceDriver &&other) noexcept=delete
virtual std::string id() const
Return the id assigned to the PolyDriver.
DeviceDriver(const DeviceDriver &other)=delete
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool view(T *&x)
Get an interface to the device driver.
bool close() override
Close the DeviceDriver.
DeviceDriver & operator=(const DeviceDriver &other)=delete
DeviceDriver(DeviceDriver &&other) noexcept=delete
A cheap and cheerful framework for human readable/writable forms of messages to devices.
void onRead(yarp::os::Bottle &v) override
Alternative handler for reading messages from the network, and passing them on to the respond() metho...
void attach(yarp::os::TypedReader< yarp::os::Bottle > &source)
Attach this object to a source of messages.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
A mini-server for performing network communication in the background.
void useCallback(TypedReaderCallback< T > &callback) override
Set an object whose onRead method will be called when data is available.
void setReplier(PortReader &reader) override
If a message is received that requires a reply, use this handler.
An interface for reading from a network connection.
An object that can be configured.
Definition IConfig.h:23
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
A base class for nested structures that can be searched.
Definition Searchable.h:56
A callback for typed data from a port.
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_UNUSED(var)
Definition api.h:162
#define YARP_dev_API
Definition api.h:18