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