LCOV - code coverage report
Current view: top level - modules/shm - shm_setter_impl.cc (source / functions) Hit Total Coverage
Test: vlink Lines: 19 20 95.0 %
Date: 2026-06-27 19:56:04 Functions: 9 10 90.0 %
Branches: 6 12 50.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                 :            : #include "./shm_setter_impl.h"
      25                 :            : 
      26                 :            : #include "./base/helpers.h"
      27                 :            : 
      28                 :            : namespace vlink {
      29                 :            : 
      30                 :            : // ShmSetterImpl
      31         [ +  - ]:         12 : ShmSetterImpl::ShmSetterImpl(const ShmConf& conf) : conf_(conf) {}
      32                 :            : 
      33                 :         12 : void ShmSetterImpl::init() {
      34   [ +  +  +  -  :         12 :   static auto& factory = ShmFactory::get();
             +  -  -  - ]
      35                 :            : 
      36                 :         12 :   conf_.hash_code = Helpers::get_hash_code(conf_.event);
      37                 :            : 
      38                 :            :   object_ =
      39         [ +  - ]:         12 :       factory.get_object<Object>({kImplType, conf_.address, conf_.domain, conf_.depth, conf_.history, conf_.wait});
      40                 :            : 
      41                 :         12 :   object_->add_impl(this);
      42                 :         12 : }
      43                 :            : 
      44                 :         12 : void ShmSetterImpl::deinit() {
      45                 :         12 :   detach();
      46                 :            : 
      47                 :         12 :   object_->remove_impl(this);
      48                 :         12 : }
      49                 :            : 
      50                 :         13 : bool ShmSetterImpl::is_support_loan() const { return true; }
      51                 :            : 
      52                 :         64 : Bytes ShmSetterImpl::loan(int64_t size) { return object_->loan(static_cast<uint64_t>(conf_.hash_code), size); }
      53                 :            : 
      54                 :          1 : bool ShmSetterImpl::return_loan(const Bytes& bytes) { return object_->release(bytes); }
      55                 :            : 
      56                 :          0 : const Conf* ShmSetterImpl::get_conf() const { return &conf_; }
      57                 :            : 
      58                 :          2 : const AbstractNode* ShmSetterImpl::get_abstract_node() const { return object_.get(); }
      59                 :            : 
      60                 :         70 : void ShmSetterImpl::write(const Bytes& msg_data) { object_->publish(static_cast<uint64_t>(conf_.hash_code), msg_data); }
      61                 :            : 
      62                 :         12 : void ShmSetterImpl::sync(SyncCallback&& callback) {
      63                 :            :   // object_->register_sub_connect_callback(this, [callback = std::move(callback)](bool connected) {
      64                 :            :   //   if (connected) {
      65                 :            :   //     callback();
      66                 :            :   //   }
      67                 :            :   // });
      68                 :            : 
      69                 :            :   (void)callback;
      70                 :            : 
      71                 :         12 :   object_->enable_detect_timer();
      72                 :         12 : }
      73                 :            : 
      74                 :            : }  // namespace vlink

Generated by: LCOV version 1.14