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