|
18 | 18 |
|
19 | 19 | #include <fastcdr/FastBuffer.h> |
20 | 20 | #include <fastcdr/Cdr.h> |
21 | | -#include <fastdds/dds/xtypes/dynamic_types/DynamicPubSubType.hpp> |
22 | | -#include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilderFactory.hpp> |
23 | | -#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp> |
24 | 21 |
|
25 | 22 | #include <ddspipe_participants/types/dds/TopicDataType.hpp> |
26 | 23 |
|
@@ -49,16 +46,6 @@ TopicDataType::TopicDataType( |
49 | 46 |
|
50 | 47 | // Set Type Identifiers |
51 | 48 | type_identifiers_ = type_identifiers; |
52 | | - |
53 | | - // Eagerly try to build the dynamic type for keyed topics |
54 | | - // This may fail transiently if dependency TypeObjects have not been received yet |
55 | | - // Keep key capability enabled and retry later on demand |
56 | | - if (keyed_ && !initialize_dynamic_type_()) |
57 | | - { |
58 | | - EPROSIMA_LOG_WARNING(DDSPIPE_DDS_TYPESUPPORT, |
59 | | - "Cannot build dynamic type for keyed topic " |
60 | | - << type_name_ << " yet. Will retry when needed."); |
61 | | - } |
62 | 49 | } |
63 | 50 |
|
64 | 51 | TopicDataType::~TopicDataType() |
@@ -118,142 +105,30 @@ uint32_t TopicDataType::calculate_serialized_size( |
118 | 105 | bool TopicDataType::compute_key( |
119 | 106 | fastdds::rtps::SerializedPayload_t& payload, |
120 | 107 | fastdds::rtps::InstanceHandle_t& handle, |
121 | | - bool force_md5) |
| 108 | + bool /* = false */) |
122 | 109 | { |
123 | | - if (!is_compute_key_provided) |
124 | | - { |
125 | | - return false; |
126 | | - } |
127 | | - |
128 | | - if (!initialize_dynamic_type_()) |
129 | | - { |
130 | | - // Dynamic type is not available yet (or permanently failed due to structural errors) |
131 | | - // Keep capability enabled so future calls can retry when dependencies arrive |
132 | | - EPROSIMA_LOG_WARNING(DDSPIPE_DDS_TYPESUPPORT, |
133 | | - "Cannot compute key for type " |
134 | | - << type_name_ << ": dynamic type unavailable."); |
135 | | - return false; |
136 | | - } |
137 | | - |
138 | | - fastdds::dds::DynamicPubSubType pub_sub_type(dynamic_type_); |
139 | | - return pub_sub_type.compute_key(payload, handle, force_md5); |
| 110 | + // NOTE: This method returns false because Fast DDS always sends the KEY_HASH in inline QoS. |
| 111 | + // As a result, the reader will never call this method when communicating with a Fast DDS writer. |
| 112 | + // This would only be needed if receiving data from another DDS vendor that omits the KEY_HASH. |
| 113 | + // Workaround in that case (different DDS vendor that omits KEY_HASH): set expects_inline_qos_ to |
| 114 | + // true in DataReaderQos |
| 115 | + return false; |
140 | 116 | } |
141 | 117 |
|
142 | 118 | bool TopicDataType::compute_key( |
143 | 119 | const void* const data, |
144 | 120 | fastdds::rtps::InstanceHandle_t& handle, |
145 | | - bool force_md5) |
| 121 | + bool /* = false */) |
146 | 122 | { |
147 | 123 | if (is_compute_key_provided) |
148 | 124 | { |
| 125 | + // Load the instanceHandle from data into handle |
149 | 126 | const auto p = static_cast<const DataType*>(data); |
150 | | - |
151 | | - // Fast path: key already available in routing data. |
152 | | - if (p->instanceHandle.isDefined()) |
153 | | - { |
154 | | - handle = p->instanceHandle; |
155 | | - return true; |
156 | | - } |
157 | | - |
158 | | - // Fallback path: compute key from serialized payload when handle is not present. |
159 | | - if (p->payload.data != nullptr && p->payload.length > 0) |
160 | | - { |
161 | | - fastdds::rtps::SerializedPayload_t payload(p->payload.length); |
162 | | - if (!payload.copy(&p->payload)) |
163 | | - { |
164 | | - return false; |
165 | | - } |
166 | | - |
167 | | - return compute_key(payload, handle, force_md5); |
168 | | - } |
169 | | - |
170 | | - return false; |
171 | | - } |
172 | | - |
173 | | - return false; |
174 | | -} |
175 | | - |
176 | | -bool TopicDataType::initialize_dynamic_type_() const |
177 | | -{ |
178 | | - std::lock_guard<std::mutex> lock(dynamic_type_mtx_); |
179 | | - |
180 | | - // Another thread may have initialized or permanently failed initialization |
181 | | - // before this thread acquired the mutex |
182 | | - if (dynamic_type_) |
183 | | - { |
| 127 | + handle = p->instanceHandle; |
184 | 128 | return true; |
185 | 129 | } |
186 | 130 |
|
187 | | - if (dynamic_type_init_failed_) |
188 | | - { |
189 | | - return false; |
190 | | - } |
191 | | - |
192 | | - fastdds::dds::xtypes::TypeInformation type_information; |
193 | | - |
194 | | - auto& registry = fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry(); |
195 | | - |
196 | | - auto try_get_type_information = [&](const fastdds::dds::xtypes::TypeIdentifierPair& identifiers) -> bool |
197 | | - { |
198 | | - return fastdds::dds::RETCODE_OK == registry.get_type_information(identifiers, type_information); |
199 | | - }; |
200 | | - |
201 | | - if (!try_get_type_information(type_identifiers_)) |
202 | | - { |
203 | | - fastdds::dds::xtypes::TypeIdentifierPair complete_only; |
204 | | - complete_only.type_identifier1(type_identifiers_.type_identifier1()); |
205 | | - |
206 | | - if (!try_get_type_information(complete_only)) |
207 | | - { |
208 | | - fastdds::dds::xtypes::TypeIdentifierPair minimal_only; |
209 | | - minimal_only.type_identifier2(type_identifiers_.type_identifier2()); |
210 | | - |
211 | | - if (!try_get_type_information(minimal_only)) |
212 | | - { |
213 | | - // Missing type information may be transient while dependency types are still arriving |
214 | | - return false; |
215 | | - } |
216 | | - } |
217 | | - } |
218 | | - |
219 | | - const auto complete_type_identifier = type_information.complete().typeid_with_size().type_id(); |
220 | | - fastdds::dds::xtypes::TypeObject type_object; |
221 | | - if (fastdds::dds::RETCODE_OK != registry.get_type_object(complete_type_identifier, type_object)) |
222 | | - { |
223 | | - // Missing type object may be transient while dependency types are still arriving |
224 | | - return false; |
225 | | - } |
226 | | - |
227 | | - // Pre-check consistency before calling create_type_w_type_object |
228 | | - // If dependencies are missing from the registry, skip type creation entirely |
229 | | - // to avoid noisy error logs from internal FastDDS type creation functions |
230 | | - try |
231 | | - { |
232 | | - fastdds::dds::xtypes::TypeObjectUtils::type_object_consistency(type_object); |
233 | | - } |
234 | | - catch (const fastdds::dds::xtypes::InvalidArgumentError&) |
235 | | - { |
236 | | - EPROSIMA_LOG_WARNING(DDSPIPE_DDS_TYPESUPPORT, |
237 | | - "TypeObject for " |
238 | | - << type_name_ << " has unresolvable dependencies. " |
239 | | - << "Skipping dynamic type creation for now."); |
240 | | - return false; |
241 | | - } |
242 | | - |
243 | | - auto dyn_type_builder = fastdds::dds::DynamicTypeBuilderFactory::get_instance()->create_type_w_type_object( |
244 | | - type_object); |
245 | | - if (!dyn_type_builder) |
246 | | - { |
247 | | - dynamic_type_init_failed_ = true; |
248 | | - return false; |
249 | | - } |
250 | | - |
251 | | - dynamic_type_ = dyn_type_builder->build(); |
252 | | - if (!dynamic_type_) |
253 | | - { |
254 | | - dynamic_type_init_failed_ = true; |
255 | | - } |
256 | | - return dynamic_type_ != nullptr; |
| 131 | + return false; |
257 | 132 | } |
258 | 133 |
|
259 | 134 | void* TopicDataType::create_data() |
|
0 commit comments