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