YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
RobotDescription_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
8#include <yarp/os/Log.h>
10#include <yarp/os/LogStream.h>
11#include <mutex>
12
13using namespace yarp::dev;
14using namespace yarp::os;
15
16namespace {
17YARP_LOG_COMPONENT(ROBOTDESCRIPTION_NWS_YARP, "yarp.device.robotDescription_nws_yarp")
18}
19
21{
22 std::lock_guard <std::mutex> lg(m_mutex);
23
24 std::vector<DeviceDescription> dev_list;
26 retval.ret = m_istorage->getAllDevices(dev_list);
27 if (retval.ret) {
28 retval.devices = dev_list;
29 } else {
30 yCError(ROBOTDESCRIPTION_NWS_YARP, "Unable to getAllDevices");
31 }
32 return retval;
33}
34
36{
37 std::lock_guard <std::mutex> lg(m_mutex);
38
39 std::vector<DeviceDescription> dev_list;
41 retval.ret = m_istorage->getAllDevicesByType(type, dev_list);
42 if (retval.ret) {
43 retval.devices = dev_list;
44 } else {
45 yCError(ROBOTDESCRIPTION_NWS_YARP, "Unable to getAllDevicesByType");
46 }
47 return retval;
48}
49
51{
52 std::lock_guard <std::mutex> lg(m_mutex);
53
54 auto ret = m_istorage->registerDevice(dev);
55 if (!ret)
56 {
57 yCError(ROBOTDESCRIPTION_NWS_YARP, "Unable to registerDevice");
58 }
59 return ret;
60}
61
63{
64 std::lock_guard <std::mutex> lg(m_mutex);
65
66 auto ret = m_istorage->unregisterDevice(dev);
67 if (!ret)
68 {
69 yCError(ROBOTDESCRIPTION_NWS_YARP, "Unable to unregisterDevice");
70 }
71 return ret;
72}
73
75{
76 std::lock_guard <std::mutex> lg(m_mutex);
77
78 auto ret = m_istorage->unregisterAll();
79 if (!ret)
80 {
81 yCError(ROBOTDESCRIPTION_NWS_YARP, "Unable to unregisterAll");
82 }
83 return ret;
84}
85
86//------------------------------------------------------------------------------------------------------------------------------
87
89{
90 if (!this->parseParams(config)) { return false; }
91
93 {
94 yCError(ROBOTDESCRIPTION_NWS_YARP, "open(): Could not open rpc port %s, check network", m_local.c_str());
95 return false;
96 }
97
98 m_rpc_port.setReader(*this);
99 return true;
100}
101
103{
104 std::lock_guard lock(m_mutex);
105
106 if (driver->isValid())
107 {
108 IRobotDescription* ird = nullptr;
109 driver->view(ird);
110 if (!ird)
111 {
112 yCError(ROBOTDESCRIPTION_NWS_YARP, "Subdevice passed to attach method is invalid");
113 return false;
114 }
115 m_RPC = std::make_unique<IRobotDescriptiond>(ird);
116 }
117
118 yCInfo(ROBOTDESCRIPTION_NWS_YARP, "Attach done");
119 return true;
120}
121
123{
124 std::lock_guard lock (m_mutex);
125 m_RPC.reset();
126 return true;
127}
128
130{
132 return true;
133}
134
136{
137 if (!connection.isValid()) { return false;}
138 if (!m_RPC) { return false;}
139
140 std::lock_guard<std::mutex> lock(m_mutex);
141 if (m_RPC)
142 {
143 bool b = m_RPC->read(connection);
144 if (b) {
145 return true;
146 }
147 }
148
149 yCDebug(ROBOTDESCRIPTION_NWS_YARP) << "read() Command failed";
150 return false;
151}
bool ret
virtual yarp::dev::ReturnValue unregisterAllRPC() override
virtual return_getAllDevices getAllDevicesRPC() override
virtual yarp::dev::ReturnValue registerDeviceRPC(const yarp::dev::DeviceDescription &dev) override
virtual return_getAllDevicesByType getAllDevicesByTypeRPC(const std::string &type) override
virtual yarp::dev::ReturnValue unregisterDeviceRPC(const std::string &dev) override
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
std::unique_ptr< IRobotDescriptiond > m_RPC
bool attach(yarp::dev::PolyDriver *driver) override
Attach to another object.
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool detach() override
Detach the object (you must have first called attach).
std::vector< yarp::dev::DeviceDescription > devices
yarp::dev::ReturnValue ret
std::vector< yarp::dev::DeviceDescription > devices
bool view(T *&x)
Get an interface to the device driver.
This interface allows users to retrieve a list which contains the names and the types of the currentl...
virtual yarp::dev::ReturnValue registerDevice(const DeviceDescription &dev)=0
Register a new running yarp device into a robot description server.
virtual yarp::dev::ReturnValue getAllDevices(std::vector< DeviceDescription > &dev_list)=0
Ask the complete list of all yarp device drivers registered by a robot description server.
virtual yarp::dev::ReturnValue unregisterDevice(const std::string &device_name)=0
Unregister a running yarp device from a robot description server.
virtual yarp::dev::ReturnValue unregisterAll()=0
Unregister all the devices.
virtual yarp::dev::ReturnValue getAllDevicesByType(const std::string &type, std::vector< DeviceDescription > &dev_list)=0
Ask a list of all registered yarp device drivers whose type corresponds to the given param.
A container for a device driver.
Definition PolyDriver.h:23
bool isValid() const
Check if device is valid.
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
virtual bool isValid() const =0
void setReader(PortReader &reader) override
Set an external reader for port data.
Definition Port.cpp:511
void close() override
Stop port activity.
Definition Port.cpp:363
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
#define yCInfo(component,...)
#define yCError(component,...)
#define yCDebug(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.