Skip to content

Commit 6bf7dde

Browse files
committed
Combine package name with message namespace
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
1 parent a01e10e commit 6bf7dde

5 files changed

Lines changed: 56 additions & 43 deletions

File tree

rmw_fastrtps_cpp/src/type_support_common.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ _create_type_name(
5050
RMW_SET_ERROR_MSG("members handle is null");
5151
return "";
5252
}
53+
5354
std::ostringstream ss;
54-
ss << members->package_name_
55-
<< "::"
56-
<< members->message_namespace_
57-
<< "::dds_::"
58-
<< members->message_name_
59-
<< "_";
55+
std::string message_namespace(members->message_namespace_);
56+
std::string message_name(members->message_name_);
57+
if (!message_namespace.empty()) {
58+
ss << message_namespace << "::";
59+
}
60+
ss << "dds_::" << message_name << "_";
6061
return ss.str();
6162
}
6263

rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <cassert>
2222
#include <memory>
23+
#include <sstream>
2324
#include <string>
2425

2526
#include "rmw_fastrtps_dynamic_cpp/MessageTypeSupport.hpp"
@@ -34,9 +35,14 @@ MessageTypeSupport<MembersType>::MessageTypeSupport(const MembersType * members)
3435
assert(members);
3536
this->members_ = members;
3637

37-
std::string name = std::string(this->members_->package_name_) + "::" +
38-
this->members_->message_namespace_ + "::dds_::" + this->members_->message_name_ + "_";
39-
this->setName(name.c_str());
38+
std::ostringstream ss;
39+
std::string message_namespace(this->members_->message_namespace_);
40+
std::string message_name(this->members_->message_name_);
41+
if (!message_namespace.empty()) {
42+
ss << message_namespace << "::";
43+
}
44+
ss << "dds_::" << message_name << "_";
45+
this->setName(ss.str().c_str());
4046

4147
// Fully bound by default
4248
this->max_size_bound_ = true;

rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <fastcdr/FastBuffer.h>
1919
#include <fastcdr/Cdr.h>
2020
#include <cassert>
21+
#include <sstream>
2122
#include <string>
2223

2324
#include "rmw_fastrtps_dynamic_cpp/ServiceTypeSupport.hpp"
@@ -38,9 +39,14 @@ RequestTypeSupport<ServiceMembersType, MessageMembersType>::RequestTypeSupport(
3839
assert(members);
3940
this->members_ = members->request_members_;
4041

41-
std::string name = std::string(this->members_->package_name_) + "::" +
42-
this->members_->message_namespace_ + "::dds_::" + this->members_->message_name_ + "_";
43-
this->setName(name.c_str());
42+
std::ostringstream ss;
43+
std::string message_namespace(this->members_->message_namespace_);
44+
std::string message_name(this->members_->message_name_);
45+
if (!message_namespace.empty()) {
46+
ss << message_namespace << "::";
47+
}
48+
ss << "dds_::" << message_name << "_";
49+
this->setName(ss.str().c_str());
4450

4551
// Fully bound by default
4652
this->max_size_bound_ = true;
@@ -60,9 +66,14 @@ ResponseTypeSupport<ServiceMembersType, MessageMembersType>::ResponseTypeSupport
6066
assert(members);
6167
this->members_ = members->response_members_;
6268

63-
std::string name = std::string(this->members_->package_name_) + "::" +
64-
this->members_->message_namespace_ + "::dds_::" + this->members_->message_name_ + "_";
65-
this->setName(name.c_str());
69+
std::ostringstream ss;
70+
std::string message_namespace(this->members_->message_namespace_);
71+
std::string message_name(this->members_->message_name_);
72+
if (!message_namespace.empty()) {
73+
ss << message_namespace << "::";
74+
}
75+
ss << "dds_::" << message_name << "_";
76+
this->setName(ss.str().c_str());
6677

6778
// Fully bound by default
6879
this->max_size_bound_ = true;

rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ _create_type_name(
8080
RMW_SET_ERROR_MSG("members handle is null");
8181
return "";
8282
}
83+
8384
std::ostringstream ss;
84-
ss << members->package_name_
85-
<< "::"
86-
<< members->message_namespace_
87-
<< "::dds_::"
88-
<< members->message_name_
89-
<< "_";
85+
std::string message_namespace(members->message_namespace_);
86+
std::string message_name(members->message_name_);
87+
if (!message_namespace.empty()) {
88+
ss << message_namespace << "::";
89+
}
90+
ss << "dds_::" << message_name << "_";
9091
return ss.str();
9192
}
9293

