Skip to content

Commit 3498255

Browse files
committed
update interospection to get hostname and pid using winsock2
1 parent f4211e4 commit 3498255

1 file changed

Lines changed: 40 additions & 8 deletions

File tree

patch/ros-lyrical-moveit-task-constructor-core.patch

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,53 @@ index 9ddb94f..9896d36 100644
8989

9090
return distance_to_cost(distance);
9191
diff --git a/src/introspection.cpp b/src/introspection.cpp
92-
index d938f95..85292d9 100644
92+
index d938f95..35d502a 100644
9393
--- a/src/introspection.cpp
9494
+++ b/src/introspection.cpp
95-
@@ -49,6 +49,10 @@
96-
#include <sstream>
95+
@@ -50,6 +50,14 @@
9796
#include <boost/bimap.hpp>
97+
#include <rcutils/isalnum_no_locale.h>
9898

9999
+#ifdef _WIN32
100-
+#include <winsock.h>
100+
+ #include <winsock2.h>
101+
+ #include <process.h>
102+
+ #pragma comment(lib, "ws2_32.lib")
103+
+#else
104+
+ #include <unistd.h>
101105
+#endif
102106
+
103-
namespace ros {
104-
namespace names {
105-
bool isValidCharInName(char c); // unfortunately this is not declared in ros/names.h
106-
@@ -214,7 +214,7 @@ void Introspection::publishAllSolutions(bool wait) {
107+
static auto LOGGER = rclcpp::get_logger("introspection");
108+
109+
namespace moveit {
110+
@@ -60,12 +68,26 @@ std::string getTaskId(const TaskPrivate* task) {
111+
static const std::string ALLOWED = "_/";
112+
std::ostringstream oss;
113+
char our_hostname[256] = { 0 };
114+
+ #ifdef _WIN32
115+
+ {
116+
+ static bool wsa_initialised = false;
117+
+ if (wsa_initialised) {
118+
+ WSADATA wsaData;
119+
+ WSAStartup(MAKEWORD(2, 2), &wsaData);
120+
+ wsa_initialised = true;
121+
+ }
122+
+ }
123+
+ #endif
124+
gethostname(our_hostname, sizeof(our_hostname) - 1);
125+
// Replace all invalid ROS-name chars with an underscore
126+
std::replace_if(
127+
our_hostname, our_hostname + strlen(our_hostname),
128+
[](const char ch) { return !rcutils_isalnum_no_locale(ch) && ALLOWED.find(ch) == std::string::npos; }, '_');
129+
- oss << our_hostname << "_" << getpid() << "_" << reinterpret_cast<std::size_t>(task);
130+
+ #ifdef _WIN32
131+
+ oss << our_hostname << "_" << _getpid() << "_" << reinterpret_cast<std::size_t>(task);
132+
+ # else
133+
+ oss << our_hostname << "_" << getpid() << "_" << reinterpret_cast<std::size_t>(task);
134+
+ #endif
135+
return oss.str();
136+
}
137+
} // namespace
138+
@@ -214,7 +236,7 @@ void Introspection::publishAllSolutions(bool wait) {
107139
};
108140
}
109141

0 commit comments

Comments
 (0)