mirror of
https://github.com/moveit/moveit_task_constructor.git
synced 2025-11-04 14:49:57 +08:00
introspection: remove any invalid ROS-name chars from hostname (#465)
This commit is contained in:
parent
6a01550e8d
commit
76d293863b
@ -49,6 +49,12 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <boost/bimap.hpp>
|
#include <boost/bimap.hpp>
|
||||||
|
|
||||||
|
namespace ros {
|
||||||
|
namespace names {
|
||||||
|
bool isValidCharInName(char c); // unfortunately this is not declared in ros/names.h
|
||||||
|
} // namespace names
|
||||||
|
} // namespace ros
|
||||||
|
|
||||||
namespace moveit {
|
namespace moveit {
|
||||||
namespace task_constructor {
|
namespace task_constructor {
|
||||||
|
|
||||||
@ -57,8 +63,10 @@ std::string getTaskId(const TaskPrivate* task) {
|
|||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
char our_hostname[256] = { 0 };
|
char our_hostname[256] = { 0 };
|
||||||
gethostname(our_hostname, sizeof(our_hostname) - 1);
|
gethostname(our_hostname, sizeof(our_hostname) - 1);
|
||||||
// Hostname could have `-` as a character but this is an invalid character in ROS so we replace it with `_`
|
// Replace all invalid ROS-name chars with an underscore
|
||||||
std::replace(std::begin(our_hostname), std::end(our_hostname), '-', '_');
|
std::replace_if(
|
||||||
|
our_hostname, our_hostname + strlen(our_hostname),
|
||||||
|
[](const char ch) { return !ros::names::isValidCharInName(ch); }, '_');
|
||||||
oss << our_hostname << "_" << getpid() << "_" << reinterpret_cast<std::size_t>(task);
|
oss << our_hostname << "_" << getpid() << "_" << reinterpret_cast<std::size_t>(task);
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user