Branch data Line data Source code
1 : : /* 2 : : * Copyright (C) 2026 by Thun Lu. All rights reserved. 3 : : * Author: Thun Lu <thun.lu@zohomail.cn> 4 : : * Repo: https://github.com/thun-res/vlink 5 : : * _ __ __ _ __ 6 : : * | | / / / / (_) ____ / /__ 7 : : * | | / / / / / / / __ \ / //_/ 8 : : * | |/ / / /___ / / / / / / / ,< 9 : : * |___/ /_____/ /_/ /_/ /_/ /_/|_| 10 : : * 11 : : * Licensed under the Apache License, Version 2.0 (the "License"); 12 : : * you may not use this file except in compliance with the License. 13 : : * You may obtain a copy of the License at 14 : : * 15 : : * http://www.apache.org/licenses/LICENSE-2.0 16 : : * 17 : : * Unless required by applicable law or agreed to in writing, software 18 : : * distributed under the License is distributed on an "AS IS" BASIS, 19 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 : : * See the License for the specific language governing permissions and 21 : : * limitations under the License. 22 : : */ 23 : : 24 : : #pragma once 25 : : 26 : : #include "./base/helpers.h" 27 : : #include "./dds_factory.h" 28 : : #include "./extension/qos_profile.h" 29 : : 30 : : namespace vlink { 31 : : 32 : 1732 : [[maybe_unused]] static Duration_t get_dds_duration(int32_t ms) { 33 [ + + ]: 1732 : if (ms < 0) { 34 : : #ifdef VLINK_SUPPORT_DDS_V3 35 : : return dds::c_TimeInfinite; 36 : : #else 37 : 347 : return eprosima::fastrtps::c_TimeInfinite; 38 : : #endif 39 : : } 40 : : 41 : 1385 : return Duration_t(ms / 1000, (ms % 1000) * 1000000); 42 : : } 43 : : 44 : : template <typename T> 45 : 287 : [[maybe_unused]] static void convert_qos(T& dds_qos, const Qos& qos, int32_t depth = 0) { 46 [ + + ]: 287 : if VUNLIKELY (!qos.valid) { 47 : 19 : return; 48 : : } 49 : : 50 : : // reliability 51 : : 52 [ + + ]: 268 : if (qos.reliability.kind == Qos::Reliability::kBestEffort) { 53 : 7 : dds_qos.reliability().kind = dds::BEST_EFFORT_RELIABILITY_QOS; 54 : : } else { 55 : 261 : dds_qos.reliability().kind = dds::RELIABLE_RELIABILITY_QOS; 56 : : } 57 : : 58 : 268 : dds_qos.reliability().max_blocking_time = get_dds_duration(qos.reliability.block_time); 59 : : 60 : : if constexpr (std::is_same_v<T, dds::DataWriterQos>) { 61 : : #ifdef VLINK_SUPPORT_DDS_V3 62 : : dds_qos.reliable_writer_qos().times.heartbeat_period = get_dds_duration(qos.reliability.heartbeat_time); 63 : : #else 64 : 142 : dds_qos.reliable_writer_qos().times.heartbeatPeriod = get_dds_duration(qos.reliability.heartbeat_time); 65 : : #endif 66 : : } 67 : : 68 : : // history 69 : : 70 [ + + ]: 268 : if (qos.history.kind == Qos::History::kKeepLast) { 71 : 164 : dds_qos.history().kind = dds::KEEP_LAST_HISTORY_QOS; 72 : : } else { 73 : 104 : dds_qos.history().kind = dds::KEEP_ALL_HISTORY_QOS; 74 : : } 75 : : 76 [ + + ]: 268 : if (depth == 0) { 77 : 267 : dds_qos.history().depth = qos.history.depth; 78 : : } else { 79 : 1 : dds_qos.history().depth = depth; 80 : : } 81 : : 82 : : // durability 83 : : 84 [ + + ]: 268 : if (qos.durability.kind == Qos::Durability::kVolatile) { 85 : 220 : dds_qos.durability().kind = dds::VOLATILE_DURABILITY_QOS; 86 [ + + ]: 48 : } else if (qos.durability.kind == Qos::Durability::kTransientLocal) { 87 : 44 : dds_qos.durability().kind = dds::TRANSIENT_LOCAL_DURABILITY_QOS; 88 [ + + ]: 4 : } else if (qos.durability.kind == Qos::Durability::kTransient) { 89 : 2 : dds_qos.durability().kind = dds::TRANSIENT_DURABILITY_QOS; 90 : : } else { 91 : 2 : dds_qos.durability().kind = dds::PERSISTENT_DURABILITY_QOS; 92 : : } 93 : : 94 : : // publish_mode 95 : : if constexpr (std::is_same_v<T, dds::DataWriterQos>) { 96 [ + + ]: 142 : if (qos.publish_mode.kind == Qos::PublishMode::kSync) { 97 : 140 : dds_qos.publish_mode().kind = dds::SYNCHRONOUS_PUBLISH_MODE; 98 : : } else { 99 : 2 : dds_qos.publish_mode().kind = dds::ASYNCHRONOUS_PUBLISH_MODE; 100 : : } 101 : : } 102 : : 103 : : // liveliness 104 : : 105 [ + + ]: 268 : if (qos.liveliness.kind == Qos::Liveliness::kAutomatic) { 106 : 264 : dds_qos.liveliness().kind = dds::AUTOMATIC_LIVELINESS_QOS; 107 [ + + ]: 4 : } else if (qos.liveliness.kind == Qos::Liveliness::kManualParticipant) { 108 : 2 : dds_qos.liveliness().kind = dds::MANUAL_BY_PARTICIPANT_LIVELINESS_QOS; 109 : : } else { 110 : 2 : dds_qos.liveliness().kind = dds::MANUAL_BY_TOPIC_LIVELINESS_QOS; 111 : : } 112 : : 113 : 268 : dds_qos.liveliness().lease_duration = get_dds_duration(qos.liveliness.duration); 114 : : 115 [ + + ]: 268 : if (qos.liveliness.duration > 0) { 116 : 250 : dds_qos.liveliness().announcement_period = get_dds_duration(qos.liveliness.duration / 10); 117 : : } 118 : : 119 : : // destination_order 120 : : 121 [ + + ]: 268 : if (qos.destination_order.kind == Qos::DestinationOrder::kReceptionTimestamp) { 122 : 266 : dds_qos.destination_order().kind = dds::BY_RECEPTION_TIMESTAMP_DESTINATIONORDER_QOS; 123 : : } else { 124 : 2 : dds_qos.destination_order().kind = dds::BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS; 125 : : } 126 : : 127 : : // ownership 128 : : 129 [ + + ]: 268 : if (qos.ownership.kind == Qos::Ownership::kShared) { 130 : 266 : dds_qos.ownership().kind = dds::SHARED_OWNERSHIP_QOS; 131 : : } else { 132 : 2 : dds_qos.ownership().kind = dds::EXCLUSIVE_OWNERSHIP_QOS; 133 : : } 134 : : 135 : : // deadline 136 : 268 : dds_qos.deadline().period = get_dds_duration(qos.deadline.period); 137 : : 138 : : // lifespan 139 : 268 : dds_qos.lifespan().duration = get_dds_duration(qos.lifespan.duration); 140 : : 141 : : // latency_budget 142 : 268 : dds_qos.latency_budget().duration = get_dds_duration(qos.latency_budget.duration); 143 : : 144 : : // resource_limits 145 : : 146 [ + - + - ]: 268 : if (qos.resource_limits.max_samples > 0 && qos.resource_limits.max_instances > 0 && 147 [ + - ]: 268 : qos.resource_limits.max_samples_per_instance > 0) { 148 : 268 : dds_qos.resource_limits().max_samples = qos.resource_limits.max_samples; 149 : 268 : dds_qos.resource_limits().max_instances = qos.resource_limits.max_instances; 150 : 268 : dds_qos.resource_limits().max_samples_per_instance = qos.resource_limits.max_samples_per_instance; 151 : : } 152 : : } 153 : : 154 : : } // namespace vlink