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 "./dds_setter_impl.h" 25 : : 26 : : namespace vlink { 27 : : 28 : : // WriterListener 29 : 23 : DdsSetterImpl::WriterListener::WriterListener(NodeImpl* impl) : DdsWriterListener(impl) {} 30 : : 31 : : // DdsSetterImpl 32 [ + - + - ]: 24 : DdsSetterImpl::DdsSetterImpl(const DdsConf& conf) : conf_(conf) {} 33 : : 34 : 23 : void DdsSetterImpl::init() { 35 [ - + - - : 23 : if VUNLIKELY (is_cdr_type && is_security_type) { - + ] 36 [ # # # # ]: 0 : VLOG_F("Cdr type does not support security."); 37 : : } 38 : : 39 [ + - ]: 23 : participant_ = DdsFactory::create_participant(kPublisher | kSubscriber, conf_, get_all_properties()); 40 : : 41 [ + - ]: 23 : topic_ = DdsFactory::create_topic(kPublisher | kSubscriber, conf_, participant_.get(), is_cdr_type, {}, ser_type); 42 : : 43 : 23 : publisher_ = DdsFactory::create_publisher(kPublisher, conf_, participant_.get()); 44 : : 45 [ + - - + : 23 : if VUNLIKELY (!participant_ || !topic_) { - + ] 46 [ # # # # ]: 0 : VLOG_E("DdsSetterImpl::init(): participant/topic creation failed; setter left uninitialised."); 47 : : 48 : 0 : return; 49 : : } 50 : : 51 [ - + ]: 23 : if (is_cdr_type) { 52 : 0 : ser_type = topic_->get_type_name(); 53 : : } 54 : : 55 [ + - ]: 23 : listener_.emplace(this); 56 : : 57 : : writer_ = 58 : 23 : DdsFactory::create_datawriter(kSetter, conf_, publisher_.get(), topic_.get(), &listener_.value(), is_cdr_type); 59 : : } 60 : : 61 : 23 : void DdsSetterImpl::deinit() { 62 : 23 : detach(); 63 : : 64 : 23 : writer_.reset(); 65 : 23 : listener_.reset(); 66 : 23 : publisher_.reset(); 67 : 23 : topic_.reset(); 68 : 23 : participant_.reset(); 69 : 23 : } 70 : : 71 : 0 : const Conf* DdsSetterImpl::get_conf() const { return &conf_; } 72 : : 73 : 2 : const AbstractNode* DdsSetterImpl::get_abstract_node() const { return this; } 74 : : 75 : 2 : Status::BasePtr DdsSetterImpl::get_status(Status::Type type) const { 76 [ - + ]: 2 : if VUNLIKELY (!writer_) { 77 : 0 : return std::make_shared<Status::Unknown>(); 78 : : } 79 : : 80 : 2 : return WriterListener::get_status(writer_.get(), type); 81 : : } 82 : : 83 : 1 : std::any DdsSetterImpl::get_native_handle() const { return publisher_; } 84 : : 85 : 29 : void DdsSetterImpl::write(const Bytes& msg_data) { 86 [ - + ]: 29 : if (is_cdr_type) { 87 : 0 : DdsFactory::write_cdr_data(writer_.get(), msg_data); 88 : 0 : return; 89 : : } 90 : : 91 : 58 : DdsFactory::write_data(writer_.get(), msg_data, seq_.fetch_add(1, std::memory_order_relaxed)); 92 : : } 93 : : 94 : 23 : void DdsSetterImpl::sync(SyncCallback&& callback) { (void)callback; } 95 : : 96 : : } // namespace vlink