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 "./ddsc_proxy.hpp"
25 : :
26 : : #include <string>
27 : :
28 : : #include "./base/logger.h"
29 : : #include "./builtin/BuiltInRaw.h"
30 : :
31 : : namespace ddsc {
32 : :
33 : : // DomainParticipant
34 : 88 : DomainParticipant::DomainParticipant(int32_t domain, const dds_qos_t* qos) {
35 : 88 : entity = dds_create_participant(domain, qos, nullptr);
36 : :
37 [ - + ]: 88 : if VUNLIKELY (entity <= 0) {
38 [ # # # # ]: 0 : CLOG_E("dds_create_participant: %s.", dds_strretcode(-entity));
39 : : }
40 : 88 : }
41 : :
42 : 176 : DomainParticipant::~DomainParticipant() {
43 [ - + ]: 88 : if VUNLIKELY (entity <= 0) {
44 : 0 : return;
45 : : }
46 : :
47 : 88 : dds_delete(entity);
48 : :
49 : 88 : entity = 0;
50 : 88 : }
51 : :
52 : : // Topic
53 : 129 : Topic::Topic(dds_entity_t part, const std::string& topic, const std::string& type_name) {
54 : : (void)type_name;
55 : :
56 : 129 : entity = dds_create_topic(part, &vlink_BuiltInRaw_desc, topic.c_str(), nullptr, nullptr);
57 : :
58 [ - + ]: 129 : if VUNLIKELY (entity <= 0) {
59 [ # # # # ]: 0 : CLOG_E("dds_create_topic: %s.", dds_strretcode(-entity));
60 : : }
61 : 129 : }
62 : :
63 : 258 : Topic::~Topic() {
64 [ - + ]: 129 : if VUNLIKELY (entity <= 0) {
65 : 0 : return;
66 : : }
67 : :
68 : 129 : dds_delete(entity);
69 : :
70 : 129 : entity = 0;
71 : 129 : }
72 : :
73 : : // Publisher
74 : 101 : Publisher::Publisher(dds_entity_t part) {
75 : 101 : entity = dds_create_publisher(part, nullptr, nullptr);
76 : :
77 [ - + ]: 101 : if VUNLIKELY (entity <= 0) {
78 [ # # # # ]: 0 : CLOG_E("dds_create_publisher: %s.", dds_strretcode(-entity));
79 : : }
80 : 101 : }
81 : :
82 : 202 : Publisher::~Publisher() {
83 [ - + ]: 101 : if VUNLIKELY (entity <= 0) {
84 : 0 : return;
85 : : }
86 : :
87 : 101 : dds_delete(entity);
88 : :
89 : 101 : entity = 0;
90 : 101 : }
91 : :
92 : : // Subscriber
93 : 103 : Subscriber::Subscriber(dds_entity_t part) {
94 : 103 : entity = dds_create_subscriber(part, nullptr, nullptr);
95 : :
96 [ - + ]: 103 : if VUNLIKELY (entity <= 0) {
97 [ # # # # ]: 0 : CLOG_E("dds_create_subscriber: %s.", dds_strretcode(-entity));
98 : : }
99 : 103 : }
100 : :
101 : 206 : Subscriber::~Subscriber() {
102 [ - + ]: 103 : if VUNLIKELY (entity <= 0) {
103 : 0 : return;
104 : : }
105 : :
106 : 103 : dds_delete(entity);
107 : :
108 : 103 : entity = 0;
109 : 103 : }
110 : :
111 : : // DataWriter
112 : 116 : DataWriter::DataWriter(dds_entity_t pub, dds_entity_t topic, const dds_qos_t* qos, const dds_listener_t* listener) {
113 : 116 : entity = dds_create_writer(pub, topic, qos, listener);
114 : :
115 [ - + ]: 116 : if VUNLIKELY (entity <= 0) {
116 [ # # # # ]: 0 : CLOG_E("dds_create_writer: %s.", dds_strretcode(-entity));
117 : : }
118 : 116 : }
119 : :
120 : 232 : DataWriter::~DataWriter() {
121 [ - + ]: 116 : if VUNLIKELY (entity <= 0) {
122 : 0 : return;
123 : : }
124 : :
125 : 116 : dds_set_listener(entity, nullptr);
126 : 116 : dds_delete(entity);
127 : :
128 : 116 : entity = 0;
129 : 116 : }
130 : :
131 : : // DataReader
132 : 109 : DataReader::DataReader(dds_entity_t sub, dds_entity_t topic, const dds_qos_t* qos, const dds_listener_t* listener) {
133 : 109 : entity = dds_create_reader(sub, topic, qos, listener);
134 : :
135 [ - + ]: 109 : if VUNLIKELY (entity <= 0) {
136 [ # # # # ]: 0 : CLOG_E("dds_create_reader: %s.", dds_strretcode(-entity));
137 : : }
138 : 109 : }
139 : :
140 : 218 : DataReader::~DataReader() {
141 [ - + ]: 109 : if VUNLIKELY (entity <= 0) {
142 : 0 : return;
143 : : }
144 : :
145 : 109 : dds_set_listener(entity, nullptr);
146 : 109 : dds_delete(entity);
147 : :
148 : 109 : entity = 0;
149 : 109 : }
150 : :
151 : : } // namespace ddsc
|