YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
RobotDescriptionStorage.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>
11
12using namespace yarp::dev;
13using namespace yarp::os;
14
15namespace {
16YARP_LOG_COMPONENT(ROBOTDESCRIPTIONSTORAGE, "yarp.device.robotDescriptionStorage")
17}
18
20{
21 dev_list = m_devices;
22 return ReturnValue_ok;
23}
24
25yarp::dev::ReturnValue RobotDescriptionStorage::getAllDevicesByType(const std::string &type, std::vector<yarp::dev::DeviceDescription>& dev_list)
26{
27 dev_list.clear();
28 for (auto it = m_devices.begin(); it != m_devices.end(); it++)
29 {
30 if (it->device_type == type)
31 {
32 dev_list.push_back(*it);
33 }
34 }
35 return ReturnValue_ok;
36}
37
39{
40 if (add_device(dev)) {
41 return ReturnValue_ok;
42 }
43 return ReturnValue::return_code::return_value_error_method_failed;
44}
45
47{
48 if (remove_device(device_name)) {
49 return ReturnValue_ok;
50 }
51 return ReturnValue::return_code::return_value_error_method_failed;
52}
53
59
60bool RobotDescriptionStorage::add_device(DeviceDescription dev)
61{
62 std::lock_guard<std::recursive_mutex> guard(m_recmutex);
63 for (auto& m_robot_device : m_devices)
64 {
65 if (dev.device_name == m_robot_device.device_name)
66 {
67 yCWarning(ROBOTDESCRIPTIONSTORAGE) << "add_device(): Device" << dev.device_name << "already exists, skipping";
68 return false;
69 }
70 }
71 m_devices.push_back(dev);
72 return true;
73}
74
75bool RobotDescriptionStorage::remove_device(const std::string& device_name)
76{
77 std::lock_guard<std::recursive_mutex> guard(m_recmutex);
78 for (auto it = m_devices.begin(); it != m_devices.end(); it++)
79 {
80 if (device_name == it->device_name)
81 {
82 m_devices.erase(it);
83 return true;
84 }
85 }
86 return false;
87}
88
90{
91 std::lock_guard<std::recursive_mutex> guard(m_recmutex);
92
93 bool raise_error = false;
94 for (int i = 0; i < p.size(); i++)
95 {
97
99 dev.device_name = pd->key;
100 dev.device_type = pd->poly->id();
102 pd->poly->view(icparams);
103 if (icparams)
104 {
105 dev.device_configuration = icparams->getConfiguration();
106 }
107
108 if (dev.device_name == "")
109 {
110 yCError(ROBOTDESCRIPTIONSTORAGE) << "Invalid device name for device type:" << dev.device_type << ", counter id:" << i;
111 raise_error = true;
112 continue;
113 }
114 if (dev.device_type.empty())
115 {
116 yCError(ROBOTDESCRIPTIONSTORAGE) << "Invalid device type for device name:" << dev.device_name << ", counter id:" << i;
117 raise_error = true;
118 continue;
119 }
120 if (!icparams || dev.device_configuration.empty())
121 {
122 yCError(ROBOTDESCRIPTIONSTORAGE) << "Unable to get configuration for device:" << dev.device_name << ", counter id:" << i;
123 }
124
125 auto ret = registerDevice(dev);
126 if (!ret)
127 {
128 yCError(ROBOTDESCRIPTIONSTORAGE) << "Unable to register device";
129 raise_error = true;
130 continue;
131 }
132 }
133
134 if (raise_error)
135 {
136 yCError(ROBOTDESCRIPTIONSTORAGE) << "attachAll() encountered one or more errors. Not all devices have been registered";
137 //return false; //This was intentionally disabled. Yarprobotinterface will close if one attach fails.
138 }
139 return true;
140}
141
143{
144 //Clear the storage
146
147 return true;
148}
bool ret
#define ReturnValue_ok
Definition ReturnValue.h:77
yarp::dev::ReturnValue registerDevice(const yarp::dev::DeviceDescription &dev) override
Register a new running yarp device into a robot description server.
yarp::dev::ReturnValue unregisterDevice(const std::string &device_name) override
Unregister a running yarp device from a robot description server.
yarp::dev::ReturnValue unregisterAll() override
Unregister all the devices.
bool attachAll(const yarp::dev::PolyDriverList &l) override
Attach to a list of objects.
bool detachAll() override
Detach the object (you must have first called attach).
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.
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.
std::string device_configuration
configuration parameters of the device
std::string device_type
type of the device
std::string device_name
name of the device
An interface for the management of the parameters of a DeviceDriver.
A mini-server for performing network communication in the background.
#define yCError(component,...)
#define yCWarning(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.