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_setter_impl.h" 25 : : 26 : : #include "./base/helpers.h" 27 : : 28 : : namespace vlink { 29 : : 30 : : // IntraSetterImpl 31 [ + - ]: 9 : IntraSetterImpl::IntraSetterImpl(const IntraConf& conf) : conf_(conf) { 32 [ + + ]: 9 : if (conf.type == "direct") { 33 : 1 : type_ = IntraType::kDirect; 34 : : } 35 : 9 : } 36 : : 37 : 9 : void IntraSetterImpl::init() { 38 [ + + + - : 9 : static auto& factory = IntraFactory::get(); + - - - ] 39 : : 40 : 9 : conf_.hash_code = Helpers::get_hash_code(conf_.event); 41 : : 42 [ + - ]: 9 : object_ = factory.get_object<Object>({kImplType, conf_.address, conf_.pipeline, type_}); 43 : : 44 : 9 : object_->add_impl(this); 45 : 9 : } 46 : : 47 : 9 : void IntraSetterImpl::deinit() { object_->remove_impl(this); } 48 : : 49 : 0 : const Conf* IntraSetterImpl::get_conf() const { return &conf_; } 50 : : 51 : 1 : const AbstractNode* IntraSetterImpl::get_abstract_node() const { return object_.get(); } 52 : : 53 : 1 : bool IntraSetterImpl::attach(class MessageLoop*) { 54 [ + - + - ]: 2 : VLOG_W("Function [attach] is not supported."); 55 : 1 : return false; 56 : : } 57 : : 58 : 1 : bool IntraSetterImpl::detach() { 59 [ + - + - ]: 2 : VLOG_W("Function [detach] is not supported."); 60 : 1 : return false; 61 : : } 62 : : 63 : 17 : void IntraSetterImpl::write(const Bytes& value_data) { object_->publish(type_, conf_.hash_code, value_data); } 64 : : 65 : 9 : void IntraSetterImpl::sync(SyncCallback&& callback) { 66 [ + - + - ]: 9 : object_->register_sub_connect_callback(this, [callback = std::move(callback)](bool connected) mutable { 67 [ + + ]: 14 : if (connected) { 68 : 7 : callback(); 69 : : } 70 : 14 : }); 71 : 9 : } 72 : : 73 : : } // namespace vlink