Skip to content

Commit

Permalink
Add function for checking QoS profile compatibility (#45)
Browse files Browse the repository at this point in the history
* Add function for checking QoS profile compatibility

Given QoS profiles for a publisher and a subscription, this function
will return `true` if the profiles are compatible.
Compatible profiles implies that the subscription and publisher will
be able to communicate.

Connected to ros2/rmw#299

Signed-off-by: Jacob Perron <[email protected]>

* Refactor signature of _write_to_buffer

Signed-off-by: Jacob Perron <[email protected]>

* Set error message instead of setting reason

Signed-off-by: Jacob Perron <[email protected]>

* Error is null reason and non-zero reason_size

Signed-off-by: Jacob Perron <[email protected]>

* Do not set output parameter if an error occurs

Signed-off-by: Jacob Perron <[email protected]>

* Add test for reason buffer too small

Signed-off-by: Jacob Perron <[email protected]>

* Warn on unknown values instead of error

Signed-off-by: Jacob Perron <[email protected]>

* Fixes

* Use vsnprintf over snprintf (or undefined things can happen)
* Handle NULL return value from `*to_str()` functions
* Add more tests

Signed-off-by: Jacob Perron <[email protected]>

* Guard against zero reason_size

Add test case.

Signed-off-by: Jacob Perron <[email protected]>
  • Loading branch information
jacobperron authored Feb 28, 2021
1 parent 37d16b8 commit f51dee1
Show file tree
Hide file tree
Showing 5 changed files with 1,203 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rmw_dds_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ rosidl_generate_interfaces(
add_library(${PROJECT_NAME}_library SHARED
src/gid_utils.cpp
src/graph_cache.cpp
src/qos.cpp
src/time_utils.cpp)

set_target_properties(${PROJECT_NAME}_library
Expand Down Expand Up @@ -93,6 +94,11 @@ if(BUILD_TESTING)
target_link_libraries(test_gid_utils ${PROJECT_NAME}_library)
endif()

ament_add_gmock(test_qos test/test_qos.cpp)
if(TARGET test_qos)
target_link_libraries(test_qos ${PROJECT_NAME}_library)
endif()

ament_add_gmock(test_time_utils test/test_time_utils.cpp)
if(TARGET test_time_utils)
target_link_libraries(test_time_utils ${PROJECT_NAME}_library)
Expand Down
1 change: 1 addition & 0 deletions rmw_dds_common/docs/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ This package includes:
- A generic [`Context`](rmw_dds_common/include/rmw_dds_common/context.hpp) type to withhold most state needed to implement [ROS nodes discovery](https://github.com/ros2/design/pull/250)
- [Comparison utilities and some C++ operator overloads](rmw_dds_common/include/rmw_dds_common/gid_utils.hpp) for `rmw_gid_t` instances
- [Conversion utilities](rmw_dds_common/include/rmw_dds_common/gid_utils.hpp) between `rmw_dds_common/msg/Gid` messages and `rmw_gid_t` instances
- A function for checking the compatibility of two QoS profiles, [`qos_profile_check_compatible`](rmw_dds_common/include/rmw_dds_common/qos.hpp)
61 changes: 61 additions & 0 deletions rmw_dds_common/include/rmw_dds_common/qos.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2021 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef RMW_DDS_COMMON__QOS_HPP_
#define RMW_DDS_COMMON__QOS_HPP_

#include "rmw/qos_profiles.h"
#include "rmw/types.h"

#include "rmw_dds_common/visibility_control.h"

namespace rmw_dds_common
{

/// Check if two QoS profiles are compatible
/**
* Two QoS profiles are compatible if a publisher and subcription
* using the QoS policies can communicate with each other.
*
* This implements the rmw API \ref rmw_qos_profile_check_compatible().
* See \ref rmw_qos_profile_check_compatible() for more information.
*
* \param[in] publisher_profile: The QoS profile used for a publisher.
* \param[in] subscription_profile: The QoS profile used for a subscription.
* \param[out] compatibility: `RMW_QOS_COMPATIBILITY_OK` if the QoS profiles are compatible, or
* `RMW_QOS_COMPATIBILITY_WARNING` if the QoS profiles might be compatible, or
* `RMW_QOS_COMPATIBILITY_ERROR` if the QoS profiles are not compatible.
* \param[out] reason: A detailed reason for a QoS incompatibility or potential incompatibility.
* Must be pre-allocated by the caller.
* This parameter is optional and may be set to `nullptr` if the reason information is not
* desired.
* \param[in] reason_size: Size of the string buffer `reason`, if one is provided.
* If `reason` is `nullptr`, then this parameter must be zero.
* \return `RMW_RET_OK` if the check was successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if `compatiblity` is `nullptr`, or
* \return `RMW_RET_INVALID_ARGUMENT` if `reason` is `nullptr` and `reason_size` is not zero, or
* \return `RMW_RET_ERROR` if there is an unexpected error.
*/
RMW_DDS_COMMON_PUBLIC
rmw_ret_t
qos_profile_check_compatible(
const rmw_qos_profile_t publisher_qos,
const rmw_qos_profile_t subscription_qos,
rmw_qos_compatibility_type_t * compatibility,
char * reason,
size_t reason_size);

} // namespace rmw_dds_common

#endif // RMW_DDS_COMMON__QOS_HPP_
Loading

0 comments on commit f51dee1

Please sign in to comment.