LCOV - code coverage report
Current view: top level - modules/dds - dds_setter_impl.cc (source / functions) Hit Total Coverage
Test: vlink Lines: 27 34 79.4 %
Date: 2026-06-27 19:56:04 Functions: 9 12 75.0 %
Branches: 13 36 36.1 %

           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                 :            : #include "./dds_setter_impl.h"
      25                 :            : 
      26                 :            : namespace vlink {
      27                 :            : 
      28                 :            : // WriterListener
      29                 :         23 : DdsSetterImpl::WriterListener::WriterListener(NodeImpl* impl) : DdsWriterListener(impl) {}
      30                 :            : 
      31                 :            : // DdsSetterImpl
      32   [ +  -  +  - ]:         24 : DdsSetterImpl::DdsSetterImpl(const DdsConf& conf) : conf_(conf) {}
      33                 :            : 
      34                 :         23 : void DdsSetterImpl::init() {
      35   [ -  +  -  -  :         23 :   if VUNLIKELY (is_cdr_type && is_security_type) {
                   -  + ]
      36   [ #  #  #  # ]:          0 :     VLOG_F("Cdr type does not support security.");
      37                 :            :   }
      38                 :            : 
      39         [ +  - ]:         23 :   participant_ = DdsFactory::create_participant(kPublisher | kSubscriber, conf_, get_all_properties());
      40                 :            : 
      41   [ +  -  +  - ]:         23 :   topic_ = DdsFactory::create_topic(kPublisher | kSubscriber, conf_, participant_.get(), is_cdr_type);
      42                 :            : 
      43                 :         23 :   publisher_ = DdsFactory::create_publisher(kPublisher, conf_, participant_.get());
      44                 :            : 
      45   [ +  -  -  +  :         23 :   if VUNLIKELY (!participant_ || !topic_) {
                   -  + ]
      46   [ #  #  #  # ]:          0 :     VLOG_E("DdsSetterImpl::init(): participant/topic creation failed; setter left uninitialised.");
      47                 :            : 
      48                 :          0 :     return;
      49                 :            :   }
      50                 :            : 
      51         [ +  - ]:         23 :   listener_.emplace(this);
      52                 :            : 
      53                 :         23 :   writer_ = DdsFactory::create_datawriter(kSetter, conf_, publisher_.get(), topic_.get(), &listener_.value());
      54                 :            : }
      55                 :            : 
      56                 :         23 : void DdsSetterImpl::deinit() {
      57                 :         23 :   detach();
      58                 :            : 
      59                 :         23 :   writer_.reset();
      60                 :         23 :   listener_.reset();
      61                 :         23 :   publisher_.reset();
      62                 :         23 :   topic_.reset();
      63                 :         23 :   participant_.reset();
      64                 :         23 : }
      65                 :            : 
      66                 :          0 : const Conf* DdsSetterImpl::get_conf() const { return &conf_; }
      67                 :            : 
      68                 :          2 : const AbstractNode* DdsSetterImpl::get_abstract_node() const { return this; }
      69                 :            : 
      70                 :          2 : Status::BasePtr DdsSetterImpl::get_status(Status::Type type) const {
      71         [ -  + ]:          2 :   if VUNLIKELY (!writer_) {
      72                 :          0 :     return std::make_shared<Status::Unknown>();
      73                 :            :   }
      74                 :            : 
      75                 :          2 :   return WriterListener::get_status(writer_.get(), type);
      76                 :            : }
      77                 :            : 
      78                 :          1 : std::any DdsSetterImpl::get_native_handle() const { return publisher_; }
      79                 :            : 
      80                 :         29 : void DdsSetterImpl::write(const Bytes& msg_data) {
      81         [ -  + ]:         29 :   if (is_cdr_type) {
      82                 :          0 :     DdsFactory::write_cdr_data(writer_.get(), msg_data);
      83                 :          0 :     return;
      84                 :            :   }
      85                 :            : 
      86                 :         58 :   DdsFactory::write_data(writer_.get(), msg_data, seq_.fetch_add(1, std::memory_order_relaxed));
      87                 :            : }
      88                 :            : 
      89                 :         23 : void DdsSetterImpl::sync(SyncCallback&& callback) { (void)callback; }
      90                 :            : 
      91                 :            : }  // namespace vlink

Generated by: LCOV version 1.14