59 if (Property::copyPortable(b, the_map))
61 m_iMap2D->store_map(the_map);
69 yCError(MAP2D_NWS_YARP) <<
"Error in copyPortable";
76 if (m_iMap2D->get_map(name, map))
82 Property::copyPortable(map, mapbot);
89 yCError(MAP2D_NWS_YARP) <<
"Map" << name <<
"not found";
96 std::vector<std::string> map_names;
97 m_iMap2D->get_map_names(map_names);
98 for (
auto& it : map_names)
106 if (m_iMap2D->remove_map(name))
113 yCError(MAP2D_NWS_YARP) <<
"Map not found";
120 m_iMap2D->clearAllMaps();
129 if (m_iMap2D->saveMapsCollection(mapfile))
136 yCError(MAP2D_NWS_YARP,
"Unable to save collection");
144 if (m_iMap2D->saveLocationsAndExtras(locfile))
151 yCError(MAP2D_NWS_YARP,
"Unable to save collection");
158 yCError(MAP2D_NWS_YARP,
"Parser error");
168 if (m_iMap2D->loadMapsCollection(mapfile))
175 yCError(MAP2D_NWS_YARP,
"Unable to load collection");
183 if (m_iMap2D->loadLocationsAndExtras(locfile))
190 yCError(MAP2D_NWS_YARP,
"Unable to load collection");
197 yCError(MAP2D_NWS_YARP,
"Parser error");
204 yCError(MAP2D_NWS_YARP,
"Invalid vocab received in Map2D_nws_yarp");
219 std::vector<std::string> loc_names;
220 m_iMap2D->getLocationsList(loc_names);
221 for (
auto& it : loc_names)
225 yCInfo(MAP2D_NWS_YARP) <<
"The following locations are currently stored in the server:" << l.
toString();
234 std::vector<std::string> area_names;
235 m_iMap2D->getAreasList(area_names);
236 for (
auto& it : area_names)
240 yCInfo(MAP2D_NWS_YARP) <<
"The following areas are currently stored in the server:" << l.
toString();
249 std::vector<std::string> path_names;
250 m_iMap2D->getPathsList(path_names);
251 for (
auto& it : path_names)
255 yCInfo(MAP2D_NWS_YARP) <<
"The following paths are currently stored in the server: " << l.
toString();
259 m_iMap2D->clearAllLocations();
261 yCInfo(MAP2D_NWS_YARP) <<
"All locations deleted";
266 m_iMap2D->clearAllAreas();
268 yCInfo(MAP2D_NWS_YARP) <<
"All areas deleted";
273 m_iMap2D->clearAllPaths();
274 yCInfo(MAP2D_NWS_YARP) <<
"All paths deleted";
279 m_iMap2D->clearAllMapsTemporaryFlags();
280 yCInfo(MAP2D_NWS_YARP) <<
"Temporary flags deleted from all maps";
286 if (m_iMap2D->clearMapTemporaryFlags(map_name))
288 yCInfo(MAP2D_NWS_YARP) <<
"Temporary flags cleaned" << map_name;
293 yCError(MAP2D_NWS_YARP,
"User requested an invalid map name");
300 if (m_iMap2D->deletePath(location_name))
303 yCInfo(MAP2D_NWS_YARP) <<
"Deleted location" << location_name;
307 yCError(MAP2D_NWS_YARP,
"User requested an invalid location name");
314 if (m_iMap2D->deleteArea(area_name))
316 yCInfo(MAP2D_NWS_YARP) <<
"Deleted area" << area_name;
321 yCError(MAP2D_NWS_YARP,
"User requested an invalid area name");
328 if (m_iMap2D->deletePath(path_name))
330 yCInfo(MAP2D_NWS_YARP) <<
"Deleted path" << path_name;
335 yCError(MAP2D_NWS_YARP,
"User requested an invalid location name");
344 if (m_iMap2D->renameLocation(orig_name, new_name))
346 yCInfo(MAP2D_NWS_YARP) <<
"Location:" << orig_name <<
"renamed to:" << new_name;
351 yCError(MAP2D_NWS_YARP,
"User requested an invalid rename operation");
360 if (m_iMap2D->renameArea(orig_name, new_name))
362 yCInfo(MAP2D_NWS_YARP) <<
"Area:" << orig_name <<
"renamed to:" << new_name;
367 yCError(MAP2D_NWS_YARP,
"User requested an invalid rename operation");
376 if (m_iMap2D->renamePath(orig_name, new_name))
378 yCInfo(MAP2D_NWS_YARP) <<
"Path:" << orig_name <<
"renamed to:" << new_name;
383 yCError(MAP2D_NWS_YARP,
"User requested an invalid rename operation");
391 if (m_iMap2D->getLocation(loc_name, loc))
394 yCInfo(MAP2D_NWS_YARP) <<
"Retrieved location" << loc_name <<
"at" << loc.
toString();
403 yCError(MAP2D_NWS_YARP,
"User requested an invalid location name");
410 if (m_iMap2D->getArea(area_name, area))
414 if (Property::copyPortable(areatemp, areabot) ==
false)
416 yCError(MAP2D_NWS_YARP) <<
"VOCAB_NAV_GET_X VOCAB_NAV_AREA failed copyPortable()";
421 yCInfo(MAP2D_NWS_YARP) <<
"Retrieved area" << area_name <<
"at" << area.
toString();
425 Property::copyPortable(areatemp, areabot);
431 yCError(MAP2D_NWS_YARP,
"User requested an invalid area name");
438 if (m_iMap2D->getPath(path_name, path))
441 if (Property::copyPortable(path, pathbot) ==
false)
443 yCError(MAP2D_NWS_YARP) <<
"VOCAB_NAV_GET_X VOCAB_NAV_PATH failed copyPortable()";
448 yCInfo(MAP2D_NWS_YARP) <<
"Retrieved path" << path_name <<
"at" << path.
toString();
452 Property::copyPortable(path, pathbot);
458 yCError(MAP2D_NWS_YARP,
"User requested an invalid path name");
471 m_iMap2D->storeLocation(name, location);
472 yCInfo(MAP2D_NWS_YARP) <<
"Added location" << name <<
"at" << location.
toString();
481 if (Property::copyPortable(b, area))
483 m_iMap2D->storeArea(area_name, area);
484 yCInfo(MAP2D_NWS_YARP) <<
"Added area" << area_name <<
"at" << area.
toString();
489 yCError(MAP2D_NWS_YARP) <<
"VOCAB_NAV_STORE_X VOCAB_NAV_AREA failed copyPortable()";
499 if (Property::copyPortable(b, path))
501 m_iMap2D->storePath(path_name, path);
502 yCInfo(MAP2D_NWS_YARP) <<
"Added path" << path_name <<
"at" << path.
toString();
507 yCError(MAP2D_NWS_YARP) <<
"VOCAB_NAV_STORE_X VOCAB_NAV_PATH failed copyPortable()";
530 if(m_iMap2D->saveLocationsAndExtras(in.
get(1).
asString()))
536 out.
addString(
"save_locations&areas failed");
541 if(m_iMap2D->loadLocationsAndExtras(in.
get(1).
asString()))
547 out.
addString(
"load_locations&areas failed");
552 std::vector<std::string> vec;
553 m_iMap2D->getLocationsList(vec);
554 for (
auto it = vec.begin(); it != vec.end(); ++it)
561 std::vector<std::string> vec;
562 m_iMap2D->getAreasList(vec);
563 for (
auto it = vec.begin(); it != vec.end(); ++it)
570 std::vector<std::string> vec;
571 m_iMap2D->getPathsList(vec);
572 for (
auto it = vec.begin(); it != vec.end(); ++it)
579 if(m_iMap2D->saveMapsCollection(in.
get(1).
asString()))
590 if(m_iMap2D->loadMapsCollection(in.
get(1).
asString()))
602 std::string map_file = in.
get(2).
asString() +
".map";
605 if (m_iMap2D->get_map(map_name, map)==
false)
607 out.
addString(
"save_map failed: map " + map_name +
" not found");
614 out.
addString(map_file +
" successfully saved");
618 out.
addString(
"save_map failed: unable to save " + map_name +
" to "+ map_file);
628 if (m_iMap2D->store_map(map))
644 std::vector<std::string> vec;
645 m_iMap2D->get_map_names(vec);
646 for (
auto it = vec.begin(); it != vec.end(); ++it)
651 else if(in.
get(0).
asString() ==
"clear_all_locations")
653 m_iMap2D->clearAllLocations();
656 else if (in.
get(0).
asString() ==
"clear_all_areas")
658 m_iMap2D->clearAllAreas();
661 else if (in.
get(0).
asString() ==
"clear_all_paths")
663 m_iMap2D->clearAllPaths();
668 m_iMap2D->clearAllMaps();
671 else if (in.
get(0).
asString() ==
"send_maps_compressed")
673 m_send_maps_compressed = in.
get(1).
asBool();
679 out.
addString(
"'save_locations&areas <full path filename>' to save locations and areas on a file");
680 out.
addString(
"'load_locations&areas <full path filename>' to load locations and areas from a file");
681 out.
addString(
"'list_locations' to view a list of all stored locations");
682 out.
addString(
"'list_areas' to view a list of all stored areas");
683 out.
addString(
"'list_paths' to view a list of all stored paths");
684 out.
addString(
"'clear_all_locations' to clear all stored locations");
685 out.
addString(
"'clear_all_areas' to clear all stored areas");
686 out.
addString(
"'clear_all_paths' to clear all stored paths");
687 out.
addString(
"'save_maps <full path>' to save a map collection to a folder");
688 out.
addString(
"'load_maps <full path>' to load a map collection from a folder");
689 out.
addString(
"'save_map <map_name> <full path>' to save a single map");
690 out.
addString(
"'load_map <full path>' to load a single map");
691 out.
addString(
"'list_maps' to view a list of all stored maps");
692 out.
addString(
"'clear_all_maps' to clear all stored maps");
693 out.
addString(
"'send_maps_compressed <0/1>' to set the map transmission mode");
697 out.
addString(
"request not understood, call 'help' to see a list of available commands");
704 std::lock_guard<std::mutex> lock(m_mutex);
707 bool ok = in.
read(connection);
715 parse_string_command(in, out);
720 parse_vocab_command(in, out);
724 if (returnToSender !=
nullptr)
726 out.
write(*returnToSender);
730 yCError(MAP2D_NWS_YARP) <<
"Invalid return to sender";
740 if (!config.
check(
"name"))
742 m_rpcPortName =
"/map2D_nws_yarp/rpc";
750 if (!m_rpcPort.open(m_rpcPortName))
752 yCError(MAP2D_NWS_YARP,
"Failed to open port %s", m_rpcPortName.c_str());
755 m_rpcPort.setReader(*
this);
758 if (config.
check(
"subdevice"))
764 if (!m_drv.open(p) || !m_drv.isValid())
766 yCError(MAP2D_NWS_YARP) <<
"Failed to open subdevice.. check params";
772 yCError(MAP2D_NWS_YARP) <<
"Failed to open subdevice.. check params";
778 yCInfo(MAP2D_NWS_YARP) <<
"Waiting for device to attach";
786 yCTrace(MAP2D_NWS_YARP,
"Close");
800 driver->
view(m_iMap2D);
803 if (
nullptr == m_iMap2D)
805 yCError(MAP2D_NWS_YARP,
"Subdevice passed to attach method is invalid");
constexpr yarp::conf::vocab32_t VOCAB_OK
constexpr yarp::conf::vocab32_t VOCAB_ERR
constexpr yarp::conf::vocab32_t VOCAB_NAV_DELETE_X
constexpr yarp::conf::vocab32_t VOCAB_INAVIGATION
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_LIST_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_AREA
constexpr yarp::conf::vocab32_t VOCAB_NAV_STORE_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_GET_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_RENAME_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_LOCATION
constexpr yarp::conf::vocab32_t VOCAB_NAV_TEMPORARY_FLAGS
constexpr yarp::conf::vocab32_t VOCAB_NAV_CLEARALL_X
constexpr yarp::conf::vocab32_t VOCAB_NAV_PATH
constexpr yarp::conf::vocab32_t VOCAB_IMAP_LOAD_X
constexpr yarp::conf::vocab32_t VOCAB_IMAP_OK
constexpr yarp::conf::vocab32_t VOCAB_IMAP_SAVE_X
constexpr yarp::conf::vocab32_t VOCAB_IMAP
constexpr yarp::conf::vocab32_t VOCAB_IMAP_GET_MAP
constexpr yarp::conf::vocab32_t VOCAB_IMAP_SET_MAP
constexpr yarp::conf::vocab32_t VOCAB_IMAP_LOCATIONS_COLLECTION
constexpr yarp::conf::vocab32_t VOCAB_IMAP_MAPS_COLLECTION
constexpr yarp::conf::vocab32_t VOCAB_IMAP_CLEAR_ALL_MAPS
constexpr yarp::conf::vocab32_t VOCAB_IMAP_ERROR
constexpr yarp::conf::vocab32_t VOCAB_IMAP_REMOVE
constexpr yarp::conf::vocab32_t VOCAB_IMAP_GET_NAMES
Map2D_nws_yarp()
Map2D_nws_yarp.
bool detach() override
Detach the object (you must have first called attach).
bool attach(yarp::dev::PolyDriver *driver) override
Attach to another object.
bool open(yarp::os::Searchable ¶ms) override
Open the DeviceDriver.
bool close() override
Close the DeviceDriver.
bool view(T *&x)
Get an interface to the device driver.
std::string toString() const
Returns text representation of the area.
std::string toString() const
Returns text representation of the path.
bool enable_map_compression_over_network(bool val)
bool loadFromFile(std::string map_filename)
Loads a yarp map file from disk.
bool saveToFile(std::string map_filename) const
Store a yarp map file to disk.
A container for a device driver.
bool isValid() const
Check if device is valid.
A simple collection of objects that can be described and transmitted in a portable way.
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void clear()
Empties the bottle of any objects it contains.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
An interface for reading from a network connection.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
An interface for writing to a network connection.
A class for storing options and configuration information.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
A base class for nested structures that can be searched.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool isString() const
Checks if value is a string.
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
virtual bool asBool() const
Get boolean value.
virtual bool isVocab32() const
Checks if value is a vocabulary identifier.
virtual std::string asString() const
Get string value.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface for the device drivers.
An interface to the operating system, including Port based communication.
std::string toString() const
Returns text representation of the location.