Skip to content

Commit

Permalink
PR Refactor
Browse files Browse the repository at this point in the history
- Took off dds_qos_policy_to_rmw_qos from qos.h to a new header inside
src called qos_converter
- renamed test file to be more representative of the function it is
testing
- refactored test code to use Value-Parameterised Gtests

Signed-off-by: Jaison Titus <jaisontj92@gmail.com>
  • Loading branch information
jaisontj committed Oct 2, 2019
1 parent 8bbf2e7 commit e4f89c1
Show file tree
Hide file tree
Showing 8 changed files with 375 additions and 249 deletions.
1 change: 1 addition & 0 deletions rmw_fastrtps_shared_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ add_library(rmw_fastrtps_shared_cpp
src/demangle.cpp
src/namespace_prefix.cpp
src/qos.cpp
src/qos_converter.cpp
src/rmw_client.cpp
src/rmw_compare_gids_equal.cpp
src/rmw_count.cpp
Expand Down
27 changes: 1 addition & 26 deletions rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/qos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ namespace eprosima
{
namespace fastrtps
{
class SubscriberAttributes;
class PublisherAttributes;
class WriterQos;
class ReaderQos;
class SubscriberAttributes;
} // namespace fastrtps
} // namespace eprosima

Expand All @@ -46,29 +44,6 @@ get_datawriter_qos(
const rmw_qos_profile_t & qos_policies,
eprosima::fastrtps::PublisherAttributes & pattr);

/*
* Converts the low-level QOS Policy; of type WriterQos or ReaderQos into rmw_qos_profile_t.
* Since WriterQos and ReaderQos do not have information about history and depth, these values are not set
* by this function.
*/
template<typename DDSQoSPolicyT>
void
dds_qos_policy_to_rmw_qos(
const DDSQoSPolicyT & dds_qos,
rmw_qos_profile_t * qos);

extern template RMW_FASTRTPS_SHARED_CPP_PUBLIC
void
dds_qos_policy_to_rmw_qos<eprosima::fastrtps::WriterQos>(
const eprosima::fastrtps::WriterQos & dds_qos,
rmw_qos_profile_t * qos);

extern template RMW_FASTRTPS_SHARED_CPP_PUBLIC
void
dds_qos_policy_to_rmw_qos<eprosima::fastrtps::ReaderQos>(
const eprosima::fastrtps::ReaderQos & dds_qos,
rmw_qos_profile_t * qos);

template<typename AttributeT>
void
dds_qos_to_rmw_qos(
Expand Down
67 changes: 1 addition & 66 deletions rmw_fastrtps_shared_cpp/src/qos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
#include <limits>

#include "rmw_fastrtps_shared_cpp/qos.hpp"
#include "qos_converter.hpp"

#include "fastrtps/attributes/PublisherAttributes.h"
#include "fastrtps/attributes/SubscriberAttributes.h"
#include "fastrtps/qos/WriterQos.h"
#include "fastrtps/qos/ReaderQos.h"

#include "rmw/error_handling.h"

Expand Down Expand Up @@ -165,70 +164,6 @@ is_valid_qos(const rmw_qos_profile_t & /* qos_policies */)
return true;
}

template<typename DDSQoSPolicyT>
void
dds_qos_policy_to_rmw_qos(
const DDSQoSPolicyT & dds_qos,
rmw_qos_profile_t * qos)
{
switch (dds_qos.m_reliability.kind) {
case eprosima::fastrtps::BEST_EFFORT_RELIABILITY_QOS:
qos->reliability = RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT;
break;
case eprosima::fastrtps::RELIABLE_RELIABILITY_QOS:
qos->reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE;
break;
default:
qos->reliability = RMW_QOS_POLICY_RELIABILITY_UNKNOWN;
break;
}

switch (dds_qos.m_durability.kind) {
case eprosima::fastrtps::TRANSIENT_LOCAL_DURABILITY_QOS:
qos->durability = RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL;
break;
case eprosima::fastrtps::VOLATILE_DURABILITY_QOS:
qos->durability = RMW_QOS_POLICY_DURABILITY_VOLATILE;
break;
default:
qos->durability = RMW_QOS_POLICY_DURABILITY_UNKNOWN;
break;
}

qos->deadline.sec = dds_qos.m_deadline.period.seconds;
qos->deadline.nsec = dds_qos.m_deadline.period.nanosec;

qos->lifespan.sec = dds_qos.m_lifespan.duration.seconds;
qos->lifespan.nsec = dds_qos.m_lifespan.duration.nanosec;

switch (dds_qos.m_liveliness.kind) {
case eprosima::fastrtps::AUTOMATIC_LIVELINESS_QOS:
qos->liveliness = RMW_QOS_POLICY_LIVELINESS_AUTOMATIC;
break;
case eprosima::fastrtps::MANUAL_BY_PARTICIPANT_LIVELINESS_QOS:
qos->liveliness = RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_NODE;
break;
case eprosima::fastrtps::MANUAL_BY_TOPIC_LIVELINESS_QOS:
qos->liveliness = RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC;
break;
default:
qos->liveliness = RMW_QOS_POLICY_LIVELINESS_UNKNOWN;
break;
}
qos->liveliness_lease_duration.sec = dds_qos.m_liveliness.lease_duration.seconds;
qos->liveliness_lease_duration.nsec = dds_qos.m_liveliness.lease_duration.nanosec;
}

template
void dds_qos_policy_to_rmw_qos<eprosima::fastrtps::WriterQos>(
const eprosima::fastrtps::WriterQos & dds_qos,
rmw_qos_profile_t * qos);

template
void dds_qos_policy_to_rmw_qos<eprosima::fastrtps::ReaderQos>(
const eprosima::fastrtps::ReaderQos & dds_qos,
rmw_qos_profile_t * qos);

template<typename AttributeT>
void
dds_qos_to_rmw_qos(
Expand Down
83 changes: 83 additions & 0 deletions rmw_fastrtps_shared_cpp/src/qos_converter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2016-2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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.

#include "qos_converter.hpp"
#include "rmw/types.h"

#include "fastrtps/qos/WriterQos.h"
#include "fastrtps/qos/ReaderQos.h"

template<typename DDSQoSPolicyT>
void
dds_qos_policy_to_rmw_qos(
const DDSQoSPolicyT & dds_qos,
rmw_qos_profile_t * qos)
{
switch (dds_qos.m_reliability.kind) {
case eprosima::fastrtps::BEST_EFFORT_RELIABILITY_QOS:
qos->reliability = RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT;
break;
case eprosima::fastrtps::RELIABLE_RELIABILITY_QOS:
qos->reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE;
break;
default:
qos->reliability = RMW_QOS_POLICY_RELIABILITY_UNKNOWN;
break;
}

switch (dds_qos.m_durability.kind) {
case eprosima::fastrtps::TRANSIENT_LOCAL_DURABILITY_QOS:
qos->durability = RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL;
break;
case eprosima::fastrtps::VOLATILE_DURABILITY_QOS:
qos->durability = RMW_QOS_POLICY_DURABILITY_VOLATILE;
break;
default:
qos->durability = RMW_QOS_POLICY_DURABILITY_UNKNOWN;
break;
}

qos->deadline.sec = dds_qos.m_deadline.period.seconds;
qos->deadline.nsec = dds_qos.m_deadline.period.nanosec;

qos->lifespan.sec = dds_qos.m_lifespan.duration.seconds;
qos->lifespan.nsec = dds_qos.m_lifespan.duration.nanosec;

switch (dds_qos.m_liveliness.kind) {
case eprosima::fastrtps::AUTOMATIC_LIVELINESS_QOS:
qos->liveliness = RMW_QOS_POLICY_LIVELINESS_AUTOMATIC;
break;
case eprosima::fastrtps::MANUAL_BY_PARTICIPANT_LIVELINESS_QOS:
qos->liveliness = RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_NODE;
break;
case eprosima::fastrtps::MANUAL_BY_TOPIC_LIVELINESS_QOS:
qos->liveliness = RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC;
break;
default:
qos->liveliness = RMW_QOS_POLICY_LIVELINESS_UNKNOWN;
break;
}
qos->liveliness_lease_duration.sec = dds_qos.m_liveliness.lease_duration.seconds;
qos->liveliness_lease_duration.nsec = dds_qos.m_liveliness.lease_duration.nanosec;
}

template
void dds_qos_policy_to_rmw_qos<eprosima::fastrtps::WriterQos>(
const eprosima::fastrtps::WriterQos & dds_qos,
rmw_qos_profile_t * qos);

template
void dds_qos_policy_to_rmw_qos<eprosima::fastrtps::ReaderQos>(
const eprosima::fastrtps::ReaderQos & dds_qos,
rmw_qos_profile_t * qos);
54 changes: 54 additions & 0 deletions rmw_fastrtps_shared_cpp/src/qos_converter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2016-2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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 QOS_CONVERTER_HPP_
#define QOS_CONVERTER_HPP_

namespace eprosima
{
namespace fastrtps
{
class ReaderQos;
class WriterQos;
} // namespace fastrtps
} // namespace eprosima

struct rmw_qos_profile_t;

/*
* Converts the low-level QOS Policy; of type WriterQos or ReaderQos into rmw_qos_profile_t.
* Since WriterQos or ReaderQos does not have information about history and depth, these values are not set
* by this function.
*
* \param[in] dds_qos of type WriterQos or ReaderQos
* \param[out] qos the equivalent of the data in WriterQos or ReaderQos in rmw_qos_profile_t
*/
template<typename DDSQoSPolicyT>
void
dds_qos_policy_to_rmw_qos(
const DDSQoSPolicyT & dds_qos,
rmw_qos_profile_t * qos);

extern template
void dds_qos_policy_to_rmw_qos<eprosima::fastrtps::WriterQos>(
const eprosima::fastrtps::WriterQos & dds_qos,
rmw_qos_profile_t * qos);

extern template
void dds_qos_policy_to_rmw_qos<eprosima::fastrtps::ReaderQos>(
const eprosima::fastrtps::ReaderQos & dds_qos,
rmw_qos_profile_t * qos);

#endif // QOS_CONVERTER_HPP_
8 changes: 4 additions & 4 deletions rmw_fastrtps_shared_cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
find_package(ament_cmake_gtest REQUIRED)
ament_add_gtest(test_dds_qos_policy_to_rmw test_dds_qos_policy_to_rmw.cpp)
if(TARGET test_dds_qos_policy_to_rmw)
ament_target_dependencies(test_dds_qos_policy_to_rmw)
target_link_libraries(test_dds_qos_policy_to_rmw ${PROJECT_NAME})
ament_add_gtest(test_dds_qos_to_rmw test_dds_qos_to_rmw.cpp)
if(TARGET test_dds_qos_to_rmw)
ament_target_dependencies(test_dds_qos_to_rmw)
target_link_libraries(test_dds_qos_to_rmw ${PROJECT_NAME})
endif()
Loading

0 comments on commit e4f89c1

Please sign in to comment.