rmw_fastrtps_shared_cpp/src/demangle.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,21 @@ _demangle_if_ros_topic(const std::string & topic_name)
3434
std::string
3535
_demangle_if_ros_type(const std::string & dds_type_string)
3636
{
37-
std::regex dds_namespace_pattern("[^:]+((::.+::)+dds_::).*");
38-
std::smatch match;
37+
std::string substring = "dds_::";
38+
size_t substring_position = dds_type_string.find(substring);
3939
if (
4040
dds_type_string[dds_type_string.size() - 1] != '_' ||
41-
!std::regex_match(dds_type_string, match, dds_namespace_pattern))
41+
substring_position == std::string::npos)
4242
{
4343
// not a ROS type
4444
return dds_type_string;
4545
}
4646

47-
// The first submatch is the whole string, the second is the outer parenthesized expression
48-
// and the third is the inner parenthesized expression
49-
assert(3u == match.size());
50-
std::string substring = match[1].str();
51-
size_t substring_position = dds_type_string.find(substring);
52-
std::string pkg = dds_type_string.substr(0, substring_position);
47+
std::string type_namespace = dds_type_string.substr(0, substring_position);
48+
type_namespace = std::regex_replace(type_namespace, std::regex("::"), "/");
5349
size_t start = substring_position + substring.size();
5450
std::string type_name = dds_type_string.substr(start, dds_type_string.length() - 1 - start);
55-
return pkg + "/" + type_name;
51+
return type_namespace + type_name;
5652
}
5753

5854
/// Return the service name for a given topic if it is part of one, else "".
@@ -114,16 +110,12 @@ _demangle_service_from_topic(const std::string & topic_name)
114110
std::string
115111
_demangle_service_type_only(const std::string & dds_type_name)
116112
{
117-
std::regex dds_namespace_pattern(".*(::.*::dds_::).*");
118-
std::smatch match;
119-
if (!std::regex_match(dds_type_name, match, dds_namespace_pattern)) {
113+
std::string ns_substring = "dds_::";
114+
size_t ns_substring_position = dds_type_name.find(ns_substring);
115+
if (std::string::npos == ns_substring_position) {
120116
// not a ROS service type
121117
return "";
122118
}
123-
// The first submatch is the whole string and the second is the parenthesized expression
124-
assert(2u == match.size());
125-
std::string ns_substring = match[1].str();
126-
size_t ns_substring_position = dds_type_name.find(ns_substring);
127119
auto suffixes = {
128120
std::string("_Response_"),
129121
std::string("_Request_"),
@@ -135,7 +127,7 @@ _demangle_service_type_only(const std::string & dds_type_name)
135127
if (suffix_position != std::string::npos) {
136128
if (dds_type_name.length() - suffix_position - suffix.length() != 0) {
137129
RCUTILS_LOG_WARN_NAMED("rmw_fastrtps_shared_cpp",
138-
"service type contains '::*::dds_::' and a suffix, but not at the end"
130+
"service type contains 'dds_::' and a suffix, but not at the end"
139131
", report this: '%s'", dds_type_name.c_str());
140132
continue;
141133
}
@@ -145,13 +137,15 @@ _demangle_service_type_only(const std::string & dds_type_name)
145137
}
146138
if (std::string::npos == suffix_position) {
147139
RCUTILS_LOG_WARN_NAMED("rmw_fastrtps_shared_cpp",
148-
"service type contains '::*::dds_::' but does not have a suffix"
140+
"service type contains 'dds_::' but does not have a suffix"
149141
", report this: '%s'", dds_type_name.c_str());
150142
return "";
151143
}
152-
// everything checks out, reformat it from '<pkg>::srv::dds_::<type><suffix>' to '<pkg>/<type>'
153-
std::string pkg = dds_type_name.substr(0, ns_substring_position);
144+
// everything checks out, reformat it from '[type_namespace::]dds_::<type><suffix>'
145+
// to '[type_namespace/]<type>'
146+
std::string type_namespace = dds_type_name.substr(0, ns_substring_position);
147+
type_namespace = std::regex_replace(type_namespace, std::regex("::"), "/");
154148
size_t start = ns_substring_position + ns_substring.length();
155149
std::string type_name = dds_type_name.substr(start, suffix_position - start);
156-
return pkg + "/" + type_name;
150+
return type_namespace + type_name;
157151
}

0 commit comments

Comments
 (0)