YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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 auto ret = m_iMap->clearAllMaps();
35 if (!ret)
36 {
37 yCError(MAP2D_RPC, "Unable to clearAllMaps");
38 }
39 return ret;
40}
41
43{
44 std::lock_guard <std::mutex> lg(m_mutex);
45
46 auto ret = m_iMap->store_map(themap);
47 if (!ret)
48 {
49 yCError(MAP2D_RPC, "Unable to store_map");
50 }
51 return ret;
52}
53
54return_get_map IMap2DRPCd::get_map_RPC(const std::string& map_name)
55{
56 std::lock_guard <std::mutex> lg(m_mutex);
57
60 ret.retval = m_iMap->get_map(map_name, map);
61 if (!ret.retval)
62 {
63 yCError(MAP2D_RPC, "Unable to getEstimatedPoses");
64 }
65 else
66 {
67 ret.themap = map;
68 }
69 return ret;
70}
71
73{
74 std::lock_guard <std::mutex> lg(m_mutex);
75
77 std::vector<string> map_names;
78 ret.retval = m_iMap->get_map_names(map_names);
79 if (!ret.retval)
80 {
81 yCError(MAP2D_RPC, "Unable to getEstimatedPoses");
82 }
83 else
84 {
85 ret.map_names = map_names;
86 }
87 return ret;
88}
89
90ReturnValue IMap2DRPCd::remove_map_RPC(const std::string& map_name)
91{
92 std::lock_guard <std::mutex> lg(m_mutex);
93
94 auto ret = m_iMap->remove_map(map_name);
95 if (!ret)
96 {
97 yCError(MAP2D_RPC, "Unable to remove_map");
98 }
99 return ret;
100}
101
103{
104 std::lock_guard <std::mutex> lg(m_mutex);
105
106 auto ret = m_iMap->storeLocation(location_name, loc);
107 if (!ret)
108 {
109 yCError(MAP2D_RPC, "Unable to storeLocation");
110 }
111 return ret;
112}
113
115{
116 std::lock_guard <std::mutex> lg(m_mutex);
117
118 auto ret = m_iMap->storeArea(area_name, area);
119 if (!ret)
120 {
121 yCError(MAP2D_RPC, "Unable to storeArea");
122 }
123 return ret;
124}
125
127{
128 std::lock_guard <std::mutex> lg(m_mutex);
129
130 auto ret = m_iMap->storePath(path_name, path);
131 if (!ret)
132 {
133 yCError(MAP2D_RPC, "Unable to storePath");
134 }
135 return ret;
136}
137
138ReturnValue IMap2DRPCd::rename_location_RPC(const std::string& original_name, const std::string& new_name)
139{
140 std::lock_guard <std::mutex> lg(m_mutex);
141
142 auto ret = m_iMap->renameLocation(original_name, new_name);
143 if (!ret)
144 {
145 yCError(MAP2D_RPC, "Unable to renameLocation");
146 }
147 return ret;
148}
149
150ReturnValue IMap2DRPCd::delete_location_RPC(const std::string& location_name)
151{
152 std::lock_guard <std::mutex> lg(m_mutex);
153
154 auto ret = m_iMap->deleteLocation(location_name);
155 if (!ret)
156 {
157 yCError(MAP2D_RPC, "Unable to deleteLocation");
158 }
159 return ret;
160}
161
162ReturnValue IMap2DRPCd::delete_path_RPC(const std::string& path_name)
163{
164 std::lock_guard <std::mutex> lg(m_mutex);
165
166 auto ret = m_iMap->deletePath(path_name);
167 if (!ret)
168 {
169 yCError(MAP2D_RPC, "Unable to deletePath");
170 }
171 return ret;
172}
173
174ReturnValue IMap2DRPCd::rename_area_RPC(const std::string& original_name, const std::string& new_name)
175{
176 std::lock_guard <std::mutex> lg(m_mutex);
177
178 auto ret = m_iMap->renameArea(original_name, new_name);
179 if (!ret)
180 {
181 yCError(MAP2D_RPC, "Unable to renameArea");
182 }
183 return ret;
184}
185
186ReturnValue IMap2DRPCd::rename_path_RPC(const std::string& original_name, const std::string& new_name)
187{
188 std::lock_guard <std::mutex> lg(m_mutex);
189
190 auto ret = m_iMap->renamePath(original_name, new_name);
191 if (!ret)
192 {
193 yCError(MAP2D_RPC, "Unable to renamePath");
194 }
195 return ret;
196}
197
198ReturnValue IMap2DRPCd::delete_area_RPC(const std::string& area_name)
199{
200 std::lock_guard <std::mutex> lg(m_mutex);
201
202 auto ret = m_iMap->deleteArea(area_name);
203 if (!ret)
204 {
205 yCError(MAP2D_RPC, "Unable to deleteArea");
206 }
207 return ret;
208}
209
211{
212 std::lock_guard <std::mutex> lg(m_mutex);
213
214 auto ret = m_iMap->clearAllLocations();
215 if (!ret)
216 {
217 yCError(MAP2D_RPC, "Unable to clearAllLocations");
218 }
219 return ret;
220}
221
223{
224 std::lock_guard <std::mutex> lg(m_mutex);
225
226 auto ret = m_iMap->clearAllAreas();
227 if (!ret)
228 {
229 yCError(MAP2D_RPC, "Unable to storePath");
230 }
231 return ret;
232}
233
235{
236 std::lock_guard <std::mutex> lg(m_mutex);
237
238 auto ret = m_iMap->clearAllPaths();
239 if (!ret)
240 {
241 yCError(MAP2D_RPC, "Unable to clearAllPaths");
242 }
243 return ret;
244}
245
247{
248 std::lock_guard <std::mutex> lg(m_mutex);
249
250 auto ret = m_iMap->clearAllMapsTemporaryFlags();
251 if (!ret)
252 {
253 yCError(MAP2D_RPC, "Unable to clearAllMapsTemporaryFlags");
254 }
255 return ret;
256}
257
259{
260 std::lock_guard <std::mutex> lg(m_mutex);
261
262 auto ret = m_iMap->clearMapTemporaryFlags(map_name);
263 if (!ret)
264 {
265 yCError(MAP2D_RPC, "Unable to clearMapTemporaryFlags");
266 }
267 return ret;
268}
269
270ReturnValue IMap2DRPCd::save_maps_collection_RPC(const std::string& maps_collection_file)
271{
272 std::lock_guard <std::mutex> lg(m_mutex);
273
274 auto ret = m_iMap->saveMapsCollection(maps_collection_file);
275 if (!ret)
276 {
277 yCError(MAP2D_RPC, "Unable to saveMapsCollection");
278 }
279 return ret;
280}
281
282ReturnValue IMap2DRPCd::load_maps_collection_RPC(const std::string& maps_collection_file)
283{
284 std::lock_guard <std::mutex> lg(m_mutex);
285
286 auto ret = m_iMap->loadMapsCollection(maps_collection_file);
287 if (!ret)
288 {
289 yCError(MAP2D_RPC, "Unable to loadMapsCollection");
290 }
291 return ret;
292}
293
294ReturnValue IMap2DRPCd::save_locations_and_extras_RPC(const std::string& locations_collection_file)
295{
296 std::lock_guard <std::mutex> lg(m_mutex);
297
298 auto ret = m_iMap->saveLocationsAndExtras(locations_collection_file);
299 if (!ret)
300 {
301 yCError(MAP2D_RPC, "Unable to saveLocationsAndExtras");
302 }
303 return ret;
304}
305
306ReturnValue IMap2DRPCd::load_locations_and_extras_RPC(const std::string& locations_collection_file)
307{
308 std::lock_guard <std::mutex> lg(m_mutex);
309
310 auto ret = m_iMap->loadLocationsAndExtras(locations_collection_file);
311 if (!ret)
312 {
313 yCError(MAP2D_RPC, "Unable to loadLocationsAndExtras");
314 }
315 return ret;
316}
317
318return_get_location IMap2DRPCd::get_location_RPC(const std::string& location_name)
319{
320 std::lock_guard <std::mutex> lg(m_mutex);
321
323 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return ret; }}
325 ret.retval = m_iMap->getLocation(location_name, loc);
326 if (!ret.retval)
327 {
328 yCError(MAP2D_RPC, "Unable to getLocation");
329 }
330 else
331 {
332 ret.loc = loc;
333 }
334 return ret;
335}
336
337return_get_area IMap2DRPCd::get_area_RPC(const std::string& area_name)
338{
339 std::lock_guard <std::mutex> lg(m_mutex);
340
342 {if (m_iMap == nullptr) { yCError(MAP2D_RPC, "Invalid interface"); return ret; }}
344 ret.retval = m_iMap->getArea(area_name, area);
345 if (!ret.retval)
346 {
347 yCError(MAP2D_RPC, "Unable to getArea");
348 }
349 else
350 {
351 ret.area = area;
352 }
353 return ret;
354}
355
356return_get_path IMap2DRPCd::get_path_RPC(const std::string& path_name)
357{
358 std::lock_guard <std::mutex> lg(m_mutex);
359
362 ret.retval = m_iMap->getPath(path_name, path);
363 if (!ret.retval)
364 {
365 yCError(MAP2D_RPC, "Unable to getPath");
366 }
367 else
368 {
369 ret.path = path;
370 }
371 return ret;
372}
373
375{
376 std::lock_guard <std::mutex> lg(m_mutex);
377
379 std::vector<string> loc_names;
380 ret.retval = m_iMap->getLocationsList(loc_names);
381 if (!ret.retval)
382 {
383 yCError(MAP2D_RPC, "Unable to getLocationsList");
384 }
385 else
386 {
387 ret.locations = loc_names;
388 }
389 return ret;
390}
391
393{
394 std::lock_guard <std::mutex> lg(m_mutex);
395
397 std::vector<string> area_names;
398 ret.retval = m_iMap->getAreasList(area_names);
399 if (!ret.retval)
400 {
401 yCError(MAP2D_RPC, "Unable to getAreasList");
402 }
403 else
404 {
405 ret.areas = area_names;
406 }
407 return ret;
408}
409
411{
412 std::lock_guard <std::mutex> lg(m_mutex);
413
415 std::vector<string> path_names;
416 ret.retval = m_iMap->getPathsList(path_names);
417 if (!ret.retval)
418 {
419 yCError(MAP2D_RPC, "Unable to getPathsList");
420 }
421 else
422 {
423 ret.paths = path_names;
424 }
425 return ret;
426}
bool ret
return_get_map_names get_map_names_RPC() override
yarp::dev::ReturnValue clear_all_areas_RPC() override
yarp::dev::ReturnValue rename_path_RPC(const std::string &original_name, const std::string &new_name) override
return_get_path get_path_RPC(const std::string &path_name) override
yarp::dev::ReturnValue store_area_RPC(const std::string &area_name, const yarp::dev::Nav2D::Map2DArea &area) override
yarp::dev::ReturnValue load_locations_and_extras_RPC(const std::string &locations_collection_file) override
yarp::dev::ReturnValue store_map_RPC(const yarp::dev::Nav2D::MapGrid2D &themap) override
yarp::dev::ReturnValue save_locations_and_extras_RPC(const std::string &locations_collection_file) override
yarp::dev::ReturnValue rename_area_RPC(const std::string &original_name, const std::string &new_name) override
yarp::dev::ReturnValue rename_location_RPC(const std::string &original_name, const std::string &new_name) override
yarp::dev::ReturnValue save_maps_collection_RPC(const std::string &maps_collection_file) override
yarp::dev::ReturnValue delete_area_RPC(const std::string &area_name) override
return_get_location get_location_RPC(const std::string &location_name) override
yarp::dev::ReturnValue delete_path_RPC(const std::string &path_name) override
return_get_areas_list get_areas_list_RPC() override
yarp::dev::ReturnValue clear_map_temporary_flags_RPC(const std::string &map_name) override
yarp::dev::ReturnValue store_path_RPC(const std::string &path_name, const yarp::dev::Nav2D::Map2DPath &path) override
yarp::dev::ReturnValue clear_all_maps_temporary_flags_RPC() 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
yarp::dev::ReturnValue clear_all_locations_RPC() override
yarp::dev::ReturnValue clear_all_paths_RPC() override
yarp::dev::ReturnValue clear_all_maps_RPC() override
return_get_map get_map_RPC(const std::string &map_name) override
yarp::dev::ReturnValue store_location_RPC(const std::string &location_name, const yarp::dev::Nav2D::Map2DLocation &loc) override
yarp::dev::ReturnValue remove_map_RPC(const std::string &map_name) override
yarp::dev::ReturnValue load_maps_collection_RPC(const std::string &maps_collection_file) override
yarp::dev::ReturnValue delete_location_RPC(const std::string &location_name) override
virtual yarp::dev::ReturnValue storeLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation loc)=0
Store a location specified by the user in the world reference frame.
virtual yarp::dev::ReturnValue storePath(std::string path_name, yarp::dev::Nav2D::Map2DPath path)=0
Store a path.
virtual yarp::dev::ReturnValue deleteLocation(std::string location_name)=0
Delete a location.
virtual yarp::dev::ReturnValue get_map_names(std::vector< std::string > &map_names)=0
Gets a list containing the names of all registered maps.
virtual yarp::dev::ReturnValue loadMapsCollection(std::string file_name)=0
Load a collection of maps from disk.
virtual yarp::dev::ReturnValue saveMapsCollection(std::string file_name)=0
Save a collection of maps to disk.
virtual yarp::dev::ReturnValue getPath(std::string path_name, yarp::dev::Nav2D::Map2DPath &path)=0
Retrieves a path.
virtual yarp::dev::ReturnValue renamePath(std::string original_name, std::string new_name)=0
Searches for a path and renames it.
virtual yarp::dev::ReturnValue saveLocationsAndExtras(std::string file_name)=0
Save a collection of locations/area/paths etc to disk.
virtual yarp::dev::ReturnValue deleteArea(std::string area_name)=0
Delete an area.
virtual yarp::dev::ReturnValue getLocationsList(std::vector< std::string > &locations)=0
Get a list of the names of all stored locations.
virtual yarp::dev::ReturnValue loadLocationsAndExtras(std::string file_name)=0
Load a collection of locations/areas/paths etc from disk.
virtual yarp::dev::ReturnValue store_map(const yarp::dev::Nav2D::MapGrid2D &map)=0
Stores a map into the map server.
virtual yarp::dev::ReturnValue clearAllMaps()=0
Removes all the registered maps from the server.
virtual yarp::dev::ReturnValue clearAllMapsTemporaryFlags()=0
Clear all temporary flags from all stored maps.
virtual yarp::dev::ReturnValue clearMapTemporaryFlags(std::string map_name)=0
Clear all temporary flags from a specific map.
virtual yarp::dev::ReturnValue clearAllAreas()=0
Delete all stored areas.
virtual yarp::dev::ReturnValue renameLocation(std::string original_name, std::string new_name)=0
Searches for a location and renames it.
virtual yarp::dev::ReturnValue get_map(std::string map_name, yarp::dev::Nav2D::MapGrid2D &map)=0
Gets a map from the map server.
virtual yarp::dev::ReturnValue getAreasList(std::vector< std::string > &areas)=0
Get a list of the names of all stored areas.
virtual yarp::dev::ReturnValue storeArea(std::string area_name, yarp::dev::Nav2D::Map2DArea area)=0
Store an area.
virtual yarp::dev::ReturnValue clearAllLocations()=0
Delete all stored locations.
virtual yarp::dev::ReturnValue getPathsList(std::vector< std::string > &paths)=0
Get a list of the names of all stored paths.
virtual yarp::dev::ReturnValue getArea(std::string area_name, yarp::dev::Nav2D::Map2DArea &area)=0
Retrieves an area.
virtual yarp::dev::ReturnValue deletePath(std::string path_name)=0
Delete a path.
virtual yarp::dev::ReturnValue remove_map(std::string map_name)=0
Removes a map from the map server.
virtual yarp::dev::ReturnValue renameArea(std::string original_name, std::string new_name)=0
Searches for an area and renames it.
virtual yarp::dev::ReturnValue getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation &loc)=0
Retrieves a location specified by the user in the world reference frame.
virtual yarp::dev::ReturnValue clearAllPaths()=0
Delete all stored paths.
A mini-server for performing network communication in the background.
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
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.