Commit | Line | Data |
---|---|---|
af38ae4f PP |
1 | /* |
2 | * Copyright (c) 2023 Simon Marchi <simon.marchi@efficios.com> | |
3 | * Copyright (c) 2023 Philippe Proulx <pproulx@efficios.com> | |
4 | * | |
5 | * SPDX-License-Identifier: MIT | |
6 | */ | |
7 | ||
8 | #ifndef BABELTRACE_CPP_COMMON_BT2_PLUGIN_DEV_HPP | |
9 | #define BABELTRACE_CPP_COMMON_BT2_PLUGIN_DEV_HPP | |
10 | ||
11 | #include <cstdint> | |
12 | ||
13 | #include <glib.h> | |
14 | ||
15 | #include <babeltrace2/babeltrace.h> | |
16 | ||
e7f0f07b | 17 | #include "cpp-common/bt2c/c-string-view.hpp" |
af38ae4f PP |
18 | #include "cpp-common/bt2c/logging.hpp" |
19 | #include "cpp-common/vendor/fmt/core.h" | |
20 | ||
21 | #include "exc.hpp" | |
22 | #include "wrap.hpp" | |
23 | ||
24 | namespace bt2 { | |
25 | namespace internal { | |
26 | ||
27 | constexpr const char *unhandledExcLogStr() noexcept | |
28 | { | |
29 | return "Unhandled exception."; | |
30 | } | |
31 | ||
32 | constexpr const char *unhandledExcLogTag() noexcept | |
33 | { | |
34 | return "PLUGIN-DEV-HPP"; | |
35 | } | |
36 | ||
37 | /* | |
38 | * Base class of any component class bridge. | |
39 | * | |
40 | * `UserCompClsT` is the actual C++ user component class and `LibTypesT` | |
41 | * is a structure offering the following specific library types: | |
42 | * | |
43 | * `SelfCompCls`: | |
44 | * Self component class. | |
45 | * | |
46 | * `SelfComp`: | |
47 | * Self component. | |
48 | * | |
49 | * `SelfCompCfg`: | |
50 | * Self component configuration. | |
51 | */ | |
52 | template <typename UserCompClsT, typename LibTypesT> | |
53 | class CompClsBridge | |
54 | { | |
55 | private: | |
56 | using _LibSelfCompPtr = typename LibTypesT::SelfComp *; | |
57 | ||
58 | public: | |
59 | static UserCompClsT& userCompFromLibSelfCompPtr(const _LibSelfCompPtr libSelfCompPtr) noexcept | |
60 | { | |
61 | return wrap(libSelfCompPtr).template data<UserCompClsT>(); | |
62 | } | |
63 | ||
64 | static bt_component_class_initialize_method_status init(const _LibSelfCompPtr libSelfCompPtr, | |
65 | typename LibTypesT::SelfCompCfg *, | |
66 | const bt_value * const libParamsPtr, | |
67 | void *) noexcept | |
68 | { | |
69 | const auto selfComp = wrap(libSelfCompPtr); | |
70 | ||
71 | try { | |
72 | const auto comp = new UserCompClsT {selfComp, wrap(libParamsPtr).asMap()}; | |
73 | ||
74 | selfComp.data(*comp); | |
75 | } catch (const std::bad_alloc&) { | |
76 | return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; | |
77 | } catch (const Error&) { | |
78 | return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; | |
79 | } catch (...) { | |
80 | BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING, static_cast<int>(selfComp.loggingLevel()), | |
81 | unhandledExcLogTag(), unhandledExcLogStr()); | |
82 | return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; | |
83 | } | |
84 | ||
85 | return BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; | |
86 | } | |
87 | ||
88 | static void finalize(const _LibSelfCompPtr libSelfCompPtr) noexcept | |
89 | { | |
90 | delete &userCompFromLibSelfCompPtr(libSelfCompPtr); | |
91 | } | |
92 | ||
93 | static bt_component_class_get_supported_mip_versions_method_status | |
94 | getSupportedMipVersions(typename LibTypesT::SelfCompCls * const libSelfCompClsPtr, | |
95 | const bt_value * const libParamsPtr, void *, | |
96 | const bt_logging_level logLevel, | |
97 | bt_integer_range_set_unsigned * const libSupportedVersionsPtr) noexcept | |
98 | { | |
99 | try { | |
100 | UserCompClsT::getSupportedMipVersions(wrap(libSelfCompClsPtr), wrap(libParamsPtr), | |
101 | static_cast<LoggingLevel>(logLevel), | |
102 | wrap(libSupportedVersionsPtr)); | |
103 | return BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_OK; | |
104 | } catch (const std::bad_alloc&) { | |
105 | return BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_MEMORY_ERROR; | |
106 | } catch (const Error&) { | |
107 | return BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_ERROR; | |
108 | } catch (...) { | |
109 | BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING, static_cast<int>(logLevel), unhandledExcLogTag(), | |
110 | unhandledExcLogStr()); | |
111 | return BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_ERROR; | |
112 | } | |
113 | } | |
114 | ||
115 | static bt_component_class_query_method_status | |
116 | query(typename LibTypesT::SelfCompCls * const libSelfCompClsPtr, | |
117 | bt_private_query_executor * const libPrivQueryExecPtr, const char * const object, | |
118 | const bt_value * const libParamsPtr, void *, | |
119 | const bt_value ** const libResultPtr) noexcept | |
120 | { | |
121 | const auto privQueryExec = wrap(libPrivQueryExecPtr); | |
122 | ||
123 | try { | |
124 | auto result = UserCompClsT::query(wrap(libSelfCompClsPtr), privQueryExec, object, | |
125 | wrap(libParamsPtr)); | |
126 | ||
127 | *libResultPtr = result.release().libObjPtr(); | |
128 | return BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK; | |
129 | } catch (const TryAgain&) { | |
130 | return BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_AGAIN; | |
131 | } catch (const UnknownObject&) { | |
132 | return BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_UNKNOWN_OBJECT; | |
133 | } catch (const std::bad_alloc&) { | |
134 | return BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR; | |
135 | } catch (const Error&) { | |
136 | return BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; | |
137 | } catch (...) { | |
138 | BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING, static_cast<int>(privQueryExec.loggingLevel()), | |
139 | unhandledExcLogTag(), unhandledExcLogStr()); | |
140 | return BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR; | |
141 | } | |
142 | } | |
143 | }; | |
144 | ||
145 | template <typename SpecCompClsBridgeT, typename LibTypesT> | |
146 | struct CompClsBridgeWithInputPorts | |
147 | { | |
148 | static bt_component_class_port_connected_method_status | |
149 | inputPortConnected(typename LibTypesT::SelfComp * const libSelfCompPtr, | |
150 | bt_self_component_port_input * const libSelfCompPortPtr, | |
151 | const bt_port_output * const libOtherPortPtr) noexcept | |
152 | { | |
153 | try { | |
154 | SpecCompClsBridgeT::userCompFromLibSelfCompPtr(libSelfCompPtr) | |
155 | .inputPortConnected(wrap(libSelfCompPortPtr), wrap(libOtherPortPtr)); | |
156 | } catch (const std::bad_alloc&) { | |
157 | return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_MEMORY_ERROR; | |
158 | } catch (const Error&) { | |
159 | return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_ERROR; | |
160 | } catch (...) { | |
161 | BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING, | |
162 | static_cast<int>(wrap(libSelfCompPtr).loggingLevel()), | |
163 | unhandledExcLogTag(), unhandledExcLogStr()); | |
164 | return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_ERROR; | |
165 | } | |
166 | ||
167 | return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_OK; | |
168 | } | |
169 | }; | |
170 | ||
171 | template <typename SpecCompClsBridgeT, typename LibTypesT> | |
172 | struct CompClsBridgeWithOutputPorts | |
173 | { | |
174 | static bt_component_class_port_connected_method_status | |
175 | outputPortConnected(typename LibTypesT::SelfComp * const libSelfCompPtr, | |
176 | bt_self_component_port_output * const libSelfCompPortPtr, | |
177 | const bt_port_input * const libOtherPortPtr) noexcept | |
178 | { | |
179 | try { | |
180 | SpecCompClsBridgeT::userCompFromLibSelfCompPtr(libSelfCompPtr) | |
181 | .outputPortConnected(wrap(libSelfCompPortPtr), wrap(libOtherPortPtr)); | |
182 | } catch (const std::bad_alloc&) { | |
183 | return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_MEMORY_ERROR; | |
184 | } catch (const Error&) { | |
185 | return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_ERROR; | |
186 | } catch (...) { | |
187 | BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING, | |
188 | static_cast<int>(wrap(libSelfCompPtr).loggingLevel()), | |
189 | unhandledExcLogTag(), unhandledExcLogStr()); | |
190 | return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_ERROR; | |
191 | } | |
192 | ||
193 | return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_OK; | |
194 | } | |
195 | }; | |
196 | ||
197 | struct SrcCompClsLibTypes final | |
198 | { | |
199 | using SelfCompCls = bt_self_component_class_source; | |
200 | using SelfComp = bt_self_component_source; | |
201 | using SelfCompCfg = bt_self_component_source_configuration; | |
202 | }; | |
203 | ||
204 | template <typename UserCompClsT> | |
205 | class SrcCompClsBridge final : | |
206 | public CompClsBridge<UserCompClsT, SrcCompClsLibTypes>, | |
207 | public CompClsBridgeWithOutputPorts<SrcCompClsBridge<UserCompClsT>, SrcCompClsLibTypes> | |
208 | { | |
209 | }; | |
210 | ||
211 | struct FltCompClsLibTypes final | |
212 | { | |
213 | using SelfCompCls = bt_self_component_class_filter; | |
214 | using SelfComp = bt_self_component_filter; | |
215 | using SelfCompCfg = bt_self_component_filter_configuration; | |
216 | }; | |
217 | ||
218 | template <typename UserCompClsT> | |
219 | class FltCompClsBridge final : | |
220 | public CompClsBridge<UserCompClsT, FltCompClsLibTypes>, | |
221 | public CompClsBridgeWithInputPorts<FltCompClsBridge<UserCompClsT>, FltCompClsLibTypes>, | |
222 | public CompClsBridgeWithOutputPorts<FltCompClsBridge<UserCompClsT>, FltCompClsLibTypes> | |
223 | { | |
224 | }; | |
225 | ||
226 | struct SinkCompClsLibTypes final | |
227 | { | |
228 | using SelfCompCls = bt_self_component_class_sink; | |
229 | using SelfComp = bt_self_component_sink; | |
230 | using SelfCompCfg = bt_self_component_sink_configuration; | |
231 | }; | |
232 | ||
233 | template <typename UserCompClsT> | |
234 | class SinkCompClsBridge final : | |
235 | CompClsBridge<UserCompClsT, SinkCompClsLibTypes>, | |
236 | CompClsBridgeWithInputPorts<SinkCompClsBridge<UserCompClsT>, SinkCompClsLibTypes> | |
237 | { | |
238 | private: | |
239 | using CompClsBridge<UserCompClsT, SinkCompClsLibTypes>::userCompFromLibSelfCompPtr; | |
240 | ||
241 | public: | |
242 | static bt_component_class_sink_consume_method_status | |
243 | consume(bt_self_component_sink * const libSelfCompPtr) noexcept | |
244 | { | |
245 | try { | |
246 | if (userCompFromLibSelfCompPtr(libSelfCompPtr).consume()) { | |
247 | return BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; | |
248 | } else { | |
249 | return BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END; | |
250 | } | |
251 | } catch (const TryAgain&) { | |
252 | return BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN; | |
253 | } catch (const std::bad_alloc&) { | |
254 | return BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR; | |
255 | } catch (const Error&) { | |
256 | return BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; | |
257 | } catch (...) { | |
258 | BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING, | |
259 | static_cast<int>(wrap(libSelfCompPtr).loggingLevel()), | |
260 | unhandledExcLogTag(), unhandledExcLogStr()); | |
261 | return BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; | |
262 | } | |
263 | } | |
264 | ||
265 | static bt_component_class_sink_graph_is_configured_method_status | |
266 | graphIsConfigured(bt_self_component_sink * const libSelfCompPtr) noexcept | |
267 | { | |
268 | try { | |
269 | userCompFromLibSelfCompPtr(libSelfCompPtr).graphIsConfigured(); | |
270 | } catch (const std::bad_alloc&) { | |
271 | return BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_MEMORY_ERROR; | |
272 | } catch (const Error&) { | |
273 | return BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_ERROR; | |
274 | } catch (...) { | |
275 | BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING, | |
276 | static_cast<int>(wrap(libSelfCompPtr).loggingLevel()), | |
277 | unhandledExcLogTag(), unhandledExcLogStr()); | |
278 | return BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_ERROR; | |
279 | } | |
280 | } | |
281 | }; | |
282 | ||
283 | template <typename UserMsgIterT> | |
284 | class MsgIterClsBridge final | |
285 | { | |
286 | public: | |
287 | static UserMsgIterT& | |
288 | userMsgIterFromLibSelfMsgIterPtr(bt_self_message_iterator * const libSelfMsgIterPtr) noexcept | |
289 | { | |
290 | return bt2::wrap(libSelfMsgIterPtr).data<UserMsgIterT>(); | |
291 | } | |
292 | ||
293 | static bt_message_iterator_class_initialize_method_status | |
294 | init(bt_self_message_iterator * const libSelfMsgIterPtr, | |
295 | bt_self_message_iterator_configuration * const libSelfMsgIterConfigPtr, | |
296 | bt_self_component_port_output * const libSelfCompPortPtr) noexcept | |
297 | { | |
298 | const auto selfMsgIter = bt2::wrap(libSelfMsgIterPtr); | |
299 | ||
300 | try { | |
301 | const auto msgIter = new UserMsgIterT {selfMsgIter, bt2::wrap(libSelfMsgIterConfigPtr), | |
302 | bt2::wrap(libSelfCompPortPtr)}; | |
303 | ||
304 | selfMsgIter.data(*msgIter); | |
305 | } catch (const std::bad_alloc&) { | |
306 | return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; | |
307 | } catch (const bt2::Error&) { | |
308 | return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR; | |
309 | } catch (...) { | |
310 | BT_LOG_WRITE_CUR_LVL( | |
311 | BT_LOG_WARNING, | |
312 | static_cast<int>(wrap(libSelfMsgIterPtr).component().loggingLevel()), | |
313 | unhandledExcLogTag(), unhandledExcLogStr()); | |
314 | return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR; | |
315 | } | |
316 | ||
317 | return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK; | |
318 | } | |
319 | ||
320 | static void finalize(bt_self_message_iterator * const libSelfMsgIterPtr) noexcept | |
321 | { | |
322 | delete &userMsgIterFromLibSelfMsgIterPtr(libSelfMsgIterPtr); | |
323 | } | |
324 | ||
325 | static bt_message_iterator_class_next_method_status | |
326 | next(bt_self_message_iterator * const libSelfMsgIterPtr, bt_message_array_const libMsgsPtr, | |
327 | const uint64_t capacity, uint64_t * const count) noexcept | |
328 | { | |
329 | try { | |
330 | auto msgArray = bt2::ConstMessageArray::wrapEmpty(libMsgsPtr, capacity); | |
331 | auto& msgIter = userMsgIterFromLibSelfMsgIterPtr(libSelfMsgIterPtr); | |
332 | ||
333 | msgIter.next(msgArray); | |
334 | *count = msgArray.release(); | |
335 | ||
336 | if (G_LIKELY(*count > 0)) { | |
337 | return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK; | |
338 | } else { | |
339 | return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END; | |
340 | } | |
341 | } catch (const bt2::TryAgain&) { | |
342 | return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_AGAIN; | |
343 | } catch (const std::bad_alloc&) { | |
344 | return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_MEMORY_ERROR; | |
345 | } catch (const bt2::Error&) { | |
346 | return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR; | |
347 | } catch (...) { | |
348 | BT_LOG_WRITE_CUR_LVL( | |
349 | BT_LOG_WARNING, | |
350 | static_cast<int>(wrap(libSelfMsgIterPtr).component().loggingLevel()), | |
351 | unhandledExcLogTag(), unhandledExcLogStr()); | |
352 | return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR; | |
353 | } | |
354 | } | |
355 | ||
356 | static bt_message_iterator_class_can_seek_beginning_method_status | |
357 | canSeekBeginning(bt_self_message_iterator * const libSelfMsgIterPtr, | |
358 | bt_bool * const canSeek) noexcept | |
359 | { | |
360 | try { | |
361 | *canSeek = static_cast<bt_bool>( | |
362 | userMsgIterFromLibSelfMsgIterPtr(libSelfMsgIterPtr).canSeekBeginning()); | |
363 | } catch (const bt2::TryAgain&) { | |
364 | return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_AGAIN; | |
365 | } catch (const std::bad_alloc&) { | |
366 | return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_MEMORY_ERROR; | |
367 | } catch (const bt2::Error&) { | |
368 | return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_ERROR; | |
369 | } catch (...) { | |
370 | BT_LOG_WRITE_CUR_LVL( | |
371 | BT_LOG_WARNING, | |
372 | static_cast<int>(wrap(libSelfMsgIterPtr).component().loggingLevel()), | |
373 | unhandledExcLogTag(), unhandledExcLogStr()); | |
374 | return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_ERROR; | |
375 | } | |
376 | ||
377 | return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_OK; | |
378 | } | |
379 | ||
380 | static bt_message_iterator_class_seek_beginning_method_status | |
381 | seekBeginning(bt_self_message_iterator * const libSelfMsgIterPtr) noexcept | |
382 | { | |
383 | try { | |
384 | userMsgIterFromLibSelfMsgIterPtr(libSelfMsgIterPtr).seekBeginning(); | |
385 | } catch (const bt2::TryAgain&) { | |
386 | return BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_AGAIN; | |
387 | } catch (const std::bad_alloc&) { | |
388 | return BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_MEMORY_ERROR; | |
389 | } catch (const bt2::Error&) { | |
390 | return BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_ERROR; | |
391 | } catch (...) { | |
392 | BT_LOG_WRITE_CUR_LVL( | |
393 | BT_LOG_WARNING, | |
394 | static_cast<int>(wrap(libSelfMsgIterPtr).component().loggingLevel()), | |
395 | unhandledExcLogTag(), unhandledExcLogStr()); | |
396 | return BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_ERROR; | |
397 | } | |
398 | ||
399 | return BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_OK; | |
400 | } | |
401 | ||
402 | static bt_message_iterator_class_can_seek_ns_from_origin_method_status | |
403 | canSeekNsFromOrigin(bt_self_message_iterator * const libSelfMsgIterPtr, | |
404 | const std::int64_t nsFromOrigin, bt_bool * const canSeek) noexcept | |
405 | { | |
406 | try { | |
407 | *canSeek = static_cast<bt_bool>(userMsgIterFromLibSelfMsgIterPtr(libSelfMsgIterPtr) | |
408 | .canSeekNsFromOrigin(nsFromOrigin)); | |
409 | } catch (const bt2::TryAgain&) { | |
410 | return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_AGAIN; | |
411 | } catch (const std::bad_alloc&) { | |
412 | return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_MEMORY_ERROR; | |
413 | } catch (const bt2::Error&) { | |
414 | return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_ERROR; | |
415 | } catch (...) { | |
416 | BT_LOG_WRITE_CUR_LVL( | |
417 | BT_LOG_WARNING, | |
418 | static_cast<int>(wrap(libSelfMsgIterPtr).component().loggingLevel()), | |
419 | unhandledExcLogTag(), unhandledExcLogStr()); | |
420 | return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_ERROR; | |
421 | } | |
422 | ||
423 | return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK; | |
424 | } | |
425 | ||
426 | static bt_message_iterator_class_seek_ns_from_origin_method_status | |
427 | seekNsFromOrigin(bt_self_message_iterator * const libSelfMsgIterPtr, | |
428 | const std::int64_t nsFromOrigin) noexcept | |
429 | { | |
430 | try { | |
431 | userMsgIterFromLibSelfMsgIterPtr(libSelfMsgIterPtr).seekNsFromOrigin(nsFromOrigin); | |
432 | } catch (const bt2::TryAgain&) { | |
433 | return BT_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_AGAIN; | |
434 | } catch (const std::bad_alloc&) { | |
435 | return BT_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_MEMORY_ERROR; | |
436 | } catch (const bt2::Error&) { | |
437 | return BT_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_ERROR; | |
438 | } catch (...) { | |
439 | BT_LOG_WRITE_CUR_LVL( | |
440 | BT_LOG_WARNING, | |
441 | static_cast<int>(wrap(libSelfMsgIterPtr).component().loggingLevel()), | |
442 | unhandledExcLogTag(), unhandledExcLogStr()); | |
443 | return BT_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_ERROR; | |
444 | } | |
445 | ||
446 | return BT_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_OK; | |
447 | } | |
448 | }; | |
449 | ||
450 | } /* namespace internal */ | |
451 | ||
452 | template <typename UserMessageIteratorT, typename UserComponentT> | |
453 | class UserMessageIterator; | |
454 | ||
455 | /* | |
456 | * Base class of any user component. | |
457 | * | |
458 | * See the specific `bt2::UserSourceComponent`, | |
459 | * `bt2::UserFilterComponent`, and `bt2::UserSinkComponent`. | |
460 | */ | |
461 | template <typename SelfCompT> | |
462 | class UserComponent | |
463 | { | |
464 | /* Give a related message iterator access to this logger */ | |
465 | template <typename, typename> | |
466 | friend class UserMessageIterator; | |
467 | ||
468 | protected: | |
469 | explicit UserComponent(const SelfCompT selfComp, const std::string& logTag) : | |
470 | _mLogger {selfComp, fmt::format("{}/[{}]", logTag, selfComp.name())}, _mSelfComp {selfComp} | |
471 | { | |
472 | } | |
473 | ||
474 | protected: | |
e7f0f07b | 475 | bt2c::CStringView _name() const noexcept |
af38ae4f PP |
476 | { |
477 | return _mSelfComp.name(); | |
478 | } | |
479 | ||
480 | LoggingLevel _loggingLevel() const noexcept | |
481 | { | |
482 | return _mSelfComp.loggingLevel(); | |
483 | } | |
484 | ||
485 | std::uint64_t _graphMipVersion() const noexcept | |
486 | { | |
487 | return _mSelfComp.graphMipVersion(); | |
488 | } | |
489 | ||
490 | SelfCompT _selfComp() noexcept | |
491 | { | |
492 | return _mSelfComp; | |
493 | } | |
494 | ||
495 | bt2c::Logger _mLogger; | |
496 | ||
497 | private: | |
498 | SelfCompT _mSelfComp; | |
499 | }; | |
500 | ||
501 | /* | |
502 | * Base class of a user source component `UserComponentT` (CRTP). | |
503 | * | |
504 | * `UserComponentT::UserComponentT()` must accept a | |
505 | * `bt2::SelfSourceComponent` parameter, which it needs to forward to | |
506 | * bt2::UserSourceComponent::UserSourceComponent(), and a | |
507 | * `bt2::ConstValue` parameter (initialization parameters). | |
508 | */ | |
509 | template <typename UserComponentT> | |
510 | class UserSourceComponent : public UserComponent<SelfSourceComponent> | |
511 | { | |
512 | protected: | |
513 | using _OutputPorts = SelfSourceComponent::OutputPorts; | |
514 | ||
515 | explicit UserSourceComponent(const SelfSourceComponent selfComp, const std::string& logTag) : | |
516 | UserComponent<SelfSourceComponent> {selfComp, logTag} | |
517 | { | |
518 | } | |
519 | ||
520 | public: | |
521 | static Value::Shared query(const SelfComponentClass selfCompCls, | |
522 | const PrivateQueryExecutor privQueryExec, const char * const obj, | |
523 | const ConstValue params) | |
524 | { | |
525 | return UserComponentT::_query(selfCompCls, privQueryExec, obj, params); | |
526 | } | |
527 | ||
528 | static void getSupportedMipVersions(const SelfComponentClass selfCompCls, | |
529 | const ConstValue params, const LoggingLevel loggingLevel, | |
530 | const UnsignedIntegerRangeSet ranges) | |
531 | { | |
532 | UserComponentT::_getSupportedMipVersions(selfCompCls, params, loggingLevel, ranges); | |
533 | } | |
534 | ||
535 | void outputPortConnected(const SelfComponentOutputPort outputPort, | |
536 | const ConstInputPort inputPort) | |
537 | { | |
538 | static_cast<UserComponentT&>(*this).outputPortConnected(outputPort, inputPort); | |
539 | } | |
540 | ||
541 | protected: | |
542 | /* Overloadable */ | |
543 | static Value::Shared _query(SelfComponentClass, PrivateQueryExecutor, const char *, ConstValue) | |
544 | { | |
545 | throw UnknownObject {}; | |
546 | } | |
547 | ||
548 | /* Overloadable */ | |
549 | static void _getSupportedMipVersions(SelfComponentClass, ConstValue, LoggingLevel, | |
550 | const UnsignedIntegerRangeSet ranges) | |
551 | { | |
552 | ranges.addRange(0, 0); | |
553 | } | |
554 | ||
555 | /* Overloadable */ | |
556 | void _outputPortConnected(SelfComponentOutputPort, ConstInputPort) | |
557 | { | |
558 | } | |
559 | ||
560 | template <typename DataT> | |
561 | _OutputPorts::Port _addOutputPort(const char * const name, DataT * const data) | |
562 | { | |
563 | return this->_selfComp().addOutputPort(name, data); | |
564 | } | |
565 | ||
566 | _OutputPorts::Port _addOutputPort(const char *name) | |
567 | { | |
568 | return this->_selfComp().addOutputPort(name); | |
569 | } | |
570 | ||
571 | template <typename DataT> | |
572 | _OutputPorts::Port _addOutputPort(const std::string& name, DataT * const data) | |
573 | { | |
574 | return this->_selfComp().addOutputPort(name, data); | |
575 | } | |
576 | ||
577 | _OutputPorts::Port _addOutputPort(const std::string& name) | |
578 | { | |
579 | return this->_selfComp().addOutputPort(name); | |
580 | } | |
581 | ||
582 | _OutputPorts _outputPorts() noexcept | |
583 | { | |
584 | return this->_selfComp().outputPorts(); | |
585 | } | |
586 | }; | |
587 | ||
588 | /* | |
589 | * Base class of a user filter component `UserComponentT` (CRTP). | |
590 | * | |
591 | * `UserComponentT::UserComponentT()` must accept a | |
592 | * `bt2::SelfFilterComponent` parameter, which it needs to forward to | |
593 | * bt2::UserFilterComponent::UserFilterComponent(), and a | |
594 | * `bt2::ConstValue` parameter (initialization parameters). | |
595 | */ | |
596 | template <typename UserComponentT> | |
597 | class UserFilterComponent : public UserComponent<SelfFilterComponent> | |
598 | { | |
599 | protected: | |
600 | using _InputPorts = SelfFilterComponent::InputPorts; | |
601 | using _OutputPorts = SelfFilterComponent::OutputPorts; | |
602 | ||
603 | explicit UserFilterComponent(const SelfFilterComponent selfComp, const std::string& logTag) : | |
604 | UserComponent<SelfFilterComponent> {selfComp, logTag} | |
605 | { | |
606 | } | |
607 | ||
608 | public: | |
609 | static Value::Shared query(const SelfComponentClass selfCompCls, | |
610 | const PrivateQueryExecutor privQueryExec, const char * const obj, | |
611 | const ConstValue params) | |
612 | { | |
613 | return UserComponentT::_query(selfCompCls, privQueryExec, obj, params); | |
614 | } | |
615 | ||
616 | static void getSupportedMipVersions(const SelfComponentClass selfCompCls, | |
617 | const ConstValue params, const LoggingLevel loggingLevel, | |
618 | const UnsignedIntegerRangeSet ranges) | |
619 | { | |
620 | UserComponentT::_getSupportedMipVersions(selfCompCls, params, loggingLevel, ranges); | |
621 | } | |
622 | ||
623 | void inputPortConnected(const SelfComponentInputPort inputPort, | |
624 | const ConstOutputPort outputPort) | |
625 | { | |
626 | static_cast<UserComponentT&>(*this)._inputPortConnected(inputPort, outputPort); | |
627 | } | |
628 | ||
629 | void outputPortConnected(const SelfComponentOutputPort outputPort, | |
630 | const ConstInputPort inputPort) | |
631 | { | |
632 | static_cast<UserComponentT&>(*this)._outputPortConnected(outputPort, inputPort); | |
633 | } | |
634 | ||
635 | protected: | |
636 | /* Overloadable */ | |
637 | static Value::Shared _query(SelfComponentClass, PrivateQueryExecutor, const char *, ConstValue) | |
638 | { | |
639 | throw UnknownObject {}; | |
640 | } | |
641 | ||
642 | /* Overloadable */ | |
643 | static void _getSupportedMipVersions(SelfComponentClass, ConstValue, LoggingLevel, | |
644 | const UnsignedIntegerRangeSet ranges) | |
645 | { | |
646 | ranges.addRange(0, 0); | |
647 | } | |
648 | ||
649 | /* Overloadable */ | |
650 | void _inputPortConnected(SelfComponentInputPort, ConstOutputPort) | |
651 | { | |
652 | } | |
653 | ||
654 | /* Overloadable */ | |
655 | void _outputPortConnected(SelfComponentOutputPort, ConstInputPort) | |
656 | { | |
657 | } | |
658 | ||
659 | template <typename DataT> | |
660 | _OutputPorts::Port _addInputPort(const char * const name, DataT * const data) | |
661 | { | |
662 | return this->_selfComp().addInputPort(name, data); | |
663 | } | |
664 | ||
665 | _InputPorts::Port _addInputPort(const char *name) | |
666 | { | |
667 | return this->_selfComp().addInputPort(name); | |
668 | } | |
669 | ||
670 | template <typename DataT> | |
671 | _InputPorts::Port _addInputPort(const std::string& name, DataT * const data) | |
672 | { | |
673 | return this->_selfComp().addInputPort(name, data); | |
674 | } | |
675 | ||
676 | _InputPorts::Port _addInputPort(const std::string& name) | |
677 | { | |
678 | return this->_selfComp().addInputPort(name); | |
679 | } | |
680 | ||
681 | _InputPorts _inputPorts() noexcept | |
682 | { | |
683 | return this->_selfComp().inputPorts(); | |
684 | } | |
685 | ||
686 | template <typename DataT> | |
687 | _OutputPorts::Port _addOutputPort(const char * const name, DataT * const data) | |
688 | { | |
689 | return this->_selfComp().addOutputPort(name, data); | |
690 | } | |
691 | ||
692 | _OutputPorts::Port _addOutputPort(const char *name) | |
693 | { | |
694 | return this->_selfComp().addOutputPort(name); | |
695 | } | |
696 | ||
697 | template <typename DataT> | |
698 | _OutputPorts::Port _addOutputPort(const std::string& name, DataT * const data) | |
699 | { | |
700 | return this->_selfComp().addOutputPort(name, data); | |
701 | } | |
702 | ||
703 | _OutputPorts::Port _addOutputPort(const std::string& name) | |
704 | { | |
705 | return this->_selfComp().addOutputPort(name); | |
706 | } | |
707 | ||
708 | _OutputPorts _outputPorts() noexcept | |
709 | { | |
710 | return this->_selfComp().outputPorts(); | |
711 | } | |
712 | }; | |
713 | ||
714 | /* | |
715 | * Base class of a user sink component `UserComponentT` (CRTP). | |
716 | * | |
717 | * `UserComponentT::UserComponentT()` must accept a | |
718 | * `bt2::SelfSinkComponent` parameter, which it needs to forward to | |
719 | * bt2::UserSinkComponent::UserSinkComponent(), and a `bt2::ConstValue` | |
720 | * parameter (initialization parameters). | |
721 | * | |
722 | * `UserComponentT` must implement: | |
723 | * | |
724 | * bool _consume(); | |
725 | * | |
726 | * This method returns `true` if the sink component still needs to | |
727 | * consume, or `false` if it's finished. | |
728 | */ | |
729 | template <typename UserComponentT> | |
730 | class UserSinkComponent : public UserComponent<SelfSinkComponent> | |
731 | { | |
732 | protected: | |
733 | using _InputPorts = SelfSinkComponent::InputPorts; | |
734 | ||
735 | explicit UserSinkComponent(const SelfSinkComponent selfComp, const std::string& logTag) : | |
736 | UserComponent<SelfSinkComponent> {selfComp, logTag} | |
737 | { | |
738 | } | |
739 | ||
740 | public: | |
741 | static Value::Shared query(const SelfComponentClass selfCompCls, | |
742 | const PrivateQueryExecutor privQueryExec, const char * const obj, | |
743 | const ConstValue params) | |
744 | { | |
745 | return UserComponentT::_query(selfCompCls, privQueryExec, obj, params); | |
746 | } | |
747 | ||
748 | static void getSupportedMipVersions(const SelfComponentClass selfCompCls, | |
749 | const ConstValue params, const LoggingLevel loggingLevel, | |
750 | const UnsignedIntegerRangeSet ranges) | |
751 | { | |
752 | UserComponentT::_getSupportedMipVersions(selfCompCls, params, loggingLevel, ranges); | |
753 | } | |
754 | ||
755 | void graphIsConfigured() | |
756 | { | |
757 | static_cast<UserComponentT&>(*this)._graphIsConfigured(); | |
758 | } | |
759 | ||
760 | void inputPortConnected(const SelfComponentInputPort inputPort, | |
761 | const ConstOutputPort outputPort) | |
762 | { | |
763 | static_cast<UserComponentT&>(*this)._inputPortConnected(inputPort, outputPort); | |
764 | } | |
765 | ||
766 | bool consume() | |
767 | { | |
768 | return static_cast<UserComponentT&>(*this)._consume(); | |
769 | } | |
770 | ||
771 | protected: | |
772 | /* Overloadable */ | |
773 | static Value::Shared _query(SelfComponentClass, PrivateQueryExecutor, const char *, ConstValue) | |
774 | { | |
775 | throw UnknownObject {}; | |
776 | } | |
777 | ||
778 | /* Overloadable */ | |
779 | static void _getSupportedMipVersions(SelfComponentClass, ConstValue, LoggingLevel, | |
780 | const UnsignedIntegerRangeSet ranges) | |
781 | { | |
782 | ranges.addRange(0, 0); | |
783 | } | |
784 | ||
785 | /* Overloadable */ | |
786 | void _graphIsConfigured() | |
787 | { | |
788 | } | |
789 | ||
790 | /* Overloadable */ | |
791 | void _inputPortConnected(SelfComponentInputPort, ConstOutputPort) | |
792 | { | |
793 | } | |
794 | ||
795 | MessageIterator::Shared _createMessageIterator(const _InputPorts::Port port) | |
796 | { | |
797 | return this->_selfComp().createMessageIterator(port); | |
798 | } | |
799 | ||
800 | template <typename DataT> | |
801 | _InputPorts::Port _addInputPort(const char * const name, DataT * const data) | |
802 | { | |
803 | return this->_selfComp().addInputPort(name, data); | |
804 | } | |
805 | ||
806 | _InputPorts::Port _addInputPort(const char *name) | |
807 | { | |
808 | return this->_selfComp().addInputPort(name); | |
809 | } | |
810 | ||
811 | template <typename DataT> | |
812 | _InputPorts::Port _addInputPort(const std::string& name, DataT * const data) | |
813 | { | |
814 | return this->_selfComp().addInputPort(name, data); | |
815 | } | |
816 | ||
817 | _InputPorts::Port _addInputPort(const std::string& name) | |
818 | { | |
819 | return this->_selfComp().addInputPort(name); | |
820 | } | |
821 | ||
822 | _InputPorts _inputPorts() noexcept | |
823 | { | |
824 | return this->_selfComp().inputPorts(); | |
825 | } | |
826 | }; | |
827 | ||
828 | /* | |
829 | * Base class of a user message iterator `UserMessageIteratorT` (CRTP) | |
830 | * of which the parent user component class is `UserComponentT`. | |
831 | * | |
832 | * `UserMessageIteratorT::UserMessageIteratorT()` must accept a | |
833 | * `bt2::SelfMessageIterator` parameter, which it needs to forward to | |
834 | * bt2::UserMessageIterator::UserMessageIterator(). | |
835 | * | |
836 | * The public next() method below (called by the bridge) implements the | |
837 | * very common pattern of appending messages into the output array, and, | |
838 | * meanwhile: | |
839 | * | |
840 | * If it catches a `bt2::TryAgain` exception: | |
841 | * If the message array isn't empty, transform this into a success | |
842 | * (don't throw). | |
843 | * | |
844 | * Otherwise rethrow. | |
845 | * | |
846 | * If it catches an error: | |
847 | * If the message array isn't empty, transform this into a success | |
848 | * (don't throw), but save the error of the current thread and the | |
849 | * type of error to throw the next time the user calls next(). | |
850 | * | |
851 | * Otherwise rethrow. | |
852 | * | |
853 | * `UserMessageIteratorT` must implement: | |
854 | * | |
855 | * void _next(bt2::ConstMessageArray& messages); | |
856 | * | |
857 | * This method fills `messages` with at most `messages.capacity()` | |
858 | * messages and may throw `bt2::TryAgain` or a valid error whenever. | |
859 | * Leaving an empty `messages` means the end of iteration. | |
860 | */ | |
861 | template <typename UserMessageIteratorT, typename UserComponentT> | |
862 | class UserMessageIterator | |
863 | { | |
864 | private: | |
865 | /* Type of `_mExcToThrowType` */ | |
866 | enum class _ExcToThrowType | |
867 | { | |
868 | NONE, | |
869 | ERROR, | |
870 | MEM_ERROR, | |
871 | }; | |
872 | ||
873 | protected: | |
874 | explicit UserMessageIterator(const SelfMessageIterator selfMsgIter, | |
875 | const std::string& logTagSuffix) : | |
876 | _mSelfMsgIter {selfMsgIter}, | |
877 | _mLogger {selfMsgIter, | |
878 | fmt::format("{}/{}", this->_component()._mLogger.tag(), logTagSuffix)} | |
879 | { | |
880 | } | |
881 | ||
882 | public: | |
883 | ~UserMessageIterator() | |
884 | { | |
885 | this->_resetError(); | |
886 | } | |
887 | ||
888 | void next(bt2::ConstMessageArray& messages) | |
889 | { | |
890 | /* Any saved error? Now is the time to throw */ | |
891 | if (G_UNLIKELY(_mExcToThrowType != _ExcToThrowType::NONE)) { | |
892 | /* Move `_mSavedLibError`, if any, as current thread error */ | |
893 | if (_mSavedLibError) { | |
894 | BT_CURRENT_THREAD_MOVE_ERROR_AND_RESET(_mSavedLibError); | |
895 | } | |
896 | ||
897 | /* Throw the corresponding exception */ | |
898 | if (_mExcToThrowType == _ExcToThrowType::ERROR) { | |
899 | throw bt2::Error {}; | |
900 | } else { | |
901 | BT_ASSERT(_mExcToThrowType == _ExcToThrowType::MEM_ERROR); | |
902 | throw bt2::MemoryError {}; | |
903 | } | |
904 | } | |
905 | ||
906 | /* | |
907 | * When catching some exception below, if our message array | |
908 | * isn't empty, then return immediately before throwing to | |
909 | * provide those messages to downstream. | |
910 | * | |
911 | * When catching an error, also save the current thread error, | |
912 | * if any, so that we can restore it later (see the beginning of | |
913 | * this method). | |
914 | */ | |
915 | BT_ASSERT_DBG(_mExcToThrowType == _ExcToThrowType::NONE); | |
916 | ||
917 | try { | |
918 | this->_userObj()._next(messages); | |
919 | ||
920 | /* We're done: everything below is exception handling */ | |
921 | return; | |
922 | } catch (const bt2::TryAgain&) { | |
923 | if (messages.isEmpty()) { | |
924 | throw; | |
925 | } | |
926 | } catch (const std::bad_alloc&) { | |
927 | if (messages.isEmpty()) { | |
928 | throw; | |
929 | } | |
930 | ||
931 | _mExcToThrowType = _ExcToThrowType::MEM_ERROR; | |
932 | } catch (const bt2::Error&) { | |
933 | if (messages.isEmpty()) { | |
934 | throw; | |
935 | } | |
936 | ||
937 | _mExcToThrowType = _ExcToThrowType::ERROR; | |
938 | } | |
939 | ||
940 | if (_mExcToThrowType != _ExcToThrowType::NONE) { | |
941 | BT_CPPLOGE( | |
942 | "An error occurred, but there are {} messages to return: delaying the error reporting.", | |
943 | messages.length()); | |
944 | BT_ASSERT(!_mSavedLibError); | |
945 | _mSavedLibError = bt_current_thread_take_error(); | |
946 | } | |
947 | } | |
948 | ||
949 | bool canSeekBeginning() | |
950 | { | |
951 | this->_resetError(); | |
952 | return this->_userObj()._canSeekBeginning(); | |
953 | } | |
954 | ||
955 | void seekBeginning() | |
956 | { | |
957 | this->_resetError(); | |
958 | return this->_userObj()._seekBeginning(); | |
959 | } | |
960 | ||
961 | bool canSeekNsFromOrigin(const std::int64_t nsFromOrigin) | |
962 | { | |
963 | this->_resetError(); | |
964 | return this->_userObj()._canSeekNsFromOrigin(nsFromOrigin); | |
965 | } | |
966 | ||
967 | void seekNsFromOrigin(const std::int64_t nsFromOrigin) | |
968 | { | |
969 | this->_resetError(); | |
970 | this->_userObj()._seekNsFromOrigin(nsFromOrigin); | |
971 | } | |
972 | ||
973 | protected: | |
974 | /* Overloadable */ | |
975 | bool _canSeekBeginning() noexcept | |
976 | { | |
977 | return false; | |
978 | } | |
979 | ||
980 | /* Overloadable */ | |
981 | void _seekBeginning() noexcept | |
982 | { | |
983 | } | |
984 | ||
985 | /* Overloadable */ | |
986 | bool _canSeekNsFromOrigin(std::int64_t) noexcept | |
987 | { | |
988 | return false; | |
989 | } | |
990 | ||
991 | /* Overloadable */ | |
992 | void _seekNsFromOrigin(std::int64_t) noexcept | |
993 | { | |
994 | } | |
995 | ||
996 | MessageIterator::Shared _createMessageIterator(const SelfComponentInputPort port) | |
997 | { | |
998 | return _mSelfMsgIter.createMessageIterator(port); | |
999 | } | |
1000 | ||
1001 | UserComponentT& _component() noexcept | |
1002 | { | |
1003 | return _mSelfMsgIter.component().template data<UserComponentT>(); | |
1004 | } | |
1005 | ||
1006 | SelfComponentOutputPort _port() noexcept | |
1007 | { | |
1008 | return _mSelfMsgIter.port(); | |
1009 | } | |
1010 | ||
1011 | bool _isInterrupted() const noexcept | |
1012 | { | |
1013 | return _mSelfMsgIter.isInterrupted(); | |
1014 | } | |
1015 | ||
1016 | private: | |
1017 | UserMessageIteratorT& _userObj() noexcept | |
1018 | { | |
1019 | return static_cast<UserMessageIteratorT&>(*this); | |
1020 | } | |
1021 | ||
1022 | void _resetError() noexcept | |
1023 | { | |
1024 | _mExcToThrowType = _ExcToThrowType::NONE; | |
1025 | ||
1026 | if (_mSavedLibError) { | |
1027 | bt_error_release(_mSavedLibError); | |
1028 | } | |
1029 | } | |
1030 | ||
1031 | SelfMessageIterator _mSelfMsgIter; | |
1032 | ||
1033 | /* | |
1034 | * next() may accumulate messages, and then catch an error before | |
1035 | * returning. In that case, it saves the error of the current thread | |
1036 | * here so that it can return its accumulated messages and throw the | |
1037 | * next time. | |
1038 | * | |
1039 | * It also saves the type of the exception to throw the next time. | |
1040 | */ | |
1041 | _ExcToThrowType _mExcToThrowType = _ExcToThrowType::NONE; | |
1042 | const bt_error *_mSavedLibError = nullptr; | |
1043 | ||
1044 | protected: | |
1045 | bt2c::Logger _mLogger; | |
1046 | }; | |
1047 | ||
1048 | } /* namespace bt2 */ | |
1049 | ||
1050 | #define BT_CPP_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID( \ | |
1051 | _pluginId, _componentClassId, _name, _userComponentClass, _userMessageIteratorClass) \ | |
1052 | BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID( \ | |
1053 | _pluginId, _componentClassId, _name, \ | |
1054 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::next); \ | |
1055 | BT_PLUGIN_SOURCE_COMPONENT_CLASS_INITIALIZE_METHOD_WITH_ID( \ | |
1056 | _pluginId, _componentClassId, bt2::internal::SrcCompClsBridge<_userComponentClass>::init); \ | |
1057 | BT_PLUGIN_SOURCE_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID( \ | |
1058 | _pluginId, _componentClassId, \ | |
1059 | bt2::internal::SrcCompClsBridge<_userComponentClass>::finalize); \ | |
1060 | BT_PLUGIN_SOURCE_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_WITH_ID( \ | |
1061 | _pluginId, _componentClassId, \ | |
1062 | bt2::internal::SrcCompClsBridge<_userComponentClass>::getSupportedMipVersions); \ | |
1063 | BT_PLUGIN_SOURCE_COMPONENT_CLASS_OUTPUT_PORT_CONNECTED_METHOD_WITH_ID( \ | |
1064 | _pluginId, _componentClassId, \ | |
1065 | bt2::internal::SrcCompClsBridge<_userComponentClass>::outputPortConnected); \ | |
1066 | BT_PLUGIN_SOURCE_COMPONENT_CLASS_QUERY_METHOD_WITH_ID( \ | |
1067 | _pluginId, _componentClassId, \ | |
1068 | bt2::internal::SrcCompClsBridge<_userComponentClass>::query); \ | |
1069 | BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_WITH_ID( \ | |
1070 | _pluginId, _componentClassId, \ | |
1071 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::init); \ | |
1072 | BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_FINALIZE_METHOD_WITH_ID( \ | |
1073 | _pluginId, _componentClassId, \ | |
1074 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::finalize); \ | |
1075 | BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHODS_WITH_ID( \ | |
1076 | _pluginId, _componentClassId, \ | |
1077 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::seekBeginning, \ | |
1078 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::canSeekBeginning); \ | |
1079 | BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHODS_WITH_ID( \ | |
1080 | _pluginId, _componentClassId, \ | |
1081 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::seekNsFromOrigin, \ | |
1082 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::canSeekNsFromOrigin); | |
1083 | ||
1084 | #define BT_CPP_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID( \ | |
1085 | _pluginId, _componentClassId, _name, _userComponentClass, _userMessageIteratorClass) \ | |
1086 | BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID( \ | |
1087 | _pluginId, _componentClassId, _name, \ | |
1088 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::next); \ | |
1089 | BT_PLUGIN_FILTER_COMPONENT_CLASS_INITIALIZE_METHOD_WITH_ID( \ | |
1090 | _pluginId, _componentClassId, bt2::internal::FltCompClsBridge<_userComponentClass>::init); \ | |
1091 | BT_PLUGIN_FILTER_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID( \ | |
1092 | _pluginId, _componentClassId, \ | |
1093 | bt2::internal::FltCompClsBridge<_userComponentClass>::finalize); \ | |
1094 | BT_PLUGIN_FILTER_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_WITH_ID( \ | |
1095 | _pluginId, _componentClassId, \ | |
1096 | bt2::internal::FltCompClsBridge<_userComponentClass>::getSupportedMipVersions); \ | |
1097 | BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD_WITH_ID( \ | |
1098 | _pluginId, _componentClassId, \ | |
1099 | bt2::internal::FltCompClsBridge<_userComponentClass>::inputPortConnected); \ | |
1100 | BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_CONNECTED_METHOD_WITH_ID( \ | |
1101 | _pluginId, _componentClassId, \ | |
1102 | bt2::internal::FltCompClsBridge<_userComponentClass>::outputPortConnected); \ | |
1103 | BT_PLUGIN_FILTER_COMPONENT_CLASS_QUERY_METHOD_WITH_ID( \ | |
1104 | _pluginId, _componentClassId, \ | |
1105 | bt2::internal::FltCompClsBridge<_userComponentClass>::query); \ | |
1106 | BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_WITH_ID( \ | |
1107 | _pluginId, _componentClassId, \ | |
1108 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::init); \ | |
1109 | BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_FINALIZE_METHOD_WITH_ID( \ | |
1110 | _pluginId, _componentClassId, \ | |
1111 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::finalize); \ | |
1112 | BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHODS_WITH_ID( \ | |
1113 | _pluginId, _componentClassId, \ | |
1114 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::seekBeginning, \ | |
1115 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::canSeekBeginning); \ | |
1116 | BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHODS_WITH_ID( \ | |
1117 | _pluginId, _componentClassId, \ | |
1118 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::seekNsFromOrigin, \ | |
1119 | bt2::internal::MsgIterClsBridge<_userMessageIteratorClass>::canSeekNsFromOrigin); | |
1120 | ||
1121 | #define BT_CPP_PLUGIN_SINK_COMPONENT_CLASS_WITH_ID(_pluginId, _componentClassId, _name, \ | |
1122 | _userComponentClass) \ | |
1123 | BT_PLUGIN_SINK_COMPONENT_CLASS_WITH_ID( \ | |
1124 | _pluginId, _componentClassId, _name, \ | |
1125 | bt2::internal::SinkCompClsBridge<_userComponentClass>::consume); \ | |
1126 | BT_PLUGIN_SINK_COMPONENT_CLASS_INITIALIZE_METHOD_WITH_ID( \ | |
1127 | _pluginId, _componentClassId, \ | |
1128 | bt2::internal::SinkCompClsBridge<_userComponentClass>::init); \ | |
1129 | BT_PLUGIN_SINK_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID( \ | |
1130 | _pluginId, _componentClassId, \ | |
1131 | bt2::internal::SinkCompClsBridge<_userComponentClass>::finalize); \ | |
1132 | BT_PLUGIN_SINK_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_WITH_ID( \ | |
1133 | _pluginId, _componentClassId, \ | |
1134 | bt2::internal::SinkCompClsBridge<_userComponentClass>::getSupportedMipVersions); \ | |
1135 | BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD_WITH_ID( \ | |
1136 | _pluginId, _componentClassId, \ | |
1137 | bt2::internal::SinkCompClsBridge<_userComponentClass>::inputPortConnected); \ | |
1138 | BT_PLUGIN_SINK_COMPONENT_CLASS_GRAPH_IS_CONFIGURED_METHOD_WITH_ID( \ | |
1139 | _pluginId, _componentClassId, \ | |
1140 | bt2::internal::SinkCompClsBridge<_userComponentClass>::graphIsConfigured); \ | |
1141 | BT_PLUGIN_SINK_COMPONENT_CLASS_QUERY_METHOD_WITH_ID( \ | |
1142 | _pluginId, _componentClassId, \ | |
1143 | bt2::internal::SinkCompClsBridge<_userComponentClass>::query); | |
1144 | ||
1145 | #define BT_CPP_PLUGIN_SOURCE_COMPONENT_CLASS(_name, _userComponentClass, \ | |
1146 | _userMessageIteratorClass) \ | |
1147 | BT_CPP_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _userComponentClass, \ | |
1148 | _userMessageIteratorClass) | |
1149 | ||
1150 | #define BT_CPP_PLUGIN_FILTER_COMPONENT_CLASS(_name, _userComponentClass, \ | |
1151 | _userMessageIteratorClass) \ | |
1152 | BT_CPP_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _userComponentClass, \ | |
1153 | _userMessageIteratorClass) | |
1154 | ||
1155 | #define BT_CPP_PLUGIN_SINK_COMPONENT_CLASS(_name, _userComponentClass) \ | |
1156 | BT_CPP_PLUGIN_SINK_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _userComponentClass) | |
1157 | ||
1158 | #endif /* BABELTRACE_CPP_COMMON_BT2_PLUGIN_DEV_HPP */ |