LCOV - code coverage report
Current view: top level - modules/ddsc - ddsc_qos.hpp (source / functions) Hit Total Coverage
Test: vlink Lines: 40 40 100.0 %
Date: 2026-06-27 19:56:04 Functions: 2 2 100.0 %
Branches: 27 30 90.0 %

           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 "./ddsc_factory.hpp"
      28                 :            : #include "./extension/qos_profile.h"
      29                 :            : 
      30                 :            : namespace vlink {
      31                 :            : 
      32                 :       1075 : [[maybe_unused]] static dds_duration_t get_dds_duration(int32_t ms) {
      33         [ +  + ]:       1075 :   if (ms < 0) {
      34                 :        286 :     return DDS_INFINITY;
      35                 :            :   }
      36                 :            : 
      37                 :        789 :   return DDS_MSECS(ms);
      38                 :            : }
      39                 :            : 
      40                 :        225 : [[maybe_unused]] static void convert_qos(dds_qos_t* dds_qos, const Qos& qos, int32_t depth = 0) {
      41         [ +  + ]:        225 :   if VUNLIKELY (!qos.valid) {
      42                 :         10 :     return;
      43                 :            :   }
      44                 :            : 
      45                 :            :   // reliability
      46                 :            : 
      47         [ +  + ]:        215 :   if (qos.reliability.kind == Qos::Reliability::kBestEffort) {
      48                 :          3 :     dds_qset_reliability(dds_qos, DDS_RELIABILITY_BEST_EFFORT, get_dds_duration(qos.reliability.block_time));
      49                 :            :   } else {
      50                 :        212 :     dds_qset_reliability(dds_qos, DDS_RELIABILITY_RELIABLE, get_dds_duration(qos.reliability.block_time));
      51                 :            :   }
      52                 :            : 
      53                 :            :   // history
      54                 :            : 
      55         [ +  + ]:        215 :   if (depth == 0) {
      56                 :        208 :     depth = qos.history.depth;
      57                 :            :   }
      58                 :            : 
      59         [ +  + ]:        215 :   if (qos.history.kind == Qos::History::kKeepLast) {
      60                 :        118 :     dds_qset_history(dds_qos, DDS_HISTORY_KEEP_LAST, depth);
      61                 :            :   } else {
      62                 :         97 :     dds_qset_history(dds_qos, DDS_HISTORY_KEEP_ALL, depth);
      63                 :            :   }
      64                 :            : 
      65                 :            :   // durability
      66                 :            : 
      67         [ +  + ]:        215 :   if (qos.durability.kind == Qos::Durability::kVolatile) {
      68                 :        172 :     dds_qset_durability(dds_qos, DDS_DURABILITY_VOLATILE);
      69         [ +  + ]:         43 :   } else if (qos.durability.kind == Qos::Durability::kTransientLocal) {
      70                 :         39 :     dds_qset_durability(dds_qos, DDS_DURABILITY_TRANSIENT_LOCAL);
      71         [ +  + ]:          4 :   } else if (qos.durability.kind == Qos::Durability::kTransient) {
      72                 :          2 :     dds_qset_durability(dds_qos, DDS_DURABILITY_TRANSIENT);
      73                 :            :   } else {
      74                 :          2 :     dds_qset_durability(dds_qos, DDS_DURABILITY_PERSISTENT);
      75                 :            :   }
      76                 :            : 
      77                 :            :   // publish_mode
      78                 :            : 
      79                 :            :   // liveliness
      80                 :            : 
      81         [ +  + ]:        215 :   if (qos.liveliness.kind == Qos::Liveliness::kAutomatic) {
      82                 :        211 :     dds_qset_liveliness(dds_qos, DDS_LIVELINESS_AUTOMATIC, get_dds_duration(qos.liveliness.duration));
      83         [ +  + ]:          4 :   } else if (qos.liveliness.kind == Qos::Liveliness::kManualParticipant) {
      84                 :          2 :     dds_qset_liveliness(dds_qos, DDS_LIVELINESS_MANUAL_BY_PARTICIPANT, get_dds_duration(qos.liveliness.duration));
      85                 :            :   } else {
      86                 :          2 :     dds_qset_liveliness(dds_qos, DDS_LIVELINESS_MANUAL_BY_TOPIC, get_dds_duration(qos.liveliness.duration));
      87                 :            :   }
      88                 :            : 
      89                 :            :   // destination_order
      90                 :            : 
      91         [ +  + ]:        215 :   if (qos.destination_order.kind == Qos::DestinationOrder::kReceptionTimestamp) {
      92                 :        213 :     dds_qset_destination_order(dds_qos, DDS_DESTINATIONORDER_BY_RECEPTION_TIMESTAMP);
      93                 :            :   } else {
      94                 :          2 :     dds_qset_destination_order(dds_qos, DDS_DESTINATIONORDER_BY_SOURCE_TIMESTAMP);
      95                 :            :   }
      96                 :            : 
      97                 :            :   // ownership
      98                 :            : 
      99         [ +  + ]:        215 :   if (qos.ownership.kind == Qos::Ownership::kShared) {
     100                 :        213 :     dds_qset_ownership(dds_qos, DDS_OWNERSHIP_SHARED);
     101                 :            :   } else {
     102                 :          2 :     dds_qset_ownership(dds_qos, DDS_OWNERSHIP_EXCLUSIVE);
     103                 :            :   }
     104                 :            : 
     105                 :            :   // deadline
     106                 :        215 :   dds_qset_deadline(dds_qos, get_dds_duration(qos.deadline.period));
     107                 :            : 
     108                 :            :   // lifespan
     109                 :        215 :   dds_qset_lifespan(dds_qos, get_dds_duration(qos.lifespan.duration));
     110                 :            : 
     111                 :            :   // latency_budget
     112                 :        215 :   dds_qset_latency_budget(dds_qos, get_dds_duration(qos.latency_budget.duration));
     113                 :            : 
     114                 :            :   // resource_limits
     115                 :            : 
     116   [ +  -  +  - ]:        215 :   if (qos.resource_limits.max_samples > 0 && qos.resource_limits.max_instances > 0 &&
     117         [ +  - ]:        215 :       qos.resource_limits.max_samples_per_instance > 0) {
     118                 :        215 :     dds_qset_resource_limits(dds_qos, qos.resource_limits.max_samples, qos.resource_limits.max_instances,
     119                 :        215 :                              qos.resource_limits.max_samples_per_instance);
     120                 :            :   }
     121                 :            : }
     122                 :            : 
     123                 :            : }  // namespace vlink

Generated by: LCOV version 1.14