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
15#include <yarp/dev/api.h>
16
17namespace yarp::dev {
18class DeviceDriver;
19class DeprecatedDeviceDriver;
20class DeviceResponder;
21}
22
29{
30public:
32 DeviceDriver(const DeviceDriver& other) = delete;
33 DeviceDriver(DeviceDriver&& other) noexcept = delete;
34 DeviceDriver& operator=(const DeviceDriver& other) = delete;
35 DeviceDriver& operator=(DeviceDriver&& other) noexcept = delete;
36
37 virtual ~DeviceDriver();
38
51 virtual bool open(yarp::os::Searchable& config) { YARP_UNUSED(config); return true; }
52
57 virtual bool close() { return true; }
58
59
69 virtual std::string id() const;
70
74 virtual void setId(const std::string& id);
75
85 template <class T>
86 bool view(T *&x) {
87 x = nullptr;
88
89 // This is not super-portable; and it requires RTTI compiled
90 // in. For systems on which this is a problem, suggest:
91 // either replace it with a regular cast (and warn user) or
92 // implement own method for checking interface support.
93 T *v = dynamic_cast<T *>(getImplementation());
94
95 if (v != nullptr) {
96 x = v;
97 return true;
98 }
99
100 return false;
101 }
102
111 return this;
112 }
113
114#ifndef DOXYGEN_SHOULD_SKIP_THIS
115private:
116 class Private;
117 Private* mPriv = nullptr;
118#endif
119};
120
136
137
148 public yarp::os::TypedReaderCallback<yarp::os::Bottle>
149{
150
151private:
152 yarp::os::Bottle examples;
153 yarp::os::Bottle explains;
154 yarp::os::Bottle details;
155
156public:
161
168 void addUsage(const char *txt, const char *explain = nullptr);
169
176 void addUsage(const yarp::os::Bottle& bot, const char *explain = nullptr);
177
184 virtual bool respond(const yarp::os::Bottle& command,
185 yarp::os::Bottle& reply);
186
193 bool read(yarp::os::ConnectionReader& connection) override;
194
202 void onRead(yarp::os::Bottle& v) override {
203 yarp::os::Bottle reply;
204 respond(v,reply);
205 }
206
210 void makeUsage();
211
218 source.useCallback(*this);
219 source.setReplier(*this);
220 }
221};
222
223
224#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
virtual bool close()
Close the DeviceDriver.
virtual bool open(yarp::os::Searchable &config)
Open the DeviceDriver.
bool view(T *&x)
Get an interface to the device driver.
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.
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:31
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