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_publisher_impl.h" 25 : : 26 : : #include "./base/helpers.h" 27 : : 28 : : namespace vlink { 29 : : 30 : : // IntraPublisherImpl 31 [ + - ]: 155 : IntraPublisherImpl::IntraPublisherImpl(const IntraConf& conf) : conf_(conf) { 32 [ + + ]: 155 : if (conf.type == "direct") { 33 : 20 : type_ = IntraType::kDirect; 34 : : } 35 : 155 : } 36 : : 37 : 151 : void IntraPublisherImpl::init() { 38 [ + + + - : 151 : static auto& factory = IntraFactory::get(); + - - - ] 39 : : 40 : 151 : conf_.hash_code = Helpers::get_hash_code(conf_.event); 41 : : 42 [ + - ]: 151 : object_ = factory.get_object<Object>({kImplType, conf_.address, conf_.pipeline, type_, conf_.hash_code}); 43 : : 44 : 151 : object_->add_impl(this); 45 : : 46 [ + - + - ]: 475 : object_->register_sub_connect_callback(this, [this](bool) { PublisherImpl::update_subscribers(); }); 47 : : 48 : 151 : PublisherImpl::update_subscribers(); 49 : 151 : } 50 : : 51 : 151 : void IntraPublisherImpl::deinit() { object_->remove_impl(this); } 52 : : 53 : 0 : const Conf* IntraPublisherImpl::get_conf() const { return &conf_; } 54 : : 55 : 1 : const AbstractNode* IntraPublisherImpl::get_abstract_node() const { return object_.get(); } 56 : : 57 : 899 : bool IntraPublisherImpl::has_subscribers() const { 58 [ + + + + ]: 899 : return !object_->msg_map_is_empty() || !object_->intra_msg_map_is_empty(); 59 : : } 60 : : 61 : 527 : bool IntraPublisherImpl::write(const Bytes& msg_data) { return object_->publish(type_, conf_.hash_code, msg_data); } 62 : : 63 : 19 : bool IntraPublisherImpl::write(const IntraData& intra_data) { 64 : 19 : return object_->publish(type_, conf_.hash_code, intra_data); 65 : : } 66 : : 67 : : } // namespace vlink