YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeDevice_nws_yarp.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025-2025 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7
9#include <yarp/os/LogStream.h>
10
11namespace
12{
13YARP_LOG_COMPONENT(FAKEDEVICE_NWS_YARP, "yarp.device.FakeDevice_nws_yarp")
14}
15
17{
18 if (driver->isValid())
19 {
20 driver->view(m_iFake);
21 }
22
23 if (m_iFake == nullptr)
24 {
25 yCError(FAKEDEVICE_NWS_YARP, "Subdevice passed to attach method is invalid (it does not implement all the required interfaces)");
26 return false;
27 }
28
30
31 yCDebug(FAKEDEVICE_NWS_YARP) << "Attach successful";
32
33 return true;
34}
35
37{
39 {
40 yCError(FAKEDEVICE_NWS_YARP) << "Unable to open port:" << m_rpc_port_name;
41 return false;
42 }
43
44 m_RpcPort.setReader(*this);
45
46 yCDebug(FAKEDEVICE_NWS_YARP) << "Waiting to be attached";
47
48 return true;
49}
50
52{
54 m_iFake = nullptr;
55 return true;
56}
57
59{
60 detach();
62 return true;
63}
64
66{
67 bool b = m_RPC.read(connection);
68 if (b)
69 {
70 return true;
71 }
72
73 yCWarning(FAKEDEVICE_NWS_YARP) << "read() Command failed";
74
75 return false;
76}
virtual bool open(yarp::os::Searchable &prop) override
Open the DeviceDriver.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
virtual bool detach() override
Detach the object (you must have first called attach).
const std::string m_rpc_port_name
yarp::dev::test::IFakeDeviceInterfaceTest1 * m_iFake
virtual bool attach(yarp::dev::PolyDriver *drv) override
Attach to another object.
virtual bool close() override
Close the DeviceDriver.
yarp::os::RpcServer m_RpcPort
void setInterface(yarp::dev::test::IFakeDeviceInterfaceTest1 *_iFake)
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
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.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void setReader(PortReader &reader) override
Set an external reader for port data.
void close() override
Stop port activity.
An interface for reading from a network connection.
A base class for nested structures that can be searched.
Definition Searchable.h:31
#define yCError(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)