LCOV - code coverage report
Current view: top level - modules/intra - intra_subscriber_impl.cc (source / functions) Hit Total Coverage
Test: vlink Lines: 44 44 100.0 %
Date: 2026-07-26 14:05:51 Functions: 17 17 100.0 %
Branches: 33 54 61.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 "./intra_subscriber_impl.h"
      25                 :            : 
      26                 :            : #include <utility>
      27                 :            : 
      28                 :            : #include "./base/helpers.h"
      29                 :            : 
      30                 :            : namespace vlink {
      31                 :            : 
      32                 :            : // IntraSubscriberImpl
      33         [ +  - ]:        165 : IntraSubscriberImpl::IntraSubscriberImpl(const IntraConf& conf) : conf_(conf) {
      34         [ +  + ]:        165 :   if (conf.type == "direct") {
      35                 :         11 :     type_ = IntraType::kDirect;
      36                 :            :   }
      37                 :        165 : }
      38                 :            : 
      39                 :        162 : void IntraSubscriberImpl::init() {
      40   [ +  +  +  -  :        162 :   static auto& factory = IntraFactory::get();
             +  -  -  - ]
      41                 :            : 
      42                 :        162 :   conf_.hash_code = Helpers::get_hash_code(conf_.event);
      43                 :            : 
      44         [ +  - ]:        162 :   object_ = factory.get_object<Object>({kImplType, conf_.address, conf_.pipeline, type_, conf_.hash_code});
      45                 :        162 :   object_->add_impl(this);
      46                 :        162 : }
      47                 :            : 
      48                 :        162 : void IntraSubscriberImpl::deinit() {
      49                 :        162 :   bool was_listened = is_listened;
      50                 :            : 
      51                 :        162 :   object_->remove_impl(this);
      52                 :        162 :   is_listened = false;
      53                 :            : 
      54   [ +  +  +  +  :        162 :   if (was_listened && object_->msg_map_is_empty() && object_->intra_msg_map_is_empty()) {
             +  -  +  + ]
      55   [ +  -  +  - ]:        302 :     object_->traverse_sub_connect_callback([](NodeImpl*, const auto& callback) { callback(false); });
      56                 :            :   }
      57                 :        162 : }
      58                 :            : 
      59                 :          2 : bool IntraSubscriberImpl::suspend() {
      60                 :          2 :   has_suspend = true;
      61                 :            : 
      62                 :          2 :   return true;
      63                 :            : }
      64                 :            : 
      65                 :          2 : bool IntraSubscriberImpl::resume() {
      66                 :          2 :   has_suspend = false;
      67                 :            : 
      68                 :          2 :   return true;
      69                 :            : }
      70                 :            : 
      71                 :          4 : bool IntraSubscriberImpl::is_suspend() const { return has_suspend; }
      72                 :            : 
      73                 :        566 : const Conf* IntraSubscriberImpl::get_conf() const { return &conf_; }
      74                 :            : 
      75                 :          1 : const AbstractNode* IntraSubscriberImpl::get_abstract_node() const { return object_.get(); }
      76                 :            : 
      77                 :          1 : bool IntraSubscriberImpl::attach(class MessageLoop*) {
      78   [ +  -  +  - ]:          2 :   VLOG_W("Function [attach] is not supported.");
      79                 :          1 :   return false;
      80                 :            : }
      81                 :            : 
      82                 :          1 : bool IntraSubscriberImpl::detach() {
      83   [ +  -  +  - ]:          2 :   VLOG_W("Function [detach] is not supported.");
      84                 :          1 :   return false;
      85                 :            : }
      86                 :            : 
      87                 :        152 : bool IntraSubscriberImpl::listen(MsgCallback&& callback) {
      88   [ +  +  +  - ]:        152 :   const bool was_empty = object_->msg_map_is_empty() && object_->intra_msg_map_is_empty();
      89                 :            : 
      90                 :        152 :   object_->register_msg_callback(this, std::move(callback));
      91                 :            : 
      92         [ +  + ]:        152 :   if VLIKELY (was_empty) {
      93   [ +  -  +  - ]:        286 :     object_->traverse_sub_connect_callback([](NodeImpl*, const auto& target_callback) { target_callback(true); });
      94                 :            :   }
      95                 :            : 
      96                 :        152 :   return true;
      97                 :            : }
      98                 :            : 
      99                 :          8 : bool IntraSubscriberImpl::listen(IntraMsgCallback&& callback) {
     100   [ +  -  +  - ]:          8 :   const bool was_empty = object_->msg_map_is_empty() && object_->intra_msg_map_is_empty();
     101                 :            : 
     102                 :          8 :   object_->register_intra_msg_callback(this, std::move(callback));
     103                 :            : 
     104         [ +  - ]:          8 :   if VLIKELY (was_empty) {
     105   [ +  -  +  - ]:         16 :     object_->traverse_sub_connect_callback([](NodeImpl*, const auto& target_callback) { target_callback(true); });
     106                 :            :   }
     107                 :            : 
     108                 :          8 :   return true;
     109                 :            : }
     110                 :            : 
     111                 :            : }  // namespace vlink

Generated by: LCOV version 1.14