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