cpp-common/bt2: remove redundant assertions
[babeltrace.git] / src / cpp-common / bt2 / self-component-port.hpp
CommitLineData
b6f09a6b
PP
1/*
2 * Copyright (c) 2023 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#ifndef BABELTRACE_CPP_COMMON_BT2_SELF_COMPONENT_PORT_HPP
8#define BABELTRACE_CPP_COMMON_BT2_SELF_COMPONENT_PORT_HPP
9
10#include <cstdint>
b6f09a6b
PP
11
12#include <babeltrace2/babeltrace.h>
13
14#include "logging.hpp"
15
e7f0f07b 16#include "cpp-common/bt2c/c-string-view.hpp"
b6f09a6b
PP
17
18#include "borrowed-object-iterator.hpp"
19#include "borrowed-object.hpp"
20#include "component-port.hpp"
21#include "message-iterator.hpp"
22
23namespace bt2 {
24
25class SelfSourceComponent;
26class SelfFilterComponent;
27class SelfSinkComponent;
28
29class SelfComponent final : public BorrowedObject<bt_self_component>
30{
31public:
d246c457 32 explicit SelfComponent(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
b6f09a6b
PP
33 {
34 }
35
36 explicit SelfComponent(bt_self_component_source * const libObjPtr) noexcept :
37 _ThisBorrowedObject {bt_self_component_source_as_self_component(libObjPtr)}
38 {
39 }
40
41 explicit SelfComponent(bt_self_component_filter * const libObjPtr) noexcept :
42 _ThisBorrowedObject {bt_self_component_filter_as_self_component(libObjPtr)}
43 {
44 }
45
46 explicit SelfComponent(bt_self_component_sink * const libObjPtr) noexcept :
47 _ThisBorrowedObject {bt_self_component_sink_as_self_component(libObjPtr)}
48 {
49 }
50
51 /* Not `explicit` to make them behave like copy constructors */
52 SelfComponent(SelfSourceComponent other) noexcept;
53 SelfComponent(SelfFilterComponent other) noexcept;
54 SelfComponent(SelfSinkComponent other) noexcept;
55
56 SelfComponent operator=(SelfSourceComponent other) noexcept;
57 SelfComponent operator=(SelfFilterComponent other) noexcept;
58 SelfComponent operator=(SelfSinkComponent other) noexcept;
59
60 ConstComponent asConstComponent() const noexcept
61 {
62 return ConstComponent {bt_self_component_as_component(this->libObjPtr())};
63 }
64
65 bool isSource() const noexcept
66 {
67 return this->asConstComponent().isSource();
68 }
69
70 bool isFilter() const noexcept
71 {
72 return this->asConstComponent().isFilter();
73 }
74
75 bool isSink() const noexcept
76 {
77 return this->asConstComponent().isSink();
78 }
79
e7f0f07b 80 bt2c::CStringView name() const noexcept
b6f09a6b
PP
81 {
82 return this->asConstComponent().name();
83 }
84
85 LoggingLevel loggingLevel() const noexcept
86 {
87 return this->asConstComponent().loggingLevel();
88 }
89
90 std::uint64_t graphMipVersion() const noexcept
91 {
92 return bt_self_component_get_graph_mip_version(this->libObjPtr());
93 }
94
95 template <typename T>
96 T& data() const noexcept
97 {
98 return *static_cast<T *>(bt_self_component_get_data(this->libObjPtr()));
99 }
100
101 template <typename T>
102 void data(T& obj) const noexcept
103 {
1e700b7d
SM
104 bt_self_component_set_data(this->libObjPtr(),
105 const_cast<void *>(static_cast<const void *>(&obj)));
b6f09a6b 106 }
f34d9653
SM
107
108 bt2::TraceClass::Shared createTraceClass() const
109 {
110 const auto libObjPtr = bt_trace_class_create(this->libObjPtr());
111
112 if (!libObjPtr) {
113 throw MemoryError {};
114 }
115
116 return bt2::TraceClass::Shared::createWithoutRef(libObjPtr);
117 }
f5018066
SM
118
119 bt2::ClockClass::Shared createClockClass() const
120 {
121 const auto libObjPtr = bt_clock_class_create(this->libObjPtr());
122
123 if (!libObjPtr) {
124 throw MemoryError {};
125 }
126
127 return bt2::ClockClass::Shared::createWithoutRef(libObjPtr);
128 }
b6f09a6b
PP
129};
130
131template <typename LibObjT>
132class SelfSpecificComponent : public BorrowedObject<LibObjT>
133{
134private:
135 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
136
137public:
d246c457 138 using typename BorrowedObject<LibObjT>::LibObjPtr;
b6f09a6b
PP
139
140protected:
d246c457 141 explicit SelfSpecificComponent(const LibObjPtr libObjPtr) noexcept :
b6f09a6b
PP
142 _ThisBorrowedObject {libObjPtr}
143 {
144 }
145
146 template <typename PortT, typename LibPortT, typename AddPortFuncT, typename DataT>
147 PortT _addPort(const char * const name, DataT * const data, AddPortFuncT&& func) const
148 {
149 LibPortT *libPortPtr;
150
1e700b7d
SM
151 const auto status = func(this->libObjPtr(), name,
152 const_cast<void *>(static_cast<const void *>(data)), &libPortPtr);
b6f09a6b
PP
153
154 switch (status) {
155 case BT_SELF_COMPONENT_ADD_PORT_STATUS_OK:
156 return PortT {libPortPtr};
157 case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR:
158 throw MemoryError {};
159 case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR:
160 throw Error {};
161 default:
162 bt_common_abort();
163 }
164 }
165
166public:
e7f0f07b 167 bt2c::CStringView name() const noexcept
b6f09a6b
PP
168 {
169 return this->_selfComponent().name();
170 }
171
172 LoggingLevel loggingLevel() const noexcept
173 {
174 return this->_selfComponent().loggingLevel();
175 }
176
177 std::uint64_t graphMipVersion() const noexcept
178 {
179 return this->_selfComponent().graphMipVersion();
180 }
181
182 template <typename T>
183 T& data() const noexcept
184 {
185 return this->_selfComponent().template data<T>();
186 }
187
188 template <typename T>
189 void data(T& obj) const noexcept
190 {
191 this->_selfComponent().data(obj);
192 }
193
194private:
195 SelfComponent _selfComponent() const noexcept
196 {
197 return SelfComponent {this->libObjPtr()};
198 }
199};
200
201namespace internal {
202
203template <typename LibSelfCompT, typename LibSelfCompPortPtrT>
204struct SelfComponentPortsSpec;
205
206template <>
207struct SelfComponentPortsSpec<bt_self_component_source, bt_self_component_port_output> final
208{
209 static std::uint64_t portCount(bt_self_component_source * const libCompPtr) noexcept
210 {
211 return bt_component_source_get_output_port_count(
212 bt_self_component_source_as_component_source(libCompPtr));
213 }
214
215 static bt_self_component_port_output *portByIndex(bt_self_component_source * const libCompPtr,
216 const std::uint64_t index) noexcept
217 {
218 return bt_self_component_source_borrow_output_port_by_index(libCompPtr, index);
219 }
220
221 static bt_self_component_port_output *portByName(bt_self_component_source * const libCompPtr,
222 const char * const name) noexcept
223 {
224 return bt_self_component_source_borrow_output_port_by_name(libCompPtr, name);
225 }
226};
227
228template <>
229struct SelfComponentPortsSpec<bt_self_component_filter, bt_self_component_port_output> final
230{
231 static std::uint64_t portCount(bt_self_component_filter * const libCompPtr) noexcept
232 {
233 return bt_component_filter_get_output_port_count(
234 bt_self_component_filter_as_component_filter(libCompPtr));
235 }
236
237 static bt_self_component_port_output *portByIndex(bt_self_component_filter * const libCompPtr,
238 const std::uint64_t index) noexcept
239 {
240 return bt_self_component_filter_borrow_output_port_by_index(libCompPtr, index);
241 }
242
243 static bt_self_component_port_output *portByName(bt_self_component_filter * const libCompPtr,
244 const char * const name) noexcept
245 {
246 return bt_self_component_filter_borrow_output_port_by_name(libCompPtr, name);
247 }
248};
249
250template <>
251struct SelfComponentPortsSpec<bt_self_component_filter, bt_self_component_port_input> final
252{
253 static std::uint64_t portCount(bt_self_component_filter * const libCompPtr) noexcept
254 {
255 return bt_component_filter_get_input_port_count(
256 bt_self_component_filter_as_component_filter(libCompPtr));
257 }
258
259 static bt_self_component_port_input *portByIndex(bt_self_component_filter * const libCompPtr,
260 const std::uint64_t index) noexcept
261 {
262 return bt_self_component_filter_borrow_input_port_by_index(libCompPtr, index);
263 }
264
265 static bt_self_component_port_input *portByName(bt_self_component_filter * const libCompPtr,
266 const char * const name) noexcept
267 {
268 return bt_self_component_filter_borrow_input_port_by_name(libCompPtr, name);
269 }
270};
271
272template <>
273struct SelfComponentPortsSpec<bt_self_component_sink, bt_self_component_port_input> final
274{
275 static std::uint64_t portCount(bt_self_component_sink * const libCompPtr) noexcept
276 {
277 return bt_component_sink_get_input_port_count(
278 bt_self_component_sink_as_component_sink(libCompPtr));
279 }
280
281 static bt_self_component_port_input *portByIndex(bt_self_component_sink * const libCompPtr,
282 const std::uint64_t index) noexcept
283 {
284 return bt_self_component_sink_borrow_input_port_by_index(libCompPtr, index);
285 }
286
287 static bt_self_component_port_input *portByName(bt_self_component_sink * const libCompPtr,
288 const char * const name) noexcept
289 {
290 return bt_self_component_sink_borrow_input_port_by_name(libCompPtr, name);
291 }
292};
293
294} /* namespace internal */
295
296template <typename LibSelfCompPortT, typename LibPortT>
297class SelfComponentPort;
298
299template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
300class SelfComponentPorts final : public BorrowedObject<LibSelfCompT>
301{
302private:
303 using typename BorrowedObject<LibSelfCompT>::_ThisBorrowedObject;
304 using _Spec = internal::SelfComponentPortsSpec<LibSelfCompT, LibSelfCompPortT>;
305
306public:
d246c457 307 using typename BorrowedObject<LibSelfCompT>::LibObjPtr;
b6f09a6b
PP
308 using Port = SelfComponentPort<LibSelfCompPortT, LibPortT>;
309 using Iterator = BorrowedObjectIterator<SelfComponentPorts>;
310
d246c457 311 explicit SelfComponentPorts(const LibObjPtr libObjPtr) noexcept :
b6f09a6b
PP
312 _ThisBorrowedObject {libObjPtr}
313 {
314 }
315
316 std::uint64_t length() const noexcept
317 {
318 return _Spec::portCount(this->libObjPtr());
319 }
320
321 Port operator[](std::uint64_t index) const noexcept;
15030982 322 Port operator[](bt2c::CStringView name) const noexcept;
b6f09a6b
PP
323 Iterator begin() const noexcept;
324 Iterator end() const noexcept;
325 Port front() const noexcept;
326 Port back() const noexcept;
327};
328
329class SelfSourceComponent final : public SelfSpecificComponent<bt_self_component_source>
330{
331public:
332 using OutputPorts = SelfComponentPorts<bt_self_component_source, bt_self_component_port_output,
333 const bt_port_output>;
334
335 explicit SelfSourceComponent(bt_self_component_source * const libObjPtr) noexcept :
336 SelfSpecificComponent {libObjPtr}
337 {
338 }
339
340 ConstSourceComponent asConstComponent() const noexcept
341 {
342 return ConstSourceComponent {
343 bt_self_component_source_as_component_source(this->libObjPtr())};
344 }
345
346 template <typename DataT>
15030982 347 OutputPorts::Port addOutputPort(bt2c::CStringView name, DataT& data) const;
b6f09a6b 348
15030982 349 OutputPorts::Port addOutputPort(bt2c::CStringView name) const;
b6f09a6b 350
b6f09a6b
PP
351 OutputPorts outputPorts() const noexcept;
352
353private:
354 template <typename DataT>
355 OutputPorts::Port _addOutputPort(const char *name, DataT *data) const;
356};
357
358class SelfFilterComponent final : public SelfSpecificComponent<bt_self_component_filter>
359{
360public:
361 using InputPorts = SelfComponentPorts<bt_self_component_filter, bt_self_component_port_input,
362 const bt_port_input>;
363 using OutputPorts = SelfComponentPorts<bt_self_component_filter, bt_self_component_port_output,
364 const bt_port_output>;
365
366 explicit SelfFilterComponent(bt_self_component_filter * const libObjPtr) noexcept :
367 SelfSpecificComponent {libObjPtr}
368 {
369 }
370
371 ConstFilterComponent asConstComponent() const noexcept
372 {
373 return ConstFilterComponent {
374 bt_self_component_filter_as_component_filter(this->libObjPtr())};
375 }
376
377 template <typename DataT>
15030982 378 InputPorts::Port addInputPort(bt2c::CStringView name, DataT& data) const;
b6f09a6b 379
15030982 380 InputPorts::Port addInputPort(bt2c::CStringView name) const;
b6f09a6b 381
b6f09a6b
PP
382 InputPorts inputPorts() const noexcept;
383
384 template <typename DataT>
15030982 385 OutputPorts::Port addOutputPort(bt2c::CStringView name, DataT& data) const;
b6f09a6b 386
15030982 387 OutputPorts::Port addOutputPort(bt2c::CStringView name) const;
b6f09a6b 388
b6f09a6b
PP
389 OutputPorts outputPorts() const noexcept;
390
391private:
392 template <typename DataT>
393 InputPorts::Port _addInputPort(const char *name, DataT *data) const;
394
395 template <typename DataT>
396 OutputPorts::Port _addOutputPort(const char *name, DataT *data) const;
397};
398
399class SelfSinkComponent final : public SelfSpecificComponent<bt_self_component_sink>
400{
401public:
402 using InputPorts = SelfComponentPorts<bt_self_component_sink, bt_self_component_port_input,
403 const bt_port_input>;
404
405 explicit SelfSinkComponent(bt_self_component_sink * const libObjPtr) noexcept :
406 SelfSpecificComponent {libObjPtr}
407 {
408 }
409
410 ConstSinkComponent asConstComponent() const noexcept
411 {
412 return ConstSinkComponent {bt_self_component_sink_as_component_sink(this->libObjPtr())};
413 }
414
415 MessageIterator::Shared createMessageIterator(InputPorts::Port port) const;
416
417 bool isInterrupted() const noexcept
418 {
419 return static_cast<bool>(bt_self_component_sink_is_interrupted(this->libObjPtr()));
420 }
421
422 template <typename DataT>
15030982 423 InputPorts::Port addInputPort(bt2c::CStringView name, DataT& data) const;
b6f09a6b 424
15030982 425 InputPorts::Port addInputPort(bt2c::CStringView name) const;
b6f09a6b 426
b6f09a6b
PP
427 InputPorts inputPorts() const noexcept;
428
429private:
430 template <typename DataT>
431 InputPorts::Port _addInputPort(const char *name, DataT *data) const;
432};
433
434inline SelfComponent::SelfComponent(const SelfSourceComponent other) noexcept :
435 SelfComponent {other.libObjPtr()}
436{
437}
438
439inline SelfComponent::SelfComponent(const SelfFilterComponent other) noexcept :
440 SelfComponent {other.libObjPtr()}
441{
442}
443
444inline SelfComponent::SelfComponent(const SelfSinkComponent other) noexcept :
445 SelfComponent {other.libObjPtr()}
446{
447}
448
449inline SelfComponent SelfComponent::operator=(const SelfSourceComponent other) noexcept
450{
451 *this = SelfComponent {other.libObjPtr()};
452 return *this;
453}
454
455inline SelfComponent SelfComponent::operator=(const SelfFilterComponent other) noexcept
456{
457 *this = SelfComponent {other.libObjPtr()};
458 return *this;
459}
460
461inline SelfComponent SelfComponent::operator=(const SelfSinkComponent other) noexcept
462{
463 *this = SelfComponent {other.libObjPtr()};
464 return *this;
465}
466
467namespace internal {
468
469template <typename LibObjT>
470struct SelfComponentPortSpec;
471
472/* Functions specific to self component input ports */
473template <>
474struct SelfComponentPortSpec<bt_self_component_port_input> final
475{
476 static bt_self_component_port *
477 asSelfCompPort(bt_self_component_port_input * const libObjPtr) noexcept
478 {
479 return bt_self_component_port_input_as_self_component_port(libObjPtr);
480 }
481
482 static const bt_port_input *
483 asConstPort(const bt_self_component_port_input * const libObjPtr) noexcept
484 {
485 return bt_self_component_port_input_as_port_input(libObjPtr);
486 }
487};
488
489/* Functions specific to self component output ports */
490template <>
491struct SelfComponentPortSpec<bt_self_component_port_output> final
492{
493 static bt_self_component_port *
494 asSelfCompPort(bt_self_component_port_output * const libObjPtr) noexcept
495 {
496 return bt_self_component_port_output_as_self_component_port(libObjPtr);
497 }
498
499 static const bt_port_output *
500 asConstPort(bt_self_component_port_output * const libObjPtr) noexcept
501 {
502 return bt_self_component_port_output_as_port_output(libObjPtr);
503 }
504};
505
506} /* namespace internal */
507
508template <typename LibSelfCompPortT, typename LibPortT>
509class SelfComponentPort final : public BorrowedObject<LibSelfCompPortT>
510{
511public:
d246c457 512 using typename BorrowedObject<LibSelfCompPortT>::LibObjPtr;
b6f09a6b 513
d246c457 514 explicit SelfComponentPort(const LibObjPtr libObjPtr) noexcept :
b6f09a6b
PP
515 BorrowedObject<LibSelfCompPortT> {libObjPtr}
516 {
517 }
518
519 ConstPort<LibPortT> asConstPort() const noexcept
520 {
521 return ConstPort<LibPortT> {
522 internal::SelfComponentPortSpec<LibSelfCompPortT>::asConstPort(this->libObjPtr())};
523 }
524
e7f0f07b 525 bt2c::CStringView name() const noexcept
b6f09a6b
PP
526 {
527 return this->asConstPort().name();
528 }
529
530 bool isConnected() const noexcept
531 {
532 return this->asConstPort().isConnected();
533 }
534
535 SelfComponent component() const noexcept
536 {
537 return SelfComponent {bt_self_component_port_borrow_component(this->_libSelfCompPortPtr())};
538 }
539
540 template <typename T>
541 T& data() const noexcept
542 {
421aa729 543 return *static_cast<T *>(bt_self_component_port_get_data(this->_libSelfCompPortPtr()));
b6f09a6b
PP
544 }
545
546private:
547 bt_self_component_port *_libSelfCompPortPtr() const noexcept
548 {
549 return internal::SelfComponentPortSpec<LibSelfCompPortT>::asSelfCompPort(this->libObjPtr());
550 }
551};
552
553template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
554typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
555SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::operator[](
556 const std::uint64_t index) const noexcept
557{
558 return Port {_Spec::portByIndex(this->libObjPtr(), index)};
559}
560
561template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
562typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
563SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::operator[](
15030982 564 const bt2c::CStringView name) const noexcept
b6f09a6b
PP
565{
566 return Port {_Spec::portByName(this->libObjPtr(), name)};
567}
568
b6f09a6b
PP
569template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
570typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Iterator
571SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::begin() const noexcept
572{
573 return Iterator {*this, 0};
574}
575
576template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
577typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Iterator
578SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::end() const noexcept
579{
580 return Iterator {*this, this->length()};
581}
582
583template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
584typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
585SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::front() const noexcept
586{
587 return (*this)[0];
588}
589
590template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
591typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
592SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::back() const noexcept
593{
594 return (*this)[this->length() - 1];
595}
596
597using SelfComponentInputPort = SelfComponentPort<bt_self_component_port_input, const bt_port_input>;
598
599using SelfComponentOutputPort =
600 SelfComponentPort<bt_self_component_port_output, const bt_port_output>;
601
602template <typename DataT>
603SelfSourceComponent::OutputPorts::Port SelfSourceComponent::_addOutputPort(const char * const name,
604 DataT * const data) const
605{
606 return this->_addPort<SelfSourceComponent::OutputPorts::Port, bt_self_component_port_output>(
607 name, data, bt_self_component_source_add_output_port);
608}
609
610template <typename DataT>
15030982
SM
611SelfSourceComponent::OutputPorts::Port
612SelfSourceComponent::addOutputPort(const bt2c::CStringView name, DataT& data) const
b6f09a6b
PP
613{
614 return this->_addOutputPort(name, &data);
615}
616
617inline SelfSourceComponent::OutputPorts::Port
15030982 618SelfSourceComponent::addOutputPort(const bt2c::CStringView name) const
b6f09a6b
PP
619{
620 return this->_addOutputPort<void>(name, nullptr);
621}
622
b6f09a6b
PP
623inline SelfSourceComponent::OutputPorts SelfSourceComponent::outputPorts() const noexcept
624{
625 return OutputPorts {this->libObjPtr()};
626}
627
628template <typename DataT>
629SelfFilterComponent::OutputPorts::Port SelfFilterComponent::_addOutputPort(const char * const name,
630 DataT * const data) const
631{
632 return this->_addPort<SelfFilterComponent::OutputPorts::Port, bt_self_component_port_output>(
633 name, data, bt_self_component_filter_add_output_port);
634}
635
636template <typename DataT>
15030982
SM
637SelfFilterComponent::OutputPorts::Port
638SelfFilterComponent::addOutputPort(const bt2c::CStringView name, DataT& data) const
b6f09a6b
PP
639{
640 return this->_addOutputPort(name, &data);
641}
642
643inline SelfFilterComponent::OutputPorts::Port
15030982 644SelfFilterComponent::addOutputPort(const bt2c::CStringView name) const
b6f09a6b
PP
645{
646 return this->_addOutputPort<void>(name, nullptr);
647}
648
b6f09a6b
PP
649inline SelfFilterComponent::OutputPorts SelfFilterComponent::outputPorts() const noexcept
650{
651 return OutputPorts {this->libObjPtr()};
652}
653
654template <typename DataT>
655SelfFilterComponent::InputPorts::Port SelfFilterComponent::_addInputPort(const char * const name,
656 DataT * const data) const
657{
658 return this->_addPort<SelfFilterComponent::InputPorts::Port, bt_self_component_port_input>(
659 name, data, bt_self_component_filter_add_input_port);
660}
661
662template <typename DataT>
15030982
SM
663SelfFilterComponent::InputPorts::Port
664SelfFilterComponent::addInputPort(const bt2c::CStringView name, DataT& data) const
b6f09a6b
PP
665{
666 return this->_addInputPort(name, &data);
667}
668
669inline SelfFilterComponent::InputPorts::Port
15030982 670SelfFilterComponent::addInputPort(const bt2c::CStringView name) const
b6f09a6b
PP
671{
672 return this->_addInputPort<void>(name, nullptr);
673}
674
b6f09a6b
PP
675inline SelfFilterComponent::InputPorts SelfFilterComponent::inputPorts() const noexcept
676{
677 return InputPorts {this->libObjPtr()};
678}
679
680inline MessageIterator::Shared
681SelfSinkComponent::createMessageIterator(const InputPorts::Port port) const
682{
683 bt_message_iterator *libMsgIterPtr = nullptr;
684
685 const auto status = bt_message_iterator_create_from_sink_component(
686 this->libObjPtr(), port.libObjPtr(), &libMsgIterPtr);
687
688 switch (status) {
689 case BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK:
b6f09a6b
PP
690 return MessageIterator::Shared::createWithoutRef(libMsgIterPtr);
691 case BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_MEMORY_ERROR:
692 throw MemoryError {};
693 case BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_ERROR:
694 throw Error {};
695 default:
696 bt_common_abort();
697 }
698}
699
700template <typename DataT>
701SelfSinkComponent::InputPorts::Port SelfSinkComponent::_addInputPort(const char * const name,
702 DataT * const data) const
703{
704 return this->_addPort<SelfSinkComponent::InputPorts::Port, bt_self_component_port_input>(
705 name, data, bt_self_component_sink_add_input_port);
706}
707
708template <typename DataT>
15030982 709SelfSinkComponent::InputPorts::Port SelfSinkComponent::addInputPort(const bt2c::CStringView name,
b6f09a6b
PP
710 DataT& data) const
711{
712 return this->_addInputPort(name, &data);
713}
714
715inline SelfSinkComponent::InputPorts::Port
15030982 716SelfSinkComponent::addInputPort(const bt2c::CStringView name) const
b6f09a6b
PP
717{
718 return this->_addInputPort<void>(name, nullptr);
719}
720
b6f09a6b
PP
721inline SelfSinkComponent::InputPorts SelfSinkComponent::inputPorts() const noexcept
722{
723 return InputPorts {this->libObjPtr()};
724}
725
726} /* namespace bt2 */
727
728#endif /* BABELTRACE_CPP_COMMON_BT2_SELF_COMPONENT_PORT_HPP */
This page took 0.055298 seconds and 4 git commands to generate.