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 //protocol check
50 //to be added here
51
52 return true;
53}
54
56{
58
59 return true;
60}
61
62yarp::dev::ReturnValue RobotDescription_nwc_yarp::getAllDevicesByType(const std::string &type, std::vector<DeviceDescription>& dev_list)
63{
64 std::lock_guard<std::mutex> lg(m_mutex);
65 auto ret = m_RPC.getAllDevicesByTypeRPC(type);
66 if (!ret.ret) {
67 yCError(ROBOTDESCRIPTION_NWC_YARP, "Unable to getAllDevicesByType");
68 return ret.ret;
69 }
70 dev_list = ret.devices;
71 return ReturnValue_ok;
72}
73
75{
76 std::lock_guard<std::mutex> lg(m_mutex);
77 auto ret = m_RPC.unregisterDeviceRPC(device_name);
78 if (!ret) {
79 yCError(ROBOTDESCRIPTION_NWC_YARP, "Unable to unregisterDevice");
80 return ret;
81 }
82 return ReturnValue_ok;
83}
84
86{
87 std::lock_guard<std::mutex> lg(m_mutex);
88 auto ret = m_RPC.registerDeviceRPC(dev);
89 if (!ret) {
90 yCError(ROBOTDESCRIPTION_NWC_YARP, "Unable to registerDevice");
91 return ret;
92 }
93 return ReturnValue_ok;
94}
95
96
98{
99 std::lock_guard<std::mutex> lg(m_mutex);
101 if (!ret.ret) {
102 yCError(ROBOTDESCRIPTION_NWC_YARP, "Unable to getAllDevices");
103 return ret.ret;
104 }
105 dev_list = ret.devices;
106 return ReturnValue_ok;
107}
108
110{
111 std::lock_guard<std::mutex> lg(m_mutex);
112 auto ret = m_RPC.unregisterAllRPC();
113 if (!ret) {
114 yCError(ROBOTDESCRIPTION_NWC_YARP, "Unable to unregisterAll");
115 return ret;
116 }
117 return ReturnValue_ok;
118}
bool ret
#define ReturnValue_ok
Definition ReturnValue.h:77
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: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
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.