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 [ + - ]: 130 : IntraPublisherImpl::IntraPublisherImpl(const IntraConf& conf) : conf_(conf) { 32 [ + + ]: 130 : if (conf.type == "direct") { 33 : 7 : type_ = IntraType::kDirect; 34 : : } 35 : 130 : } 36 : : 37 : 123 : void IntraPublisherImpl::init() { 38 [ + + + - : 123 : static auto& factory = IntraFactory::get(); + - - - ] 39 : : 40 : 123 : conf_.hash_code = Helpers::get_hash_code(conf_.event); 41 : : 42 [ + - ]: 123 : object_ = factory.get_object<Object>({kImplType, conf_.address, conf_.pipeline, type_}); 43 : : 44 : 123 : object_->add_impl(this); 45 : : 46 [ + - + - ]: 405 : object_->register_sub_connect_callback(this, [this](bool) { PublisherImpl::update_subscribers(); }); 47 : : 48 : 123 : PublisherImpl::update_subscribers(); 49 : 123 : } 50 : : 51 : 123 : 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 : 1 : bool IntraPublisherImpl::attach(class MessageLoop*) { 58 [ + - + - ]: 2 : VLOG_W("Function [attach] is not supported."); 59 : 1 : return false; 60 : : } 61 : : 62 : 1 : bool IntraPublisherImpl::detach() { 63 [ + - + - ]: 2 : VLOG_W("Function [detach] is not supported."); 64 : 1 : return false; 65 : : } 66 : : 67 : 588 : bool IntraPublisherImpl::has_subscribers() const { 68 [ + + + + ]: 588 : return !object_->msg_map_is_empty() || !object_->intra_msg_map_is_empty(); 69 : : } 70 : : 71 : 306 : bool IntraPublisherImpl::write(const Bytes& msg_data) { return object_->publish(type_, conf_.hash_code, msg_data); } 72 : : 73 : 18 : bool IntraPublisherImpl::write(const IntraData& intra_data) { 74 : 18 : return object_->publish(type_, conf_.hash_code, intra_data); 75 : : } 76 : : 77 : : } // namespace vlink