YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Map2D_nwc_yarp.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
8#include "Map2D_nwc_yarp.h"
9#include <yarp/os/Log.h>
11#include <yarp/os/LogStream.h>
12#include <mutex>
15
16using namespace yarp::dev;
17using namespace yarp::dev::Nav2D;
18using namespace yarp::os;
19using namespace yarp::sig;
20
21namespace {
22YARP_LOG_COMPONENT(MAP2D_NWC_YARP, "yarp.device.map2D_nwc_yarp")
23}
24
25//------------------------------------------------------------------------------------------------------------------------------
26
28{
29 if (!parseParams(config)) { return false; }
30
31 std::string local_rpc1 = m_local;
32 local_rpc1 += "/mapClient_rpc";
33
34 std::string remote_rpc1 = m_remote;
35 remote_rpc1 += "/rpc";
36
38 {
39 yCError(MAP2D_NWC_YARP, "open() error could not open rpc port %s, check network", local_rpc1.c_str());
40 return false;
41 }
42
43 bool ok=false;
44 ok=Network::connect(local_rpc1, remote_rpc1, m_carrier);
45 if (!ok)
46 {
47 yCError(MAP2D_NWC_YARP, "open() error could not connect to %s", remote_rpc1.c_str());
48 return false;
49 }
50
52 {
53 yCError(MAP2D_NWC_YARP, "Error! Cannot attach the port as a client");
54 return false;
55 }
56
57 //Check the protocol version
58 if (!m_map_RPC.checkProtocolVersion()) { return false; }
59
60 yCInfo(MAP2D_NWC_YARP) << "Opening of NWC successful";
61 return true;
62}
63
65{
66 std::lock_guard <std::mutex> lg(m_mutex);
67 return m_map_RPC.store_map_RPC(map);
68}
69
71{
72 std::lock_guard <std::mutex> lg(m_mutex);
73 auto ret = m_map_RPC.get_map_RPC(map_name);
74 if (!ret.retval)
75 {
76 yCError(MAP2D_NWC_YARP, "Unable to get_map");
77 return ret.retval;
78 }
79 map = ret.themap;
80 return ret.retval;
81}
82
84{
85 std::lock_guard <std::mutex> lg(m_mutex);
87}
88
89ReturnValue Map2D_nwc_yarp::get_map_names(std::vector<std::string>& map_names)
90{
91 std::lock_guard <std::mutex> lg(m_mutex);
93 if (!ret.retval)
94 {
95 yCError(MAP2D_NWC_YARP, "Unable to get_map_names");
96 return ret.retval;
97 }
98 map_names = ret.map_names;
99 return ret.retval;
100}
101
103{
104 std::lock_guard <std::mutex> lg(m_mutex);
105 return m_map_RPC.remove_map_RPC(map_name);
106}
107
109{
110 std::lock_guard <std::mutex> lg(m_mutex);
111 return m_map_RPC.store_location_RPC(location_name,loc);
112}
113
115{
116 std::lock_guard <std::mutex> lg(m_mutex);
117 return m_map_RPC.store_area_RPC(area_name, area);
118}
119
121{
122 std::lock_guard <std::mutex> lg(m_mutex);
123 return m_map_RPC.store_path_RPC(path_name, path);
124}
125
126ReturnValue Map2D_nwc_yarp::getLocationsList(std::vector<std::string>& locations)
127{
128 std::lock_guard <std::mutex> lg(m_mutex);
130 if (!ret.retval)
131 {
132 yCError(MAP2D_NWC_YARP, "Unable to getLocationsList");
133 return ret.retval;
134 }
135 locations = ret.locations;
136 return ret.retval;
137}
138
139ReturnValue Map2D_nwc_yarp::getAreasList(std::vector<std::string>& areas)
140{
141 std::lock_guard <std::mutex> lg(m_mutex);
143 if (!ret.retval)
144 {
145 yCError(MAP2D_NWC_YARP, "Unable to getAreasList");
146 return ret.retval;
147 }
148 areas = ret.areas;
149 return ret.retval;
150}
151
152ReturnValue Map2D_nwc_yarp::getPathsList(std::vector<std::string>& paths)
153{
154 std::lock_guard <std::mutex> lg(m_mutex);
156 if (!ret.retval)
157 {
158 yCError(MAP2D_NWC_YARP, "Unable to getPathsList");
159 return ret.retval;
160 }
161 paths = ret.paths;
162 return ret.retval;
163}
164
165ReturnValue Map2D_nwc_yarp::getAllLocations(std::vector<yarp::dev::Nav2D::Map2DLocation>& locations)
166{
167 std::lock_guard <std::mutex> lg(m_mutex);
169 if (!ret.retval)
170 {
171 yCError(MAP2D_NWC_YARP, "Unable to getAllLocations");
172 return ret.retval;
173 }
174 locations = ret.locations;
175 return ret.retval;
176}
177
178ReturnValue Map2D_nwc_yarp::getAllAreas(std::vector<yarp::dev::Nav2D::Map2DArea>& areas)
179{
180 std::lock_guard <std::mutex> lg(m_mutex);
182 if (!ret.retval)
183 {
184 yCError(MAP2D_NWC_YARP, "Unable to getAllAreas");
185 return ret.retval;
186 }
187 areas = ret.areas;
188 return ret.retval;
189}
190
191ReturnValue Map2D_nwc_yarp::getAllPaths(std::vector<yarp::dev::Nav2D::Map2DPath>& paths)
192{
193 std::lock_guard <std::mutex> lg(m_mutex);
195 if (!ret.retval)
196 {
197 yCError(MAP2D_NWC_YARP, "Unable to getAllPaths");
198 return ret.retval;
199 }
200 paths = ret.paths;
201 return ret.retval;
202}
203
205{
206 std::lock_guard <std::mutex> lg(m_mutex);
207 auto ret = m_map_RPC.get_location_RPC(location_name);
208 if (!ret.retval)
209 {
210 yCError(MAP2D_NWC_YARP, "Unable to getLocation");
211 return ret.retval;
212 }
213 loc = ret.loc;
214 return ret.retval;
215}
216
217ReturnValue Map2D_nwc_yarp::getArea(std::string area_name, Map2DArea& area)
218{
219 std::lock_guard <std::mutex> lg(m_mutex);
220 auto ret = m_map_RPC.get_area_RPC(area_name);
221 if (!ret.retval)
222 {
223 yCError(MAP2D_NWC_YARP, "Unable to getArea");
224 return ret.retval;
225 }
226 area = ret.area;
227 return ret.retval;
228}
229
230ReturnValue Map2D_nwc_yarp::getPath(std::string path_name, Map2DPath& path)
231{
232 std::lock_guard <std::mutex> lg(m_mutex);
233 auto ret = m_map_RPC.get_path_RPC(path_name);
234 if (!ret.retval)
235 {
236 yCError(MAP2D_NWC_YARP, "Unable to getPath");
237 return ret.retval;
238 }
239 path = ret.path;
240 return ret.retval;
241}
242
244{
245 std::lock_guard <std::mutex> lg(m_mutex);
246 return m_map_RPC.delete_location_RPC(location_name);
247}
248
249ReturnValue Map2D_nwc_yarp::renameLocation(std::string original_name, std::string new_name)
250{
251 std::lock_guard <std::mutex> lg(m_mutex);
252 return m_map_RPC.rename_location_RPC(original_name,new_name);
253}
254
255ReturnValue Map2D_nwc_yarp::deleteArea(std::string location_name)
256{
257 std::lock_guard <std::mutex> lg(m_mutex);
258 return m_map_RPC.delete_area_RPC(location_name);
259}
260
262{
263 std::lock_guard <std::mutex> lg(m_mutex);
264 return m_map_RPC.delete_path_RPC(path_name);
265}
266
267ReturnValue Map2D_nwc_yarp::renameArea(std::string original_name, std::string new_name)
268{
269 std::lock_guard <std::mutex> lg(m_mutex);
270 return m_map_RPC.rename_area_RPC(original_name, new_name);
271}
272
273ReturnValue Map2D_nwc_yarp::renamePath(std::string original_name, std::string new_name)
274{
275 std::lock_guard <std::mutex> lg(m_mutex);
276 return m_map_RPC.rename_path_RPC(original_name, new_name);
277}
278
280{
281 std::lock_guard <std::mutex> lg(m_mutex);
283}
284
286{
287 std::lock_guard <std::mutex> lg(m_mutex);
289}
290
296
298{
299 std::lock_guard <std::mutex> lg(m_mutex);
301}
302
304{
305 std::lock_guard <std::mutex> lg(m_mutex);
307}
308
310{
311 return true;
312}
313
319
325
331
337
338ReturnValue Map2D_nwc_yarp::saveMapToDisk(std::string map_name, std::string file_name)
339{
340 std::lock_guard <std::mutex> lg(m_mutex);
341 return m_map_RPC.save_map_to_disk_RPC(map_name,file_name);
342}
343
345{
346 std::lock_guard <std::mutex> lg(m_mutex);
347 return m_map_RPC.load_map_from_disk_RPC(file_name);
348}
349
351{
352 std::lock_guard <std::mutex> lg(m_mutex);
354}
bool ret
virtual return_get_map_names get_map_names_RPC()
virtual yarp::dev::ReturnValue save_map_to_disk_RPC(const std::string &map_name, const std::string &file_name)
virtual yarp::dev::ReturnValue save_maps_collection_RPC(const std::string &maps_collection_file)
virtual yarp::dev::ReturnValue remove_map_RPC(const std::string &map_name)
virtual yarp::dev::ReturnValue clear_all_areas_RPC()
virtual yarp::dev::ReturnValue enable_maps_compression_RPC(const bool enable_compression)
virtual yarp::dev::ReturnValue store_area_RPC(const std::string &area_name, const yarp::dev::Nav2D::Map2DArea &area)
virtual yarp::dev::ReturnValue rename_path_RPC(const std::string &original_name, const std::string &new_name)
virtual yarp::dev::ReturnValue delete_path_RPC(const std::string &path_name)
virtual return_get_all_areas get_all_areas_RPC()
virtual yarp::dev::ReturnValue store_map_RPC(const yarp::dev::Nav2D::MapGrid2D &themap)
virtual yarp::dev::ReturnValue rename_location_RPC(const std::string &original_name, const std::string &new_name)
virtual return_get_location get_location_RPC(const std::string &location_name)
virtual return_get_areas_list get_areas_list_RPC()
virtual yarp::dev::ReturnValue load_map_from_disk_RPC(const std::string &file_name)
virtual bool checkProtocolVersion()
virtual return_get_path get_path_RPC(const std::string &path_name)
virtual yarp::dev::ReturnValue store_path_RPC(const std::string &path_name, const yarp::dev::Nav2D::Map2DPath &path)
virtual yarp::dev::ReturnValue clear_all_locations_RPC()
virtual yarp::dev::ReturnValue rename_area_RPC(const std::string &original_name, const std::string &new_name)
virtual yarp::dev::ReturnValue clear_all_maps_RPC()
virtual yarp::dev::ReturnValue delete_location_RPC(const std::string &location_name)
virtual yarp::dev::ReturnValue load_locations_and_extras_RPC(const std::string &locations_collection_file)
virtual yarp::dev::ReturnValue load_maps_collection_RPC(const std::string &maps_collection_file)
virtual yarp::dev::ReturnValue delete_area_RPC(const std::string &area_name)
virtual yarp::dev::ReturnValue store_location_RPC(const std::string &location_name, const yarp::dev::Nav2D::Map2DLocation &loc)
virtual return_get_area get_area_RPC(const std::string &area_name)
virtual return_get_all_paths get_all_paths_RPC()
virtual return_get_map get_map_RPC(const std::string &map_name)
virtual yarp::dev::ReturnValue save_locations_and_extras_RPC(const std::string &locations_collection_file)
virtual yarp::dev::ReturnValue clear_all_maps_temporary_flags_RPC()
virtual return_get_paths_list get_paths_list_RPC()
virtual yarp::dev::ReturnValue clear_all_paths_RPC()
virtual return_get_locations_list get_locations_list_RPC()
virtual return_get_all_locations get_all_locations_RPC()
virtual yarp::dev::ReturnValue clear_map_temporary_flags_RPC(const std::string &map_name)
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
yarp::dev::ReturnValue getPathsList(std::vector< std::string > &paths) override
Get a list of the names of all stored paths.
yarp::dev::ReturnValue clearAllMaps() override
Removes all the registered maps from the server.
yarp::dev::ReturnValue clearAllMapsTemporaryFlags() override
Clear all temporary flags from all stored maps.
yarp::dev::ReturnValue saveMapsCollection(std::string maps_collection_file) override
Save a collection of maps to disk.
yarp::dev::ReturnValue loadMapsCollection(std::string maps_collection_file) override
Load a collection of maps from disk.
yarp::dev::ReturnValue saveLocationsAndExtras(std::string locations_collection_file) override
Save a collection of locations/area/paths etc to disk.
yarp::dev::ReturnValue remove_map(std::string map_name) override
Removes a map from the map server.
yarp::dev::ReturnValue renameLocation(std::string original_name, std::string new_name) override
Searches for a location and renames it.
yarp::dev::ReturnValue deleteLocation(std::string location_name) override
Delete a location.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::os::Port m_rpcPort_to_Map2D_nws
yarp::dev::ReturnValue clearMapTemporaryFlags(std::string map_name) override
Clear all temporary flags from a specific map.
yarp::dev::ReturnValue loadMapFromDisk(std::string file_name) override
Load a map from disk.
yarp::dev::ReturnValue getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation &loc) override
Retrieves a location specified by the user in the world reference frame.
yarp::dev::ReturnValue getAllPaths(std::vector< yarp::dev::Nav2D::Map2DPath > &paths) override
Get a list of all stored paths.
yarp::dev::ReturnValue clearAllPaths() override
Delete all stored paths.
yarp::dev::ReturnValue getAllLocations(std::vector< yarp::dev::Nav2D::Map2DLocation > &locations) override
Get a list of all stored locations.
yarp::dev::ReturnValue clearAllAreas() override
Delete all stored areas.
yarp::dev::ReturnValue storePath(std::string path_name, yarp::dev::Nav2D::Map2DPath path) override
Store a path.
yarp::dev::ReturnValue renameArea(std::string original_name, std::string new_name) override
Searches for an area and renames it.
yarp::dev::ReturnValue saveMapToDisk(std::string map_name, std::string file_name) override
Save a map to disk.
yarp::dev::ReturnValue getAreasList(std::vector< std::string > &locations) override
Get a list of the names of all stored areas.
yarp::dev::ReturnValue get_map(std::string map_name, yarp::dev::Nav2D::MapGrid2D &map) override
Gets a map from the map server.
yarp::dev::ReturnValue loadLocationsAndExtras(std::string locations_collection_file) override
Load a collection of locations/areas/paths etc from disk.
yarp::dev::ReturnValue clearAllLocations() override
Delete all stored locations.
yarp::dev::ReturnValue store_map(const yarp::dev::Nav2D::MapGrid2D &map) override
Stores a map into the map server.
yarp::dev::ReturnValue get_map_names(std::vector< std::string > &map_names) override
Gets a list containing the names of all registered maps.
IMap2DMsgs m_map_RPC
yarp::dev::ReturnValue deletePath(std::string path_name) override
Delete a path.
yarp::dev::ReturnValue getPath(std::string path_name, yarp::dev::Nav2D::Map2DPath &path) override
Retrieves a path.
yarp::dev::ReturnValue getLocationsList(std::vector< std::string > &locations) override
Get a list of the names of all stored locations.
yarp::dev::ReturnValue getAllAreas(std::vector< yarp::dev::Nav2D::Map2DArea > &areas) override
Get a list of all stored areas.
yarp::dev::ReturnValue storeArea(std::string area_name, yarp::dev::Nav2D::Map2DArea area) override
Store an area.
yarp::dev::ReturnValue renamePath(std::string original_name, std::string new_name) override
Searches for a path and renames it.
yarp::dev::ReturnValue getArea(std::string location_name, yarp::dev::Nav2D::Map2DArea &area) override
Retrieves an area.
std::mutex m_mutex
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue storeLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation loc) override
Store a location specified by the user in the world reference frame.
yarp::dev::ReturnValue enableMapsCompression(bool enable) override
Enable/disables maps compression over the network.
yarp::dev::ReturnValue deleteArea(std::string location_name) override
Delete an area.
A mini-server for performing network communication in the background.
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 yCInfo(component,...)
#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.