YARP
Yet Another Robot Platform
Map2DServerImpl.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
7#include <yarp/os/LogStream.h>
9#include "Map2DServerImpl.h"
10
13using namespace yarp::os;
14using namespace yarp::dev;
15using namespace yarp::dev::Nav2D;
16using namespace std;
17
18#define DEFAULT_THREAD_PERIOD 0.01
19
20#ifndef M_PI
21#define M_PI 3.14159265358979323846
22#endif
23
24namespace {
25YARP_LOG_COMPONENT(MAP2D_RPC, "yarp.device.map2D_nws_yarp.IMap2DRPCd")
26}
27
28#define CHECK_POINTER(xxx) {if (xxx==nullptr) {yCError(MAP2D_RPC, "Invalid interface"); return false;}}
29
31{
32 std::lock_guard <std::mutex> lg(m_mutex);
33
34 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
35
36 if (!m_iMap->clearAllMaps())
37 {
38 yCError(MAP2D_RPC, "Unable to clearAllMaps");
39 return false;
40 }
41 return true;
42}
43
45{
46 std::lock_guard <std::mutex> lg(m_mutex);
47
48 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
49
50 if (!m_iMap->store_map(themap))
51 {
52 yCError(MAP2D_RPC, "Unable to store_map");
53 return false;
54 }
55 return true;
56}
57
58return_get_map IMap2DRPCd::get_map_RPC(const std::string& map_name)
59{
60 std::lock_guard <std::mutex> lg(m_mutex);
61
63 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return ret; }}
65 if (!m_iMap->get_map(map_name,map))
66 {
67 yCError(MAP2D_RPC, "Unable to getEstimatedPoses");
68 ret.retval = false;
69 }
70 else
71 {
72 ret.retval = true;
73 ret.themap = map;
74 }
75 return ret;
76}
77
79{
80 std::lock_guard <std::mutex> lg(m_mutex);
81
83 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return ret; }}
84 std::vector<string> map_names;
85 if (!m_iMap->get_map_names(map_names))
86 {
87 yCError(MAP2D_RPC, "Unable to getEstimatedPoses");
88 ret.retval = false;
89 }
90 else
91 {
92 ret.retval = true;
93 ret.map_names = map_names;
94 }
95 return ret;
96}
97
98bool IMap2DRPCd::remove_map_RPC(const std::string& map_name)
99{
100 std::lock_guard <std::mutex> lg(m_mutex);
101
102 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
103
104 if (!m_iMap->remove_map(map_name))
105 {
106 yCError(MAP2D_RPC, "Unable to remove_map");
107 return false;
108 }
109 return true;
110}
111
112bool IMap2DRPCd::store_location_RPC(const std::string& location_name, const yarp::dev::Nav2D::Map2DLocation& loc)
113{
114 std::lock_guard <std::mutex> lg(m_mutex);
115
116 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
117
118 if (!m_iMap->storeLocation(location_name,loc))
119 {
120 yCError(MAP2D_RPC, "Unable to storeLocation");
121 return false;
122 }
123 return true;
124}
125
126bool IMap2DRPCd::store_area_RPC(const std::string& area_name, const yarp::dev::Nav2D::Map2DArea& area)
127{
128 std::lock_guard <std::mutex> lg(m_mutex);
129
130 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
131
132 if (!m_iMap->storeArea(area_name,area))
133 {
134 yCError(MAP2D_RPC, "Unable to storeArea");
135 return false;
136 }
137 return true;
138}
139
140bool IMap2DRPCd::store_path_RPC(const std::string& path_name, const yarp::dev::Nav2D::Map2DPath& path)
141{
142 std::lock_guard <std::mutex> lg(m_mutex);
143
144 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
145
146 if (!m_iMap->storePath(path_name,path))
147 {
148 yCError(MAP2D_RPC, "Unable to storePath");
149 return false;
150 }
151 return true;
152}
153
154bool IMap2DRPCd::rename_location_RPC(const std::string& original_name, const std::string& new_name)
155{
156 std::lock_guard <std::mutex> lg(m_mutex);
157
158 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
159
160 if (!m_iMap->renameLocation(original_name, new_name))
161 {
162 yCError(MAP2D_RPC, "Unable to renameLocation");
163 return false;
164 }
165 return true;
166}
167
168bool IMap2DRPCd::delete_location_RPC(const std::string& location_name)
169{
170 std::lock_guard <std::mutex> lg(m_mutex);
171
172 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
173
174 if (!m_iMap->deleteLocation(location_name))
175 {
176 yCError(MAP2D_RPC, "Unable to deleteLocation");
177 return false;
178 }
179 return true;
180}
181
182bool IMap2DRPCd::delete_path_RPC(const std::string& path_name)
183{
184 std::lock_guard <std::mutex> lg(m_mutex);
185
186 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
187
188 if (!m_iMap->deletePath(path_name))
189 {
190 yCError(MAP2D_RPC, "Unable to deletePath");
191 return false;
192 }
193 return true;
194}
195
196bool IMap2DRPCd::rename_area_RPC(const std::string& original_name, const std::string& new_name)
197{
198 std::lock_guard <std::mutex> lg(m_mutex);
199
200 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
201
202 if (!m_iMap->renameArea(original_name, new_name))
203 {
204 yCError(MAP2D_RPC, "Unable to renameArea");
205 return false;
206 }
207 return true;
208}
209
210bool IMap2DRPCd::rename_path_RPC(const std::string& original_name, const std::string& new_name)
211{
212 std::lock_guard <std::mutex> lg(m_mutex);
213
214 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
215
216 if (!m_iMap->renamePath(original_name, new_name))
217 {
218 yCError(MAP2D_RPC, "Unable to renamePath");
219 return false;
220 }
221 return true;
222}
223
224bool IMap2DRPCd::delete_area_RPC(const std::string& area_name)
225{
226 std::lock_guard <std::mutex> lg(m_mutex);
227
228 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
229
230 if (!m_iMap->deleteArea(area_name))
231 {
232 yCError(MAP2D_RPC, "Unable to deleteArea");
233 return false;
234 }
235 return true;
236}
237
239{
240 std::lock_guard <std::mutex> lg(m_mutex);
241
242 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
243
244 if (!m_iMap->clearAllLocations())
245 {
246 yCError(MAP2D_RPC, "Unable to clearAllLocations");
247 return false;
248 }
249 return true;
250}
251
253{
254 std::lock_guard <std::mutex> lg(m_mutex);
255
256 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
257
258 if (!m_iMap->clearAllAreas())
259 {
260 yCError(MAP2D_RPC, "Unable to storePath");
261 return false;
262 }
263 return true;
264}
265
267{
268 std::lock_guard <std::mutex> lg(m_mutex);
269
270 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
271
272 if (!m_iMap->clearAllPaths())
273 {
274 yCError(MAP2D_RPC, "Unable to clearAllPaths");
275 return false;
276 }
277 return true;
278}
279
281{
282 std::lock_guard <std::mutex> lg(m_mutex);
283
284 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
285
286 if (!m_iMap->clearAllMapsTemporaryFlags())
287 {
288 yCError(MAP2D_RPC, "Unable to clearAllMapsTemporaryFlags");
289 return false;
290 }
291 return true;
292}
293
294bool IMap2DRPCd::clear_map_temporary_flags_RPC(const std::string& map_name)
295{
296 std::lock_guard <std::mutex> lg(m_mutex);
297
298 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
299
300 if (!m_iMap->clearMapTemporaryFlags(map_name))
301 {
302 yCError(MAP2D_RPC, "Unable to clearMapTemporaryFlags");
303 return false;
304 }
305 return true;
306}
307
308bool IMap2DRPCd::save_maps_collection_RPC(const std::string& maps_collection_file)
309{
310 std::lock_guard <std::mutex> lg(m_mutex);
311
312 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
313
314 if (!m_iMap->saveMapsCollection(maps_collection_file))
315 {
316 yCError(MAP2D_RPC, "Unable to saveMapsCollection");
317 return false;
318 }
319 return true;
320}
321
322bool IMap2DRPCd::load_maps_collection_RPC(const std::string& maps_collection_file)
323{
324 std::lock_guard <std::mutex> lg(m_mutex);
325
326 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
327
328 if (!m_iMap->loadMapsCollection(maps_collection_file))
329 {
330 yCError(MAP2D_RPC, "Unable to loadMapsCollection");
331 return false;
332 }
333 return true;
334}
335
336bool IMap2DRPCd::save_locations_and_extras_RPC(const std::string& locations_collection_file)
337{
338 std::lock_guard <std::mutex> lg(m_mutex);
339
340 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
341
342 if (!m_iMap->saveLocationsAndExtras(locations_collection_file))
343 {
344 yCError(MAP2D_RPC, "Unable to saveLocationsAndExtras");
345 return false;
346 }
347 return true;
348}
349
350bool IMap2DRPCd::load_locations_and_extras_RPC(const std::string& locations_collection_file)
351{
352 std::lock_guard <std::mutex> lg(m_mutex);
353
354 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return false; }}
355
356 if (!m_iMap->loadLocationsAndExtras(locations_collection_file))
357 {
358 yCError(MAP2D_RPC, "Unable to loadLocationsAndExtras");
359 return false;
360 }
361 return true;
362}
363
364return_get_location IMap2DRPCd::get_location_RPC(const std::string& location_name)
365{
366 std::lock_guard <std::mutex> lg(m_mutex);
367
369 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return ret; }}
371 if (!m_iMap->getLocation(location_name, loc))
372 {
373 yCError(MAP2D_RPC, "Unable to getLocation");
374 ret.retval = false;
375 }
376 else
377 {
378 ret.retval = true;
379 ret.loc = loc;
380 }
381 return ret;
382}
383
384return_get_area IMap2DRPCd::get_area_RPC(const std::string& area_name)
385{
386 std::lock_guard <std::mutex> lg(m_mutex);
387
389 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return ret; }}
391 if (!m_iMap->getArea(area_name,area))
392 {
393 yCError(MAP2D_RPC, "Unable to getArea");
394 ret.retval = false;
395 }
396 else
397 {
398 ret.retval = true;
399 ret.area = area;
400 }
401 return ret;
402}
403
404return_get_path IMap2DRPCd::get_path_RPC(const std::string& path_name)
405{
406 std::lock_guard <std::mutex> lg(m_mutex);
407
409 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return ret; }}
411 if (!m_iMap->getPath(path_name, path))
412 {
413 yCError(MAP2D_RPC, "Unable to getPath");
414 ret.retval = false;
415 }
416 else
417 {
418 ret.retval = true;
419 ret.path = path;
420 }
421 return ret;
422}
423
425{
426 std::lock_guard <std::mutex> lg(m_mutex);
427
429 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return ret; }}
430 std::vector<string> loc_names;
431 if (!m_iMap->getLocationsList(loc_names))
432 {
433 yCError(MAP2D_RPC, "Unable to getLocationsList");
434 ret.retval = false;
435 }
436 else
437 {
438 ret.retval = true;
439 ret.locations = loc_names;
440 }
441 return ret;
442}
443
445{
446 std::lock_guard <std::mutex> lg(m_mutex);
447
449 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return ret; }}
450 std::vector<string> area_names;
451 if (!m_iMap->getAreasList(area_names))
452 {
453 yCError(MAP2D_RPC, "Unable to getAreasList");
454 ret.retval = false;
455 }
456 else
457 {
458 ret.retval = true;
459 ret.areas = area_names;
460 }
461 return ret;
462}
463
465{
466 std::lock_guard <std::mutex> lg(m_mutex);
467
469 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return ret; }}
470 std::vector<string> path_names;
471 if (!m_iMap->getPathsList(path_names))
472 {
473 yCError(MAP2D_RPC, "Unable to getPathsList");
474 ret.retval = false;
475 }
476 else
477 {
478 ret.retval = true;
479 ret.paths = path_names;
480 }
481 return ret;
482}
bool ret
return_get_map_names get_map_names_RPC() override
bool remove_map_RPC(const std::string &map_name) override
return_get_path get_path_RPC(const std::string &path_name) override
bool delete_area_RPC(const std::string &area_name) override
bool save_locations_and_extras_RPC(const std::string &locations_collection_file) override
bool clear_all_locations_RPC() override
bool clear_all_areas_RPC() override
bool store_area_RPC(const std::string &area_name, const yarp::dev::Nav2D::Map2DArea &area) override
bool clear_all_maps_RPC() override
bool rename_location_RPC(const std::string &original_name, const std::string &new_name) override
bool clear_all_maps_temporary_flags_RPC() override
bool clear_all_paths_RPC() override
bool load_locations_and_extras_RPC(const std::string &locations_collection_file) override
return_get_location get_location_RPC(const std::string &location_name) override
bool rename_path_RPC(const std::string &original_name, const std::string &new_name) override
return_get_areas_list get_areas_list_RPC() override
bool save_maps_collection_RPC(const std::string &maps_collection_file) override
bool rename_area_RPC(const std::string &original_name, const std::string &new_name) override
bool store_map_RPC(const yarp::dev::Nav2D::MapGrid2D &themap) override
bool clear_map_temporary_flags_RPC(const std::string &map_name) override
bool store_path_RPC(const std::string &path_name, const yarp::dev::Nav2D::Map2DPath &path) override
return_get_paths_list get_paths_list_RPC() override
return_get_locations_list get_locations_list_RPC() override
return_get_area get_area_RPC(const std::string &area_name) override
bool delete_path_RPC(const std::string &path_name) override
return_get_map get_map_RPC(const std::string &map_name) override
bool store_location_RPC(const std::string &location_name, const yarp::dev::Nav2D::Map2DLocation &loc) override
bool delete_location_RPC(const std::string &location_name) override
bool load_maps_collection_RPC(const std::string &maps_collection_file) override
virtual bool deleteLocation(std::string location_name)=0
Delete a location.
virtual bool deletePath(std::string path_name)=0
Delete a path.
virtual bool get_map(std::string map_name, yarp::dev::Nav2D::MapGrid2D &map)=0
Gets a map from the map server.
virtual bool deleteArea(std::string area_name)=0
Delete an area.
virtual bool storeArea(std::string area_name, yarp::dev::Nav2D::Map2DArea area)=0
Store an area.
virtual bool remove_map(std::string map_name)=0
Removes a map from the map server.
virtual bool storePath(std::string path_name, yarp::dev::Nav2D::Map2DPath path)=0
Store a path.
virtual bool clearAllPaths()=0
Delete all stored paths.
virtual bool clearAllAreas()=0
Delete all stored areas.
virtual bool storeLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation loc)=0
Store a location specified by the user in the world reference frame.
virtual bool getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation &loc)=0
Retrieves a location specified by the user in the world reference frame.
virtual bool store_map(const yarp::dev::Nav2D::MapGrid2D &map)=0
Stores a map into the map server.
virtual bool clearAllLocations()=0
Delete all stored locations.
virtual bool clearAllMapsTemporaryFlags()=0
Clear all temporary flags from all stored maps.
virtual bool get_map_names(std::vector< std::string > &map_names)=0
Gets a list containing the names of all registered maps.
virtual bool renameArea(std::string original_name, std::string new_name)=0
Searches for an area and renames it.
virtual bool getPathsList(std::vector< std::string > &paths)=0
Get a list of the names of all stored paths.
virtual bool clearAllMaps()=0
Removes all the registered maps from the server.
virtual bool clearMapTemporaryFlags(std::string map_name)=0
Clear all temporary flags from a specific map.
virtual bool renamePath(std::string original_name, std::string new_name)=0
Searches for a path and renames it.
virtual bool saveMapsCollection(std::string file_name)=0
Save a collection of maps to disk.
virtual bool loadLocationsAndExtras(std::string file_name)=0
Load a collection of locations/areas/paths etc from disk.
virtual bool getArea(std::string area_name, yarp::dev::Nav2D::Map2DArea &area)=0
Retrieves an area.
virtual bool loadMapsCollection(std::string file_name)=0
Load a collection of maps from disk.
virtual bool getPath(std::string path_name, yarp::dev::Nav2D::Map2DPath &path)=0
Retrieves a path.
virtual bool renameLocation(std::string original_name, std::string new_name)=0
Searches for a location and renames it.
virtual bool getLocationsList(std::vector< std::string > &locations)=0
Get a list of the names of all stored locations.
virtual bool getAreasList(std::vector< std::string > &areas)=0
Get a list of the names of all stored areas.
virtual bool saveLocationsAndExtras(std::string file_name)=0
Save a collection of locations/area/paths etc to disk.
#define yCError(component,...)
Definition: LogComponent.h:213
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:76
STL namespace.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.