YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Map2DStorage.h
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
6#ifndef YARP_DEV_MAP2DSERVER_H
7#define YARP_DEV_MAP2DSERVER_H
8
9#include <vector>
10#include <iostream>
11#include <string>
12#include <sstream>
13#include <mutex>
14
15#include <yarp/os/Network.h>
16#include <yarp/os/Port.h>
17#include <yarp/os/Bottle.h>
18#include <yarp/os/Time.h>
19#include <yarp/os/Property.h>
20
23#include <yarp/os/RpcServer.h>
24#include <yarp/sig/Vector.h>
25#include <yarp/dev/IMap2D.h>
26#include <yarp/dev/MapGrid2D.h>
28#include <yarp/dev/Map2DArea.h>
29#include <yarp/dev/Map2DPath.h>
31
32#include <yarp/dev/PolyDriver.h>
34#include <yarp/dev/api.h>
35
37
38#define DEFAULT_THREAD_PERIOD 20 //ms
39
55{
56private:
57 std::map<std::string, yarp::dev::Nav2D::MapGrid2D> m_maps_storage;
58 std::map<std::string, yarp::dev::Nav2D::Map2DLocation> m_locations_storage;
59 std::map<std::string, yarp::dev::Nav2D::Map2DPath> m_paths_storage;
60 std::map<std::string, yarp::dev::Nav2D::Map2DArea> m_areas_storage;
61
62public:
65 bool open(yarp::os::Searchable& params) override;
66 bool close() override;
67
68public:
69 //IMap2D methods
72 yarp::dev::ReturnValue get_map(std::string map_name, yarp::dev::Nav2D::MapGrid2D & map) override;
73 yarp::dev::ReturnValue get_map_names(std::vector<std::string> & map_names) override;
74 yarp::dev::ReturnValue remove_map(std::string map_name) override;
75 yarp::dev::ReturnValue storeLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation loc) override;
76 yarp::dev::ReturnValue storeArea(std::string area_name, yarp::dev::Nav2D::Map2DArea area) override;
77 yarp::dev::ReturnValue storePath(std::string path_name, yarp::dev::Nav2D::Map2DPath path) override;
78 yarp::dev::ReturnValue getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation & loc) override;
79 yarp::dev::ReturnValue getArea(std::string area_name, yarp::dev::Nav2D::Map2DArea & area) override;
80 yarp::dev::ReturnValue getPath(std::string path_name, yarp::dev::Nav2D::Map2DPath & path) override;
81 yarp::dev::ReturnValue getLocationsList(std::vector<std::string> & locations) override;
82 yarp::dev::ReturnValue getAreasList(std::vector<std::string> & areas) override;
83 yarp::dev::ReturnValue getPathsList(std::vector<std::string> & paths) override;
84 yarp::dev::ReturnValue getAllLocations(std::vector<yarp::dev::Nav2D::Map2DLocation>& locations) override;
85 yarp::dev::ReturnValue getAllAreas(std::vector<yarp::dev::Nav2D::Map2DArea>& areas) override;
86 yarp::dev::ReturnValue getAllPaths(std::vector<yarp::dev::Nav2D::Map2DPath>& paths) override;
87 yarp::dev::ReturnValue renameLocation(std::string original_name, std::string new_name) override;
88 yarp::dev::ReturnValue deleteLocation(std::string location_name) override;
89 yarp::dev::ReturnValue deletePath(std::string path_name) override;
90 yarp::dev::ReturnValue renameArea(std::string original_name, std::string new_name) override;
91 yarp::dev::ReturnValue renamePath(std::string original_name, std::string new_name) override;
92 yarp::dev::ReturnValue deleteArea(std::string area_name) override;
97 yarp::dev::ReturnValue clearMapTemporaryFlags(std::string map_name) override;
98 yarp::dev::ReturnValue saveMapToDisk(std::string map_name, std::string file_name) override;
99 yarp::dev::ReturnValue loadMapFromDisk(std::string file_name) override;
100 yarp::dev::ReturnValue saveMapsCollection(std::string maps_collection_file) override;
101 yarp::dev::ReturnValue loadMapsCollection(std::string maps_collection_file) override;
102 yarp::dev::ReturnValue loadLocationsAndExtras(std::string locations_file) override;
103 yarp::dev::ReturnValue saveLocationsAndExtras(std::string locations_file) override;
104 yarp::dev::ReturnValue enableMapsCompression(bool enable) override;
105
106private:
107 bool priv_load_locations_and_areas_v1(std::ifstream& file);
108 bool priv_load_locations_and_areas_v2(std::ifstream& file);
109 bool priv_load_locations_and_areas_v3(std::ifstream& file);
110
111private:
112 yarp::os::ResourceFinder m_rf_mapCollection;
113 std::mutex m_mutex;
114 yarp::os::RpcServer m_rpcPort;
115
116 bool read(yarp::os::ConnectionReader& connection) override;
117};
118
119#endif // YARP_DEV_MAP2DSTORAGE_H
contains the definition of a Map2DArea type
contains the definition of a Map2DLocation type
contains the definition of a Map2DPath type
contains the definition of a map type
contains the definition of a Vector type
This class is the parameters parser for class Map2DStorage.
Map2DStorage: A device capable of read/save collections of maps from disk, and make them accessible t...
yarp::dev::ReturnValue store_map(const yarp::dev::Nav2D::MapGrid2D &map) override
Stores a map into the map server.
yarp::dev::ReturnValue saveMapsCollection(std::string maps_collection_file) override
Save a collection of maps to disk.
yarp::dev::ReturnValue deleteLocation(std::string location_name) override
Delete a location.
yarp::dev::ReturnValue getArea(std::string area_name, yarp::dev::Nav2D::Map2DArea &area) override
Retrieves an area.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue getAllPaths(std::vector< yarp::dev::Nav2D::Map2DPath > &paths) override
Get a list of all stored paths.
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 enableMapsCompression(bool enable) override
Enable/disables maps compression over the network.
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 storeArea(std::string area_name, yarp::dev::Nav2D::Map2DArea area) override
Store an area.
yarp::dev::ReturnValue getAreasList(std::vector< std::string > &areas) override
Get a list of the names of all stored areas.
yarp::dev::ReturnValue clearAllPaths() override
Delete all stored paths.
yarp::dev::ReturnValue storePath(std::string path_name, yarp::dev::Nav2D::Map2DPath path) override
Store a path.
yarp::dev::ReturnValue clearMapTemporaryFlags(std::string map_name) override
Clear all temporary flags from a specific map.
Map2DStorage()
Map2DStorage.
yarp::dev::ReturnValue get_map_names(std::vector< std::string > &map_names) override
Gets a list containing the names of all registered maps.
yarp::dev::ReturnValue getPathsList(std::vector< std::string > &paths) override
Get a list of the names of all stored paths.
yarp::dev::ReturnValue saveLocationsAndExtras(std::string locations_file) override
Save a collection of locations/area/paths etc to disk.
yarp::dev::ReturnValue loadMapsCollection(std::string maps_collection_file) override
Load a collection of maps from disk.
yarp::dev::ReturnValue deletePath(std::string path_name) override
Delete a path.
yarp::dev::ReturnValue clearAllLocations() override
Delete 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 remove_map(std::string map_name) override
Removes a map from the map server.
yarp::dev::ReturnValue renameArea(std::string original_name, std::string new_name) override
Searches for an area and renames it.
yarp::dev::ReturnValue loadMapFromDisk(std::string file_name) override
Load a map from disk.
yarp::dev::ReturnValue clearAllMapsTemporaryFlags() override
Clear all temporary flags from all stored maps.
yarp::dev::ReturnValue deleteArea(std::string area_name) override
Delete an area.
yarp::dev::ReturnValue getAllLocations(std::vector< yarp::dev::Nav2D::Map2DLocation > &locations) override
Get a list of all stored locations.
yarp::dev::ReturnValue renamePath(std::string original_name, std::string new_name) override
Searches for a path and renames it.
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 saveMapToDisk(std::string map_name, std::string file_name) override
Save a map to disk.
yarp::dev::ReturnValue clearAllAreas() override
Delete all stored areas.
yarp::dev::ReturnValue getPath(std::string path_name, yarp::dev::Nav2D::Map2DPath &path) override
Retrieves a path.
yarp::dev::ReturnValue renameLocation(std::string original_name, std::string new_name) override
Searches for a location and renames it.
yarp::dev::ReturnValue loadLocationsAndExtras(std::string locations_file) override
Load a collection of locations/areas/paths etc from disk.
yarp::dev::ReturnValue getLocationsList(std::vector< std::string > &locations) override
Get a list of the names of all stored locations.
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
yarp::dev::ReturnValue clearAllMaps() override
Removes all the registered maps from the server.
Interface implemented by all device drivers.
IMap2D Interface.
Definition IMap2D.h:30
An interface for reading from a network connection.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
Helper class for finding config files and other external resources.
A port that is specialized as an RPC server.
Definition RpcServer.h:23
A base class for nested structures that can be searched.
Definition Searchable.h:31