LCOV - code coverage report
Current view: top level - modules/shm - shm_getter_impl.cc (source / functions) Hit Total Coverage
Test: vlink Lines: 38 39 97.4 %
Date: 2026-09-30 18:30:16 Functions: 13 13 100.0 %
Branches: 18 28 64.3 %

           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 "./shm_getter_impl.h"
      25                 :            : 
      26                 :            : #include <utility>
      27                 :            : 
      28                 :            : #include "./base/helpers.h"
      29                 :            : 
      30                 :            : namespace vlink {
      31                 :            : 
      32                 :            : // ShmGetterImpl
      33         [ +  - ]:         18 : ShmGetterImpl::ShmGetterImpl(const ShmConf& conf) : conf_(conf) {}
      34                 :            : 
      35                 :         18 : void ShmGetterImpl::init() {
      36   [ +  +  +  -  :         18 :   static auto& factory = ShmFactory::get();
             +  -  -  - ]
      37                 :            : 
      38                 :         18 :   conf_.hash_code = Helpers::get_hash_code(conf_.event);
      39                 :            : 
      40         [ +  + ]:         18 :   if (conf_.history == 0) {
      41                 :          3 :     conf_.history = 1;
      42                 :            :   }
      43                 :            : 
      44         [ +  - ]:         36 :   object_ = factory.get_object<Object>(
      45         [ +  - ]:         36 :       {kImplType, conf_.address, conf_.domain, conf_.depth, conf_.history, conf_.wait, conf_.event, this});
      46                 :            : 
      47                 :         18 :   object_->add_impl(this);
      48                 :            : 
      49                 :         18 :   object_->set_latency_and_lost_enabled(is_latency_and_lost_enabled_.load(std::memory_order_acquire));
      50                 :         18 : }
      51                 :            : 
      52                 :         18 : void ShmGetterImpl::deinit() {
      53                 :         18 :   detach();
      54                 :            : 
      55         [ +  - ]:         18 :   if (object_) {
      56                 :         18 :     object_->remove_impl(this);
      57                 :            :   }
      58                 :         18 : }
      59                 :            : 
      60                 :          1 : bool ShmGetterImpl::suspend() { return object_->suspend(); }
      61                 :            : 
      62                 :          1 : bool ShmGetterImpl::resume() { return object_->resume(); }
      63                 :            : 
      64                 :          2 : bool ShmGetterImpl::is_suspend() const { return object_->is_suspend(); }
      65                 :            : 
      66                 :         19 : bool ShmGetterImpl::is_support_loan() const { return true; }
      67                 :            : 
      68                 :         56 : const Conf* ShmGetterImpl::get_conf() const { return &conf_; }
      69                 :            : 
      70                 :          2 : const AbstractNode* ShmGetterImpl::get_abstract_node() const { return object_.get(); }
      71                 :            : 
      72                 :         18 : bool ShmGetterImpl::listen(MsgCallback&& callback) {
      73                 :         18 :   object_->register_msg_callback(this, std::move(callback));
      74                 :            : 
      75                 :         18 :   object_->subscribe();
      76                 :            : 
      77                 :         18 :   return true;
      78                 :            : }
      79                 :            : 
      80                 :          2 : void ShmGetterImpl::set_latency_and_lost_enabled(bool enable) {
      81                 :          2 :   is_latency_and_lost_enabled_.store(enable, std::memory_order_release);
      82                 :            : 
      83         [ +  + ]:          2 :   if (object_) {
      84                 :          1 :     object_->set_latency_and_lost_enabled(enable);
      85                 :            :   }
      86                 :          2 : }
      87                 :            : 
      88                 :          3 : bool ShmGetterImpl::is_latency_and_lost_enabled() const {
      89         [ +  + ]:          3 :   if (object_) {
      90                 :          2 :     return object_->is_latency_and_lost_enabled();
      91                 :            :   }
      92                 :            : 
      93                 :          1 :   return is_latency_and_lost_enabled_.load(std::memory_order_acquire);
      94                 :            : }
      95                 :            : 
      96                 :          3 : SampleLostInfo ShmGetterImpl::get_lost() const {
      97   [ +  +  -  +  :          3 :   if (object_ && object_->is_latency_and_lost_enabled()) {
                   -  + ]
      98                 :          0 :     return SampleLostInfo{object_->get_calculate_sample().get_total(), object_->get_calculate_sample().get_lost()};
      99                 :            :   }
     100                 :            : 
     101                 :          3 :   return SampleLostInfo();
     102                 :            : }
     103                 :            : 
     104                 :            : }  // namespace vlink

Generated by: LCOV version 1.14