YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeDeviceWrapper.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024-2024 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "FakeDeviceWrapper.h"
7
8#include <yarp/os/Log.h>
10#include <yarp/os/LogStream.h>
12
13using namespace yarp::os;
14using namespace yarp::dev;
15
16namespace {
17YARP_LOG_COMPONENT(FAKEDEVICEWRAPPER, "yarp.device.fakeDeviceWrapper")
18}
19
21{
22 if (!iTest) { yCError(FAKEDEVICEWRAPPER) << "Invalid/not yet attached interface"; }
23
24 yCInfo(FAKEDEVICEWRAPPER) << "testSetValue() called";
25 return iTest->testSetValue(value);
26}
27
29{
30 if (!iTest) { yCError(FAKEDEVICEWRAPPER) << "Invalid/not yet attached interface"; }
31
32 yCInfo(FAKEDEVICEWRAPPER) << "testGetValue() called";
33 return iTest->testGetValue(value);
34}
35
37{
38 this->m_RpcPort.open("/FakeDeviceWrapper/rpc");
39 m_RpcPort.setReader(*this);
40
41 yCInfo(FAKEDEVICEWRAPPER) << "FakeDeviceWrapper opened";
42 return true;
43}
44
46{
47 yCInfo(FAKEDEVICEWRAPPER) << "FakeDeviceWrapper closed";
48 return true;
49}
50
52{
53 iTest=nullptr;
54 return true;
55}
56
58{
59 if (drv->isValid())
60 {
61 drv->view(iTest);
62 return true;
63 }
64 return false;
65}
66
68{
69 yarp::os::Bottle command;
70 yarp::os::Bottle reply;
71 ReturnValue retval;
72
73 bool ok = command.read(connection);
74 if (!ok) {
75 return false;
76 }
77 reply.clear();
78
79 if (command.get(0).asString() == "testSetValue")
80 {
81 retval = testSetValue(1);
82 if (retval) {reply.addVocab32(VOCAB_OK);}
83 else {reply.addVocab32(VOCAB_ERR);}
84 }
85 else
86 if (command.get(0).asString() == "testGetValue")
87 {
88 int val=0;
89 retval = testGetValue(val);
90 if (retval) {
91 reply.addVocab32(VOCAB_OK);
92 }
93 else {
94 reply.addVocab32(VOCAB_ERR);
95 }
96 }
97 else
98 {
99 reply.addVocab32(VOCAB_ERR);
100 }
101
103 if (returnToSender != nullptr)
104 {
105 reply.write(*returnToSender);
106 }
107 return true;
108}
define control board standard interfaces
constexpr yarp::conf::vocab32_t VOCAB_OK
constexpr yarp::conf::vocab32_t VOCAB_ERR
bool detach() override
Detach the object (you must have first called attach).
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue testGetValue(int &value) override
This method is used to get a single value from a test device.
yarp::dev::ReturnValue testSetValue(int value) override
This method is used to set a single value inside the test device.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool attach(yarp::dev::PolyDriver *drv) override
Attach to another object.
bool view(T *&x)
Get an interface to the device driver.
A container for a device driver.
Definition PolyDriver.h:23
bool isValid() const
Check if device is valid.
virtual yarp::dev::ReturnValue testGetValue(int &value)=0
This method is used to get a single value from a test device.
virtual yarp::dev::ReturnValue testSetValue(int value)=0
This method is used to set a single value inside the test device.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
void addVocab32(yarp::conf::vocab32_t x)
Places a 32 bit vocabulary item in the bottle, at the end of the list.
Definition Bottle.cpp:164
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Definition Bottle.cpp:241
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:247
void clear()
Empties the bottle of any objects it contains.
Definition Bottle.cpp:121
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
Definition Bottle.cpp:231
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
An interface for writing to a network connection.
void setReader(PortReader &reader) override
Set an external reader for port data.
Definition Port.cpp:470
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual std::string asString() const
Get string value.
Definition Value.cpp:240
#define yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.