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