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
52 virtual bool open(yarp::os::Searchable& config) { YARP_UNUSED(config); return true; }
53
58 virtual bool close() { return true; }
59
60
70 virtual std::string id() const;
71
75 virtual void setId(const std::string& id);
76
86 template <class T>
87 bool view(T *&x) {
88 x = nullptr;
89
90 // This is not super-portable; and it requires RTTI compiled
91 // in. For systems on which this is a problem, suggest:
92 // either replace it with a regular cast (and warn user) or
93 // implement own method for checking interface support.
94 T *v = dynamic_cast<T *>(getImplementation());
95
96 if (v != nullptr) {
97 x = v;
98 return true;
99 }
100
101 return false;
102 }
103
112 return this;
113 }
114
115#ifndef DOXYGEN_SHOULD_SKIP_THIS
116private:
117 class Private;
118 Private* mPriv = nullptr;
119#endif
120};
121
137
138
149 public yarp::os::TypedReaderCallback<yarp::os::Bottle>
150{
151
152private:
153 yarp::os::Bottle examples;
154 yarp::os::Bottle explains;
155 yarp::os::Bottle details;
156
157public:
162
169 void addUsage(const char *txt, const char *explain = nullptr);
170
177 void addUsage(const yarp::os::Bottle& bot, const char *explain = nullptr);
178
185 virtual bool respond(const yarp::os::Bottle& command,
186 yarp::os::Bottle& reply);
187
194 bool read(yarp::os::ConnectionReader& connection) override;
195
203 void onRead(yarp::os::Bottle& v) override {
204 yarp::os::Bottle reply;
205 respond(v,reply);
206 }
207
211 void makeUsage();
212
219 source.useCallback(*this);
220 source.setReplier(*this);
221 }
222};
223
224
225#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.
Definition jointData.cpp:13
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