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 [ + - ]: 14 : ShmSetterImpl::ShmSetterImpl(const ShmConf& conf) : conf_(conf) {} 32 : : 33 : 14 : void ShmSetterImpl::init() { 34 [ + + + - : 14 : static auto& factory = ShmFactory::get(); + - - - ] 35 : : 36 : 14 : conf_.hash_code = Helpers::get_hash_code(conf_.event); 37 : : 38 [ + + ]: 14 : if (conf_.history == 0) { 39 : 2 : conf_.history = 1; 40 : : } 41 : : 42 [ + - ]: 28 : object_ = factory.get_object<Object>( 43 [ + - ]: 28 : {kImplType, conf_.address, conf_.domain, conf_.depth, conf_.history, conf_.wait, conf_.event, nullptr}); 44 : : 45 : 14 : object_->add_impl(this); 46 : 14 : } 47 : : 48 : 14 : void ShmSetterImpl::deinit() { 49 : 14 : detach(); 50 : : 51 : 14 : object_->remove_impl(this); 52 : 14 : } 53 : : 54 : 15 : bool ShmSetterImpl::is_support_loan() const { return true; } 55 : : 56 : 1 : Bytes ShmSetterImpl::loan(int64_t size) { return object_->loan(static_cast<uint64_t>(conf_.hash_code), size); } 57 : : 58 : 1 : bool ShmSetterImpl::return_loan(const Bytes& bytes) { return object_->release(bytes); } 59 : : 60 : 0 : const Conf* ShmSetterImpl::get_conf() const { return &conf_; } 61 : : 62 : 2 : const AbstractNode* ShmSetterImpl::get_abstract_node() const { return object_.get(); } 63 : : 64 : 165 : void ShmSetterImpl::write(const Bytes& msg_data) { object_->publish(static_cast<uint64_t>(conf_.hash_code), msg_data); } 65 : : 66 : 14 : void ShmSetterImpl::sync(SyncCallback&& callback) { callback(); } 67 : : 68 : : } // namespace vlink