YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
RobotDescription_nwc_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#include <yarp/os/Log.h>
9#include <yarp/os/LogStream.h>
10
11using namespace yarp::dev;
12using namespace yarp::os;
13using namespace yarp::sig;
14
15
16namespace {
17YARP_LOG_COMPONENT(ROBOTDESCRIPTION_NWC_YARP, "yarp.device.robotDescription_nwc_yarp")
18}
19
20
21//------------------------------------------------------------------------------------------------------------------------------
22
24{
25 if (!this->parseParams(config)) { return false; }
26
28 {
29 yCError(ROBOTDESCRIPTION_NWC_YARP, "open(): Could not open rpc port %s, check network", m_local.c_str());
30 return false;
31 }
32
33
34 bool ok = true;
35
36 ok = Network::connect(m_local, m_remote);
37 if (!ok)
38 {
39 yCError(ROBOTDESCRIPTION_NWC_YARP, "open(): Could not connect to %s", m_remote.c_str());
40 return false;
41 }
42
44 {
45 yCError(ROBOTDESCRIPTION_NWC_YARP, "Error! Cannot attach the port as a client");
46 return false;
47 }
48
49 // Check the protocol version
51 return false;
52 }
53
54 return true;
55}
56
58{
60
61 return true;
62}
63
64yarp::dev::ReturnValue RobotDescription_nwc_yarp::getAllDevicesByType(const std::string &type, std::vector<DeviceDescription>& dev_list)
65{
66 std::lock_guard<std::mutex> lg(m_mutex);
67 auto ret = m_RPC.getAllDevicesByTypeRPC(type);
68 if (!ret.ret) {
69 yCError(ROBOTDESCRIPTION_NWC_YARP, "Unable to getAllDevicesByType");
70 return ret.ret;
71 }
72 dev_list = ret.devices;
73 return ReturnValue_ok;
74}
75
77{
78 std::lock_guard<std::mutex> lg(m_mutex);
79 auto ret = m_RPC.unregisterDeviceRPC(device_name);
80 if (!ret) {
81 yCError(ROBOTDESCRIPTION_NWC_YARP, "Unable to unregisterDevice");
82 return ret;
83 }
84 return ReturnValue_ok;
85}
86
88{
89 std::lock_guard<std::mutex> lg(m_mutex);
90 auto ret = m_RPC.registerDeviceRPC(dev);
91 if (!ret) {
92 yCError(ROBOTDESCRIPTION_NWC_YARP, "Unable to registerDevice");
93 return ret;
94 }
95 return ReturnValue_ok;
96}
97
98
100{
101 std::lock_guard<std::mutex> lg(m_mutex);
103 if (!ret.ret) {
104 yCError(ROBOTDESCRIPTION_NWC_YARP, "Unable to getAllDevices");
105 return ret.ret;
106 }
107 dev_list = ret.devices;
108 return ReturnValue_ok;
109}
110
112{
113 std::lock_guard<std::mutex> lg(m_mutex);
114 auto ret = m_RPC.unregisterAllRPC();
115 if (!ret) {
116 yCError(ROBOTDESCRIPTION_NWC_YARP, "Unable to unregisterAll");
117 return ret;
118 }
119 return ReturnValue_ok;
120}
bool ret
#define ReturnValue_ok
Definition ReturnValue.h:80
virtual yarp::dev::ReturnValue unregisterAllRPC()
virtual return_getAllDevices getAllDevicesRPC()
virtual return_getAllDevicesByType getAllDevicesByTypeRPC(const std::string &type)
virtual yarp::dev::ReturnValue registerDeviceRPC(const yarp::dev::DeviceDescription &dev)
virtual yarp::dev::ReturnValue unregisterDeviceRPC(const std::string &dev)
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
yarp::dev::ReturnValue unregisterAll() override
Unregister all the devices.
yarp::dev::ReturnValue unregisterDevice(const std::string &device_name) override
Unregister a running yarp device from a robot description server.
yarp::dev::ReturnValue registerDevice(const yarp::dev::DeviceDescription &dev) override
Register a new running yarp device into a robot description server.
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue getAllDevicesByType(const std::string &type, std::vector< yarp::dev::DeviceDescription > &dev_list) override
Ask a list of all registered yarp device drivers whose type corresponds to the given param.
yarp::dev::ReturnValue getAllDevices(std::vector< yarp::dev::DeviceDescription > &dev_list) override
Ask the complete list of all yarp device drivers registered by a robot description server.
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
Definition Port.cpp:330
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
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition Wire.h:28
#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.