YARP
Yet Another Robot Platform
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 
21 #include <yarp/os/PeriodicThread.h>
22 #include <yarp/os/BufferedPort.h>
23 #include <yarp/os/RpcServer.h>
24 #include <yarp/sig/Vector.h>
25 #include <yarp/dev/IMap2D.h>
26 #include <yarp/dev/MapGrid2D.h>
27 #include <yarp/dev/Map2DLocation.h>
28 #include <yarp/dev/Map2DArea.h>
29 #include <yarp/dev/Map2DPath.h>
30 #include <yarp/os/ResourceFinder.h>
31 
32 #include <yarp/dev/PolyDriver.h>
33 #include <yarp/dev/DeviceDriver.h>
34 #include <yarp/dev/api.h>
35 
36 #define DEFAULT_THREAD_PERIOD 20 //ms
37 
55 class Map2DStorage :
57  public yarp::os::PortReader,
59 {
60 private:
61  std::map<std::string, yarp::dev::Nav2D::MapGrid2D> m_maps_storage;
62  std::map<std::string, yarp::dev::Nav2D::Map2DLocation> m_locations_storage;
63  std::map<std::string, yarp::dev::Nav2D::Map2DPath> m_paths_storage;
64  std::map<std::string, yarp::dev::Nav2D::Map2DArea> m_areas_storage;
65 
66 public:
67  Map2DStorage();
69  bool open(yarp::os::Searchable& params) override;
70  bool close() override;
71 
72 public:
73  //IMap2D methods
74  bool clearAllMaps() override;
75  bool store_map(const yarp::dev::Nav2D::MapGrid2D & map) override;
76  bool get_map(std::string map_name, yarp::dev::Nav2D::MapGrid2D & map) override;
77  bool get_map_names(std::vector<std::string> & map_names) override;
78  bool remove_map(std::string map_name) override;
79  bool storeLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation loc) override;
80  bool storeArea(std::string area_name, yarp::dev::Nav2D::Map2DArea area) override;
81  bool storePath(std::string path_name, yarp::dev::Nav2D::Map2DPath path) override;
82  bool getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation & loc) override;
83  bool getArea(std::string area_name, yarp::dev::Nav2D::Map2DArea & area) override;
84  bool getPath(std::string path_name, yarp::dev::Nav2D::Map2DPath & path) override;
85  bool getLocationsList(std::vector<std::string> & locations) override;
86  bool getAreasList(std::vector<std::string> & areas) override;
87  bool getPathsList(std::vector<std::string> & paths) override;
88  bool renameLocation(std::string original_name, std::string new_name) override;
89  bool deleteLocation(std::string location_name) override;
90  bool deletePath(std::string path_name) override;
91  bool renameArea(std::string original_name, std::string new_name) override;
92  bool renamePath(std::string original_name, std::string new_name) override;
93  bool deleteArea(std::string area_name) override;
94  bool clearAllLocations() override;
95  bool clearAllAreas() override;
96  bool clearAllPaths() override;
97  bool clearAllMapsTemporaryFlags() override;
98  bool clearMapTemporaryFlags(std::string map_name) override;
99  bool saveMapsCollection(std::string maps_collection_file) override;
100  bool loadMapsCollection(std::string maps_collection_file) override;
101 
102  bool loadLocationsAndExtras(std::string locations_file) override;
103  bool saveLocationsAndExtras(std::string locations_file) override;
104 
105 private:
106  bool priv_load_locations_and_areas_v1(std::ifstream& file);
107  bool priv_load_locations_and_areas_v2(std::ifstream& file);
108 
109 private:
110  yarp::os::ResourceFinder m_rf_mapCollection;
111  std::mutex m_mutex;
112  std::string m_rpcPortName;
113  yarp::os::RpcServer m_rpcPort;
114 
115  bool read(yarp::os::ConnectionReader& connection) override;
116 };
117 
118 #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
Map2DStorage: A device capable of read/save collections of maps from disk, and make them accessible t...
Definition: map2DStorage.h:59
bool getLocationsList(std::vector< std::string > &locations) override
Get a list of all stored locations.
bool renamePath(std::string original_name, std::string new_name) override
Searches for a path and renames it.
bool deleteArea(std::string area_name) override
Delete an area.
bool saveLocationsAndExtras(std::string locations_file) override
Save a collection of locations/area/paths etc.
bool getPath(std::string path_name, yarp::dev::Nav2D::Map2DPath &path) override
Retrieves a path.
bool close() override
Close the DeviceDriver.
bool clearAllLocations() override
Delete all stored locations.
bool deleteLocation(std::string location_name) override
Delete a location.
bool clearMapTemporaryFlags(std::string map_name) override
Clear all temporary flags from a specific map.
bool storeLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation loc) override
Store a location specified by the user in the world reference frame.
bool store_map(const yarp::dev::Nav2D::MapGrid2D &map) override
Stores a map into the map server.
bool getAreasList(std::vector< std::string > &areas) override
Get a list of all stored areas.
bool renameLocation(std::string original_name, std::string new_name) override
Searches for a location and renames it.
bool deletePath(std::string path_name) override
Delete a path.
bool saveMapsCollection(std::string maps_collection_file) override
Save a collection of maps.
bool get_map(std::string map_name, yarp::dev::Nav2D::MapGrid2D &map) override
Gets a map from the map server.
Map2DStorage()
Map2DStorage.
bool renameArea(std::string original_name, std::string new_name) override
Searches for an area and renames it.
bool remove_map(std::string map_name) override
Removes a map from the map server.
bool loadMapsCollection(std::string maps_collection_file) override
Load a collection of maps.
bool get_map_names(std::vector< std::string > &map_names) override
Gets a list containing the names of all registered maps.
bool getLocation(std::string location_name, yarp::dev::Nav2D::Map2DLocation &loc) override
Retrieves a location specified by the user in the world reference frame.
bool clearAllAreas() override
Delete all stored areas.
bool clearAllPaths() override
Delete all stored paths.
bool storePath(std::string path_name, yarp::dev::Nav2D::Map2DPath path) override
Store a path.
bool clearAllMaps() override
Removes all the registered maps from the server.
bool storeArea(std::string area_name, yarp::dev::Nav2D::Map2DArea area) override
Store an area.
bool getPathsList(std::vector< std::string > &paths) override
Get a list of all stored paths.
bool clearAllMapsTemporaryFlags() override
Clear all temporary flags from all stored maps.
bool getArea(std::string area_name, yarp::dev::Nav2D::Map2DArea &area) override
Retrieves an area.
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
bool loadLocationsAndExtras(std::string locations_file) override
Load a collection of locations/areas/paths etc.
Interface implemented by all device drivers.
Definition: DeviceDriver.h:35
IMap2D Interface.
Definition: IMap2D.h:36
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:25
Helper class for finding config files and other external resources.
A port that is specialized as an RPC server.
Definition: RpcServer.h:24
A base class for nested structures that can be searched.
Definition: Searchable.h:66