Skip to content

Commit

Permalink
Combine package name with message namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Perron <[email protected]>
  • Loading branch information
jacobperron committed May 3, 2019
1 parent 03c1d62 commit b5256e5
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 43 deletions.
13 changes: 7 additions & 6 deletions rmw_fastrtps_cpp/src/type_support_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ _create_type_name(
RMW_SET_ERROR_MSG("members handle is null");
return "";
}

std::ostringstream ss;
ss << members->package_name_
<< "::"
<< members->message_namespace_
<< "::dds_::"
<< members->message_name_
<< "_";
std::string message_namespace(members->message_namespace_);
std::string message_name(members->message_name_);
if (!message_namespace.empty()) {
ss << message_namespace << "::";
}
ss << "dds_::" << message_name << "_";
return ss.str();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <cassert>
#include <memory>
#include <sstream>
#include <string>

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

std::string name = std::string(this->members_->package_name_) + "::" +
this->members_->message_namespace_ + "::dds_::" + this->members_->message_name_ + "_";
this->setName(name.c_str());
std::ostringstream ss;
std::string message_namespace(this->members_->message_namespace_);
std::string message_name(this->members_->message_name_);
if (!message_namespace.empty()) {
ss << message_namespace << "::";
}
ss << "dds_::" << message_name << "_";
this->setName(ss.str().c_str());

// Fully bound by default
this->max_size_bound_ = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <fastcdr/FastBuffer.h>
#include <fastcdr/Cdr.h>
#include <cassert>
#include <sstream>
#include <string>

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

std::string name = std::string(this->members_->package_name_) + "::" +
this->members_->message_namespace_ + "::dds_::" + this->members_->message_name_ + "_";
this->setName(name.c_str());
std::ostringstream ss;
std::string message_namespace(this->members_->message_namespace_);
std::string message_name(this->members_->message_name_);
if (!message_namespace.empty()) {
ss << message_namespace << "::";
}
ss << "dds_::" << message_name << "_";
this->setName(ss.str().c_str());

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

std::string name = std::string(this->members_->package_name_) + "::" +
this->members_->message_namespace_ + "::dds_::" + this->members_->message_name_ + "_";
this->setName(name.c_str());
std::ostringstream ss;
std::string message_namespace(this->members_->message_namespace_);
std::string message_name(this->members_->message_name_);
if (!message_namespace.empty()) {
ss << message_namespace << "::";
}
ss << "dds_::" << message_name << "_";
this->setName(ss.str().c_str());

// Fully bound by default
this->max_size_bound_ = true;
Expand Down
13 changes: 7 additions & 6 deletions rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ _create_type_name(
RMW_SET_ERROR_MSG("members handle is null");
return "";
}

std::ostringstream ss;
ss << members->package_name_
<< "::"
<< members->message_namespace_
<< "::dds_::"
<< members->message_name_
<< "_";
std::string message_namespace(members->message_namespace_);
std::string message_name(members->message_name_);
if (!message_namespace.empty()) {
ss << message_namespace << "::";
}
ss << "dds_::" << message_name << "_";
return ss.str();
}

Expand Down
38 changes: 16 additions & 22 deletions rmw_fastrtps_shared_cpp/src/demangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,21 @@ _demangle_if_ros_topic(const std::string & topic_name)
std::string
_demangle_if_ros_type(const std::string & dds_type_string)
{
std::regex dds_namespace_pattern("[^:]+((::.+::)+dds_::).*");
std::smatch match;
std::string substring = "dds_::";
size_t substring_position = dds_type_string.find(substring);
if (
dds_type_string[dds_type_string.size() - 1] != '_' ||
!std::regex_match(dds_type_string, match, dds_namespace_pattern))
substring_position == std::string::npos)
{
// not a ROS type
return dds_type_string;
}

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

/// Return the service name for a given topic if it is part of one, else "".
Expand Down Expand Up @@ -114,16 +110,12 @@ _demangle_service_from_topic(const std::string & topic_name)
std::string
_demangle_service_type_only(const std::string & dds_type_name)
{
std::regex dds_namespace_pattern(".*(::.*::dds_::).*");
std::smatch match;
if (!std::regex_match(dds_type_name, match, dds_namespace_pattern)) {
std::string ns_substring = "dds_::";
size_t ns_substring_position = dds_type_name.find(ns_substring);
if (std::string::npos == ns_substring_position) {
// not a ROS service type
return "";
}
// The first submatch is the whole string and the second is the parenthesized expression
assert(2u == match.size());
std::string ns_substring = match[1].str();
size_t ns_substring_position = dds_type_name.find(ns_substring);
auto suffixes = {
std::string("_Response_"),
std::string("_Request_"),
Expand All @@ -135,7 +127,7 @@ _demangle_service_type_only(const std::string & dds_type_name)
if (suffix_position != std::string::npos) {
if (dds_type_name.length() - suffix_position - suffix.length() != 0) {
RCUTILS_LOG_WARN_NAMED("rmw_fastrtps_shared_cpp",
"service type contains '::*::dds_::' and a suffix, but not at the end"
"service type contains 'dds_::' and a suffix, but not at the end"
", report this: '%s'", dds_type_name.c_str());
continue;
}
Expand All @@ -145,13 +137,15 @@ _demangle_service_type_only(const std::string & dds_type_name)
}
if (std::string::npos == suffix_position) {
RCUTILS_LOG_WARN_NAMED("rmw_fastrtps_shared_cpp",
"service type contains '::*::dds_::' but does not have a suffix"
"service type contains 'dds_::' but does not have a suffix"
", report this: '%s'", dds_type_name.c_str());
return "";
}
// everything checks out, reformat it from '<pkg>::srv::dds_::<type><suffix>' to '<pkg>/<type>'
std::string pkg = dds_type_name.substr(0, ns_substring_position);
// everything checks out, reformat it from '[type_namespace::]dds_::<type><suffix>'
// to '[type_namespace/]<type>'
std::string type_namespace = dds_type_name.substr(0, ns_substring_position);
type_namespace = std::regex_replace(type_namespace, std::regex("::"), "/");
size_t start = ns_substring_position + ns_substring.length();
std::string type_name = dds_type_name.substr(start, suffix_position - start);
return pkg + "/" + type_name;
return type_namespace + type_name;
}

0 comments on commit b5256e5

Please sign in to comment.