Skip to content

Commit 7a31048

Browse files
committed
Add environment hook to automatically load built-in profiles via NDDS_QOS_PROFILES
Signed-off-by: Andrea Sorbini <[email protected]>
1 parent c035946 commit 7a31048

File tree

4 files changed

+253
-118
lines changed

4 files changed

+253
-118
lines changed

rmw_connextdds/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ install(
6565
RUNTIME DESTINATION bin
6666
)
6767

68+
if(NOT WIN32)
69+
ament_environment_hooks(env_hook/rmw_connextdds_resources.sh.in)
70+
endif()
71+
72+
install(
73+
FILES
74+
resource/xml/ros2_qos_profiles.xml
75+
resource/xml/USER_QOS_PROFILES.example.xml
76+
DESTINATION share/${PROJECT_NAME}/xml
77+
)
78+
6879
ament_export_libraries(${PROJECT_NAME})
6980
ament_export_dependencies(rmw_connextdds_common)
7081

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
################################################################################
2+
# (c) 2021 Copyright, Real-Time Innovations, Inc. (RTI)
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
################################################################################
16+
#
17+
# This file was automatically generated from template
18+
# `rmw_connextdds/env_hook/rmw_connextdds_resources.sh.in`
19+
#
20+
# The script will perform the following environment customizations:
21+
#
22+
# - Extend variable NDDS_QOS_PROFILES to load `ros2_qos_profiles.xml`.
23+
#
24+
################################################################################
25+
26+
################################################################################
27+
# Determine path to rmw_connextdds' share/ directory
28+
################################################################################
29+
_rmw_connextdds_find_sharedir()
30+
{
31+
(
32+
IFS=":"
33+
for pfx_dir in ${AMENT_PREFIX_PATH}; do
34+
sharedir="${pfx_dir}/share/rmw_connextdds"
35+
if [ -d "${sharedir}" ]; then
36+
cd "${sharedir}" && pwd
37+
break
38+
fi
39+
done
40+
)
41+
}
42+
43+
_rmw_connextdds_dir="$(_rmw_connextdds_find_sharedir)"
44+
_rmw_connextdds_xml_dir="${_rmw_connextdds_dir}/xml"
45+
46+
_ros2_qos_profiles="${_rmw_connextdds_xml_dir}/ros2_qos_profiles.xml"
47+
48+
################################################################################
49+
# Update NDDS_QOS_PROFILES
50+
################################################################################
51+
_rmw_connextdds_append_profile()
52+
{
53+
local already_added=$(
54+
IFS=";"
55+
for qos_profile_pfx in ${NDDS_QOS_PROFILES}; do
56+
qos_profile="${qos_profile_pfx#file://}"
57+
qos_profile_dir=$(dirname ${qos_profile})
58+
qos_profile_name=$(basename ${qos_profile})
59+
cd ${qos_profile_dir} || continue
60+
if [ "$(pwd)" = "${_rmw_connextdds_xml_dir}" -a \
61+
"${qos_profile_name}" = "ros2_qos_profiles.xml" ]; then
62+
printf "%s" "${qos_profile}"
63+
break;
64+
fi
65+
done
66+
) 2>/dev/null
67+
68+
if [ -z "${NDDS_QOS_PROFILES}" ]; then
69+
export NDDS_QOS_PROFILES="file://${_ros2_qos_profiles}"
70+
elif [ -z "${already_added}" ]; then
71+
export NDDS_QOS_PROFILES="${NDDS_QOS_PROFILES};file://${_ros2_qos_profiles}"
72+
fi
73+
}
74+
75+
if [ ! -f "${_ros2_qos_profiles}" ]; then
76+
printf "[@PROJECT_NAME@][WARNING] file ros2_qos_profiles.xml NOT FOUND\n" 1>&2
77+
printf "[@PROJECT_NAME@][WARNING] Custom built-in QoS profiles will not be available, unless you manually load them into the enviroment with variable NDDS_QOS_PROFILES.\n" 1>&2
78+
else
79+
_rmw_connextdds_append_profile
80+
fi
81+
82+
################################################################################
83+
# Clean up environment
84+
################################################################################
85+
unset _rmw_connextdds_dir \
86+
_rmw_connextdds_xml_dir \
87+
_ros2_qos_profiles \
88+
_rmw_connextdds_append_profile \
89+
_rmw_connextdds_find_sharedir

rmw_connextdds/resource/xml/USER_QOS_PROFILES.example.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://community.rti.com/schema/5.3.1/rti_dds_qos_profiles.xsd" version="5.3.1">
3-
<qos_library name="my_node">
4-
<qos_profile name="Default" is_default_qos="true" base_name="rmw_connextdds::Default">
3+
<qos_library name="my_application">
4+
<qos_profile name="MyProcess" is_default_qos="true" base_name="ros2::rmw_connextdds.base_application">
55
<datareader_qos topic_filter="rt/chatter">
66
<reliability>
77
<kind>RELIABLE_RELIABILITY_QOS</kind>

0 commit comments

Comments
 (0)