Add compilation guards for RMW compatibility
Use CMake rmw_VERSION for conditional compilation Signed-off-by: Dan Rose <dan@digilabs.io>
This commit is contained in:
parent
94e53ce83f
commit
c51c884413
2 changed files with 64 additions and 22 deletions
|
@ -72,6 +72,13 @@ ament_target_dependencies(rmw_cyclonedds_cpp
|
||||||
|
|
||||||
configure_rmw_library(rmw_cyclonedds_cpp)
|
configure_rmw_library(rmw_cyclonedds_cpp)
|
||||||
|
|
||||||
|
target_compile_definitions(${PROJECT_NAME}
|
||||||
|
PRIVATE
|
||||||
|
RMW_VERSION_MAJOR=${rmw_VERSION_MAJOR}
|
||||||
|
RMW_VERSION_MINOR=${rmw_VERSION_MINOR}
|
||||||
|
RMW_VERSION_PATCH=${rmw_VERSION_PATCH}
|
||||||
|
)
|
||||||
|
|
||||||
# Causes the visibility macros to use dllexport rather than dllimport,
|
# Causes the visibility macros to use dllexport rather than dllimport,
|
||||||
# which is appropriate when building the dll but not consuming it.
|
# which is appropriate when building the dll but not consuming it.
|
||||||
target_compile_definitions(${PROJECT_NAME}
|
target_compile_definitions(${PROJECT_NAME}
|
||||||
|
|
79
rmw_cyclonedds_cpp/src/rmw_node.cpp
Executable file → Normal file
79
rmw_cyclonedds_cpp/src/rmw_node.cpp
Executable file → Normal file
|
@ -61,6 +61,16 @@
|
||||||
#define MULTIDOMAIN 0
|
#define MULTIDOMAIN 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* True if the version of RMW is at least major.minor.patch */
|
||||||
|
#define RMW_VERSION_GTE(major, minor, patch) ( \
|
||||||
|
major < RMW_VERSION_MAJOR ? true \
|
||||||
|
: major > RMW_VERSION_MAJOR ? false \
|
||||||
|
: minor < RMW_VERSION_MINOR ? true \
|
||||||
|
: minor > RMW_VERSION_MINOR ? false \
|
||||||
|
: patch < RMW_VERSION_PATCH ? true \
|
||||||
|
: patch > RMW_VERSION_PATCH ? false \
|
||||||
|
: true)
|
||||||
|
|
||||||
/* Set to > 0 for printing warnings to stderr for each messages that was taken more than this many
|
/* Set to > 0 for printing warnings to stderr for each messages that was taken more than this many
|
||||||
ms after writing */
|
ms after writing */
|
||||||
#define REPORT_LATE_MESSAGES 0
|
#define REPORT_LATE_MESSAGES 0
|
||||||
|
@ -1088,13 +1098,18 @@ extern "C" rmw_ret_t rmw_fini_publisher_allocation(rmw_publisher_allocation_t *
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" rmw_publisher_t * rmw_create_publisher(
|
extern "C" rmw_publisher_t * rmw_create_publisher(
|
||||||
const rmw_node_t * node,
|
const rmw_node_t * node, const rosidl_message_type_support_t * type_supports,
|
||||||
const rosidl_message_type_support_t * type_supports, const char * topic_name,
|
const char * topic_name, const rmw_qos_profile_t * qos_policies
|
||||||
const rmw_qos_profile_t * qos_policies, const rmw_publisher_options_t * publisher_options)
|
#if RMW_VERSION_GTE(0,8,1)
|
||||||
|
, const rmw_publisher_options_t * publisher_options
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
CddsPublisher * pub;
|
CddsPublisher * pub;
|
||||||
rmw_publisher_t * rmw_publisher;
|
rmw_publisher_t * rmw_publisher;
|
||||||
|
#if RMW_VERSION_GTE(0,8,1)
|
||||||
RET_NULL_X(publisher_options, return nullptr);
|
RET_NULL_X(publisher_options, return nullptr);
|
||||||
|
#endif
|
||||||
if ((pub = create_cdds_publisher(node, type_supports, topic_name, qos_policies)) == nullptr) {
|
if ((pub = create_cdds_publisher(node, type_supports, topic_name, qos_policies)) == nullptr) {
|
||||||
goto fail_common_init;
|
goto fail_common_init;
|
||||||
}
|
}
|
||||||
|
@ -1105,7 +1120,9 @@ extern "C" rmw_publisher_t * rmw_create_publisher(
|
||||||
rmw_publisher->topic_name = reinterpret_cast<char *>(rmw_allocate(strlen(topic_name) + 1));
|
rmw_publisher->topic_name = reinterpret_cast<char *>(rmw_allocate(strlen(topic_name) + 1));
|
||||||
RET_ALLOC_X(rmw_publisher->topic_name, goto fail_topic_name);
|
RET_ALLOC_X(rmw_publisher->topic_name, goto fail_topic_name);
|
||||||
memcpy(const_cast<char *>(rmw_publisher->topic_name), topic_name, strlen(topic_name) + 1);
|
memcpy(const_cast<char *>(rmw_publisher->topic_name), topic_name, strlen(topic_name) + 1);
|
||||||
|
#if RMW_VERSION_GTE(0,8,1)
|
||||||
rmw_publisher->options = *publisher_options;
|
rmw_publisher->options = *publisher_options;
|
||||||
|
#endif
|
||||||
return rmw_publisher;
|
return rmw_publisher;
|
||||||
fail_topic_name:
|
fail_topic_name:
|
||||||
rmw_publisher_free(rmw_publisher);
|
rmw_publisher_free(rmw_publisher);
|
||||||
|
@ -1275,16 +1292,29 @@ extern "C" rmw_ret_t rmw_fini_subscription_allocation(rmw_subscription_allocatio
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" rmw_subscription_t * rmw_create_subscription(
|
extern "C" rmw_subscription_t * rmw_create_subscription(
|
||||||
const rmw_node_t * node,
|
const rmw_node_t * node, const rosidl_message_type_support_t * type_supports,
|
||||||
const rosidl_message_type_support_t * type_supports, const char * topic_name,
|
const char * topic_name, const rmw_qos_profile_t * qos_policies
|
||||||
const rmw_qos_profile_t * qos_policies, const rmw_subscription_options_t * subscription_options)
|
#if RMW_VERSION_GTE(0,8,1)
|
||||||
|
, const rmw_subscription_options_t * subscription_options
|
||||||
|
#else
|
||||||
|
, bool ignore_local_publications
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
CddsSubscription * sub;
|
CddsSubscription * sub;
|
||||||
rmw_subscription_t * rmw_subscription;
|
rmw_subscription_t * rmw_subscription;
|
||||||
|
#if RMW_VERSION_GTE(0,8,1)
|
||||||
RET_NULL_X(subscription_options, return nullptr);
|
RET_NULL_X(subscription_options, return nullptr);
|
||||||
if ((sub =
|
#endif
|
||||||
create_cdds_subscription(node, type_supports, topic_name, qos_policies,
|
if (
|
||||||
subscription_options->ignore_local_publications)) == nullptr)
|
(sub = create_cdds_subscription(
|
||||||
|
node, type_supports, topic_name, qos_policies,
|
||||||
|
#if RMW_VERSION_GTE(0,8,1)
|
||||||
|
subscription_options->ignore_local_publications
|
||||||
|
#else
|
||||||
|
ignore_local_publications
|
||||||
|
#endif
|
||||||
|
)) == nullptr)
|
||||||
{
|
{
|
||||||
goto fail_common_init;
|
goto fail_common_init;
|
||||||
}
|
}
|
||||||
|
@ -1296,7 +1326,9 @@ extern "C" rmw_subscription_t * rmw_create_subscription(
|
||||||
reinterpret_cast<const char *>(rmw_allocate(strlen(topic_name) + 1));
|
reinterpret_cast<const char *>(rmw_allocate(strlen(topic_name) + 1));
|
||||||
RET_ALLOC_X(rmw_subscription->topic_name, goto fail_topic_name);
|
RET_ALLOC_X(rmw_subscription->topic_name, goto fail_topic_name);
|
||||||
memcpy(const_cast<char *>(rmw_subscription->topic_name), topic_name, strlen(topic_name) + 1);
|
memcpy(const_cast<char *>(rmw_subscription->topic_name), topic_name, strlen(topic_name) + 1);
|
||||||
|
#if RMW_VERSION_GTE(0,8,1)
|
||||||
rmw_subscription->options = *subscription_options;
|
rmw_subscription->options = *subscription_options;
|
||||||
|
#endif
|
||||||
return rmw_subscription;
|
return rmw_subscription;
|
||||||
fail_topic_name:
|
fail_topic_name:
|
||||||
rmw_subscription_free(rmw_subscription);
|
rmw_subscription_free(rmw_subscription);
|
||||||
|
@ -2577,35 +2609,38 @@ static rmw_ret_t get_cs_names_and_types_by_node(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::set<dds_builtintopic_guid_t> guids;
|
std::set<dds_builtintopic_guid_t> guids;
|
||||||
if (node_name != nullptr &&
|
if (
|
||||||
|
node_name != nullptr &&
|
||||||
(ret = get_node_guids(node_impl, node_name, node_namespace, guids)) != RMW_RET_OK)
|
(ret = get_node_guids(node_impl, node_name, node_namespace, guids)) != RMW_RET_OK)
|
||||||
{
|
{
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
const auto re_tp = std::regex("^(" + std::string(ros_service_requester_prefix) + "|" +
|
const auto re_tp = std::regex(
|
||||||
std::string(ros_service_response_prefix) + ")(/.*)(Request|Reply)$",
|
"^(" + std::string(ros_service_requester_prefix) + "|" +
|
||||||
std::regex::extended);
|
std::string(ros_service_response_prefix) + ")(/.*)(Request|Reply)$",
|
||||||
|
std::regex::extended);
|
||||||
const auto re_typ = std::regex("^(.*::)dds_::(.*)_(Response|Request)_$", std::regex::extended);
|
const auto re_typ = std::regex("^(.*::)dds_::(.*)_(Response|Request)_$", std::regex::extended);
|
||||||
const auto filter_and_map =
|
const auto filter_and_map = [re_tp, re_typ, guids, node_name, looking_for_services](
|
||||||
[re_tp, re_typ, guids, node_name,
|
const dds_builtintopic_endpoint_t & sample,
|
||||||
looking_for_services](const dds_builtintopic_endpoint_t & sample, std::string & topic_name,
|
std::string & topic_name, std::string & type_name) -> bool {
|
||||||
std::string & type_name) -> bool {
|
|
||||||
std::cmatch cm_tp, cm_typ;
|
std::cmatch cm_tp, cm_typ;
|
||||||
if (node_name != nullptr && guids.count(sample.participant_key) == 0) {
|
if (node_name != nullptr && guids.count(sample.participant_key) == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!std::regex_search(sample.topic_name, cm_tp,
|
if (
|
||||||
re_tp) || !std::regex_search(sample.type_name, cm_typ, re_typ))
|
!std::regex_search(sample.topic_name, cm_tp, re_tp) ||
|
||||||
|
!std::regex_search(sample.type_name, cm_typ, re_typ))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (looking_for_services !=
|
if (
|
||||||
|
looking_for_services !=
|
||||||
endpoint_is_from_service(std::string(cm_tp[3]) == "Request", sample.key))
|
endpoint_is_from_service(std::string(cm_tp[3]) == "Request", sample.key))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
std::string demangled_type = std::regex_replace(std::string(cm_typ[1]), std::regex(
|
std::string demangled_type =
|
||||||
"::"), "/");
|
std::regex_replace(std::string(cm_typ[1]), std::regex("::"), "/");
|
||||||
topic_name = std::string(cm_tp[2]);
|
topic_name = std::string(cm_tp[2]);
|
||||||
type_name = std::string(demangled_type) + std::string(cm_typ[2]);
|
type_name = std::string(demangled_type) + std::string(cm_typ[2]);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue