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