cpp-common/bt2: make setters return `*this`
[babeltrace.git] / src / cpp-common / bt2 / self-component-port.hpp
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
12 #include <babeltrace2/babeltrace.h>
13
14 #include "logging.hpp"
15
16 #include "cpp-common/bt2c/c-string-view.hpp"
17
18 #include "borrowed-object-iterator.hpp"
19 #include "borrowed-object.hpp"
20 #include "component-port.hpp"
21 #include "message-iterator.hpp"
22
23 namespace bt2 {
24
25 class SelfSourceComponent;
26 class SelfFilterComponent;
27 class SelfSinkComponent;
28
29 class SelfComponent final : public BorrowedObject<bt_self_component>
30 {
31 public:
32 explicit SelfComponent(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
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
80 bt2c::CStringView name() const noexcept
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 SelfComponent data(T& obj) const noexcept
103 {
104 bt_self_component_set_data(this->libObjPtr(),
105 const_cast<void *>(static_cast<const void *>(&obj)));
106 return *this;
107 }
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 }
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 }
130 };
131
132 namespace internal {
133
134 template <typename LibObjT>
135 class SelfSpecificComponent : public BorrowedObject<LibObjT>
136 {
137 private:
138 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
139
140 public:
141 using typename BorrowedObject<LibObjT>::LibObjPtr;
142
143 protected:
144 explicit SelfSpecificComponent(const LibObjPtr libObjPtr) noexcept :
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
154 const auto status = func(this->libObjPtr(), name,
155 const_cast<void *>(static_cast<const void *>(data)), &libPortPtr);
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
169 public:
170 bt2c::CStringView name() const noexcept
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
191 protected:
192 SelfComponent _selfComponent() const noexcept
193 {
194 return SelfComponent {this->libObjPtr()};
195 }
196 };
197
198 template <typename LibSelfCompT, typename LibSelfCompPortPtrT>
199 struct SelfComponentPortsSpec;
200
201 template <>
202 struct 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
223 template <>
224 struct 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
245 template <>
246 struct 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
267 template <>
268 struct 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
291 template <typename LibSelfCompPortT, typename LibPortT>
292 class SelfComponentPort;
293
294 template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
295 class SelfComponentPorts final : public BorrowedObject<LibSelfCompT>
296 {
297 private:
298 using typename BorrowedObject<LibSelfCompT>::_ThisBorrowedObject;
299 using _Spec = internal::SelfComponentPortsSpec<LibSelfCompT, LibSelfCompPortT>;
300
301 public:
302 using typename BorrowedObject<LibSelfCompT>::LibObjPtr;
303 using Port = SelfComponentPort<LibSelfCompPortT, LibPortT>;
304 using Iterator = BorrowedObjectIterator<SelfComponentPorts>;
305
306 explicit SelfComponentPorts(const LibObjPtr libObjPtr) noexcept :
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;
317 Port operator[](bt2c::CStringView name) const noexcept;
318 Iterator begin() const noexcept;
319 Iterator end() const noexcept;
320 Port front() const noexcept;
321 Port back() const noexcept;
322 };
323
324 class SelfSourceComponent final : public internal::SelfSpecificComponent<bt_self_component_source>
325 {
326 using _ThisSelfSpecificComponent = internal::SelfSpecificComponent<bt_self_component_source>;
327
328 public:
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
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
352 template <typename DataT>
353 OutputPorts::Port addOutputPort(bt2c::CStringView name, DataT& data) const;
354
355 OutputPorts::Port addOutputPort(bt2c::CStringView name) const;
356
357 OutputPorts outputPorts() const noexcept;
358
359 private:
360 template <typename DataT>
361 OutputPorts::Port _addOutputPort(const char *name, DataT *data) const;
362 };
363
364 class SelfFilterComponent final : public internal::SelfSpecificComponent<bt_self_component_filter>
365 {
366 using _ThisSelfSpecificComponent = internal::SelfSpecificComponent<bt_self_component_filter>;
367
368 public:
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
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
394 template <typename DataT>
395 InputPorts::Port addInputPort(bt2c::CStringView name, DataT& data) const;
396
397 InputPorts::Port addInputPort(bt2c::CStringView name) const;
398
399 InputPorts inputPorts() const noexcept;
400
401 template <typename DataT>
402 OutputPorts::Port addOutputPort(bt2c::CStringView name, DataT& data) const;
403
404 OutputPorts::Port addOutputPort(bt2c::CStringView name) const;
405
406 OutputPorts outputPorts() const noexcept;
407
408 private:
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
416 class SelfSinkComponent final : public internal::SelfSpecificComponent<bt_self_component_sink>
417 {
418 using _ThisSelfSpecificComponent = internal::SelfSpecificComponent<bt_self_component_sink>;
419
420 public:
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
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
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>
451 InputPorts::Port addInputPort(bt2c::CStringView name, DataT& data) const;
452
453 InputPorts::Port addInputPort(bt2c::CStringView name) const;
454
455 InputPorts inputPorts() const noexcept;
456
457 private:
458 template <typename DataT>
459 InputPorts::Port _addInputPort(const char *name, DataT *data) const;
460 };
461
462 inline SelfComponent::SelfComponent(const SelfSourceComponent other) noexcept :
463 SelfComponent {other.libObjPtr()}
464 {
465 }
466
467 inline SelfComponent::SelfComponent(const SelfFilterComponent other) noexcept :
468 SelfComponent {other.libObjPtr()}
469 {
470 }
471
472 inline SelfComponent::SelfComponent(const SelfSinkComponent other) noexcept :
473 SelfComponent {other.libObjPtr()}
474 {
475 }
476
477 inline SelfComponent SelfComponent::operator=(const SelfSourceComponent other) noexcept
478 {
479 *this = SelfComponent {other.libObjPtr()};
480 return *this;
481 }
482
483 inline SelfComponent SelfComponent::operator=(const SelfFilterComponent other) noexcept
484 {
485 *this = SelfComponent {other.libObjPtr()};
486 return *this;
487 }
488
489 inline SelfComponent SelfComponent::operator=(const SelfSinkComponent other) noexcept
490 {
491 *this = SelfComponent {other.libObjPtr()};
492 return *this;
493 }
494
495 namespace internal {
496
497 template <typename LibObjT>
498 struct SelfComponentPortSpec;
499
500 /* Functions specific to self component input ports */
501 template <>
502 struct 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 */
518 template <>
519 struct 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
536 template <typename LibSelfCompPortT, typename LibPortT>
537 class SelfComponentPort final : public BorrowedObject<LibSelfCompPortT>
538 {
539 public:
540 using typename BorrowedObject<LibSelfCompPortT>::LibObjPtr;
541
542 explicit SelfComponentPort(const LibObjPtr libObjPtr) noexcept :
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
553 bt2c::CStringView name() const noexcept
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 {
571 return *static_cast<T *>(bt_self_component_port_get_data(this->_libSelfCompPortPtr()));
572 }
573
574 private:
575 bt_self_component_port *_libSelfCompPortPtr() const noexcept
576 {
577 return internal::SelfComponentPortSpec<LibSelfCompPortT>::asSelfCompPort(this->libObjPtr());
578 }
579 };
580
581 template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
582 typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
583 SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::operator[](
584 const std::uint64_t index) const noexcept
585 {
586 return Port {_Spec::portByIndex(this->libObjPtr(), index)};
587 }
588
589 template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
590 typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
591 SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::operator[](
592 const bt2c::CStringView name) const noexcept
593 {
594 return Port {_Spec::portByName(this->libObjPtr(), name)};
595 }
596
597 template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
598 typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Iterator
599 SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::begin() const noexcept
600 {
601 return Iterator {*this, 0};
602 }
603
604 template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
605 typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Iterator
606 SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::end() const noexcept
607 {
608 return Iterator {*this, this->length()};
609 }
610
611 template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
612 typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
613 SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::front() const noexcept
614 {
615 return (*this)[0];
616 }
617
618 template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
619 typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
620 SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::back() const noexcept
621 {
622 return (*this)[this->length() - 1];
623 }
624
625 using SelfComponentInputPort = SelfComponentPort<bt_self_component_port_input, const bt_port_input>;
626
627 using SelfComponentOutputPort =
628 SelfComponentPort<bt_self_component_port_output, const bt_port_output>;
629
630 template <typename DataT>
631 SelfSourceComponent::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
638 template <typename DataT>
639 SelfSourceComponent::OutputPorts::Port
640 SelfSourceComponent::addOutputPort(const bt2c::CStringView name, DataT& data) const
641 {
642 return this->_addOutputPort(name, &data);
643 }
644
645 inline SelfSourceComponent::OutputPorts::Port
646 SelfSourceComponent::addOutputPort(const bt2c::CStringView name) const
647 {
648 return this->_addOutputPort<void>(name, nullptr);
649 }
650
651 inline SelfSourceComponent::OutputPorts SelfSourceComponent::outputPorts() const noexcept
652 {
653 return OutputPorts {this->libObjPtr()};
654 }
655
656 template <typename DataT>
657 SelfFilterComponent::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
664 template <typename DataT>
665 SelfFilterComponent::OutputPorts::Port
666 SelfFilterComponent::addOutputPort(const bt2c::CStringView name, DataT& data) const
667 {
668 return this->_addOutputPort(name, &data);
669 }
670
671 inline SelfFilterComponent::OutputPorts::Port
672 SelfFilterComponent::addOutputPort(const bt2c::CStringView name) const
673 {
674 return this->_addOutputPort<void>(name, nullptr);
675 }
676
677 inline SelfFilterComponent::OutputPorts SelfFilterComponent::outputPorts() const noexcept
678 {
679 return OutputPorts {this->libObjPtr()};
680 }
681
682 template <typename DataT>
683 SelfFilterComponent::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
690 template <typename DataT>
691 SelfFilterComponent::InputPorts::Port
692 SelfFilterComponent::addInputPort(const bt2c::CStringView name, DataT& data) const
693 {
694 return this->_addInputPort(name, &data);
695 }
696
697 inline SelfFilterComponent::InputPorts::Port
698 SelfFilterComponent::addInputPort(const bt2c::CStringView name) const
699 {
700 return this->_addInputPort<void>(name, nullptr);
701 }
702
703 inline SelfFilterComponent::InputPorts SelfFilterComponent::inputPorts() const noexcept
704 {
705 return InputPorts {this->libObjPtr()};
706 }
707
708 inline MessageIterator::Shared
709 SelfSinkComponent::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:
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
728 template <typename DataT>
729 SelfSinkComponent::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
736 template <typename DataT>
737 SelfSinkComponent::InputPorts::Port SelfSinkComponent::addInputPort(const bt2c::CStringView name,
738 DataT& data) const
739 {
740 return this->_addInputPort(name, &data);
741 }
742
743 inline SelfSinkComponent::InputPorts::Port
744 SelfSinkComponent::addInputPort(const bt2c::CStringView name) const
745 {
746 return this->_addInputPort<void>(name, nullptr);
747 }
748
749 inline 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.046852 seconds and 4 git commands to generate.