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