LCOV - code coverage report
Current view: top level - modules/ddsc - ddsc_setter_impl.cc (source / functions) Hit Total Coverage
Test: vlink Lines: 26 30 86.7 %
Date: 2026-06-27 19:56:04 Functions: 9 11 81.8 %
Branches: 10 24 41.7 %

           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 "./ddsc_setter_impl.hpp"
      25                 :            : 
      26                 :            : namespace vlink {
      27                 :            : 
      28                 :            : // WriterListener
      29                 :         19 : DdscSetterImpl::WriterListener::WriterListener(NodeImpl* impl) : DdscWriterListener(impl) {}
      30                 :            : 
      31                 :            : // DdscSetterImpl
      32   [ +  -  +  - ]:         20 : DdscSetterImpl::DdscSetterImpl(const DdscConf& conf) : conf_(conf) {}
      33                 :            : 
      34                 :         19 : void DdscSetterImpl::init() {
      35         [ +  - ]:         19 :   participant_ = DdscFactory::create_participant(kPublisher | kSubscriber, conf_, get_all_properties());
      36                 :            : 
      37   [ +  -  +  - ]:         19 :   topic_ = DdscFactory::create_topic(kPublisher | kSubscriber, conf_, participant_.get());
      38                 :            : 
      39                 :         19 :   publisher_ = DdscFactory::create_publisher(kPublisher, conf_, participant_.get());
      40                 :            : 
      41   [ +  -  -  +  :         19 :   if VUNLIKELY (!participant_ || !topic_) {
                   -  + ]
      42   [ #  #  #  # ]:          0 :     VLOG_E("DdscSetterImpl::init(): participant/topic creation failed; setter left uninitialised.");
      43                 :            : 
      44                 :          0 :     return;
      45                 :            :   }
      46                 :            : 
      47         [ +  - ]:         19 :   listener_.emplace(this);
      48                 :            : 
      49                 :         19 :   writer_ = DdscFactory::create_datawriter(kSetter, conf_, publisher_.get(), topic_.get(), listener_->get_ptr());
      50                 :            : }
      51                 :            : 
      52                 :         19 : void DdscSetterImpl::deinit() {
      53                 :         19 :   detach();
      54                 :            : 
      55                 :         19 :   writer_.reset();
      56                 :         19 :   listener_.reset();
      57                 :         19 :   publisher_.reset();
      58                 :         19 :   topic_.reset();
      59                 :         19 :   participant_.reset();
      60                 :         19 : }
      61                 :            : 
      62                 :          0 : const Conf* DdscSetterImpl::get_conf() const { return &conf_; }
      63                 :            : 
      64                 :          2 : const AbstractNode* DdscSetterImpl::get_abstract_node() const { return this; }
      65                 :            : 
      66                 :          2 : Status::BasePtr DdscSetterImpl::get_status(Status::Type type) const {
      67         [ -  + ]:          2 :   if VUNLIKELY (!writer_) {
      68                 :          0 :     return std::make_shared<Status::Unknown>();
      69                 :            :   }
      70                 :            : 
      71                 :          2 :   return WriterListener::get_status(writer_->entity, type);
      72                 :            : }
      73                 :            : 
      74                 :          1 : std::any DdscSetterImpl::get_native_handle() const { return publisher_; }
      75                 :            : 
      76                 :         26 : void DdscSetterImpl::write(const Bytes& msg_data) {
      77                 :         52 :   DdscFactory::write_data(writer_->entity, msg_data, seq_.fetch_add(1, std::memory_order_relaxed));
      78                 :         26 : }
      79                 :            : 
      80                 :         19 : void DdscSetterImpl::sync(SyncCallback&& callback) { (void)callback; }
      81                 :            : 
      82                 :            : }  // namespace vlink

Generated by: LCOV version 1.14