cpp-common/bt2c: add `bt2c::CStringView`
[babeltrace.git] / src / cpp-common / bt2 / self-component-port.hpp
CommitLineData
b6f09a6b
PP
1/*
2 * Copyright (c) 2023 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#ifndef BABELTRACE_CPP_COMMON_BT2_SELF_COMPONENT_PORT_HPP
8#define BABELTRACE_CPP_COMMON_BT2_SELF_COMPONENT_PORT_HPP
9
10#include <cstdint>
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
24namespace bt2 {
25
26class SelfSourceComponent;
27class SelfFilterComponent;
28class SelfSinkComponent;
29
30class SelfComponent final : public BorrowedObject<bt_self_component>
31{
32public:
d246c457 33 explicit SelfComponent(const LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
b6f09a6b
PP
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
109template <typename LibObjT>
110class SelfSpecificComponent : public BorrowedObject<LibObjT>
111{
112private:
113 using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
114
115public:
d246c457 116 using typename BorrowedObject<LibObjT>::LibObjPtr;
b6f09a6b
PP
117
118protected:
d246c457 119 explicit SelfSpecificComponent(const LibObjPtr libObjPtr) noexcept :
b6f09a6b
PP
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
143public:
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
171private:
172 SelfComponent _selfComponent() const noexcept
173 {
174 return SelfComponent {this->libObjPtr()};
175 }
176};
177
178namespace internal {
179
180template <typename LibSelfCompT, typename LibSelfCompPortPtrT>
181struct SelfComponentPortsSpec;
182
183template <>
184struct 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
205template <>
206struct 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
227template <>
228struct 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
249template <>
250struct 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
273template <typename LibSelfCompPortT, typename LibPortT>
274class SelfComponentPort;
275
276template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
277class SelfComponentPorts final : public BorrowedObject<LibSelfCompT>
278{
279private:
280 using typename BorrowedObject<LibSelfCompT>::_ThisBorrowedObject;
281 using _Spec = internal::SelfComponentPortsSpec<LibSelfCompT, LibSelfCompPortT>;
282
283public:
d246c457 284 using typename BorrowedObject<LibSelfCompT>::LibObjPtr;
b6f09a6b
PP
285 using Port = SelfComponentPort<LibSelfCompPortT, LibPortT>;
286 using Iterator = BorrowedObjectIterator<SelfComponentPorts>;
287
d246c457 288 explicit SelfComponentPorts(const LibObjPtr libObjPtr) noexcept :
b6f09a6b
PP
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
307class SelfSourceComponent final : public SelfSpecificComponent<bt_self_component_source>
308{
309public:
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
335private:
336 template <typename DataT>
337 OutputPorts::Port _addOutputPort(const char *name, DataT *data) const;
338};
339
340class SelfFilterComponent final : public SelfSpecificComponent<bt_self_component_filter>
341{
342public:
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
381private:
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
389class SelfSinkComponent final : public SelfSpecificComponent<bt_self_component_sink>
390{
391public:
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
423private:
424 template <typename DataT>
425 InputPorts::Port _addInputPort(const char *name, DataT *data) const;
426};
427
428inline SelfComponent::SelfComponent(const SelfSourceComponent other) noexcept :
429 SelfComponent {other.libObjPtr()}
430{
431}
432
433inline SelfComponent::SelfComponent(const SelfFilterComponent other) noexcept :
434 SelfComponent {other.libObjPtr()}
435{
436}
437
438inline SelfComponent::SelfComponent(const SelfSinkComponent other) noexcept :
439 SelfComponent {other.libObjPtr()}
440{
441}
442
443inline SelfComponent SelfComponent::operator=(const SelfSourceComponent other) noexcept
444{
445 *this = SelfComponent {other.libObjPtr()};
446 return *this;
447}
448
449inline SelfComponent SelfComponent::operator=(const SelfFilterComponent other) noexcept
450{
451 *this = SelfComponent {other.libObjPtr()};
452 return *this;
453}
454
455inline SelfComponent SelfComponent::operator=(const SelfSinkComponent other) noexcept
456{
457 *this = SelfComponent {other.libObjPtr()};
458 return *this;
459}
460
461namespace internal {
462
463template <typename LibObjT>
464struct SelfComponentPortSpec;
465
466/* Functions specific to self component input ports */
467template <>
468struct 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 */
484template <>
485struct 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
502template <typename LibSelfCompPortT, typename LibPortT>
503class SelfComponentPort final : public BorrowedObject<LibSelfCompPortT>
504{
505public:
d246c457 506 using typename BorrowedObject<LibSelfCompPortT>::LibObjPtr;
b6f09a6b 507
d246c457 508 explicit SelfComponentPort(const LibObjPtr libObjPtr) noexcept :
b6f09a6b
PP
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
540private:
541 bt_self_component_port *_libSelfCompPortPtr() const noexcept
542 {
543 return internal::SelfComponentPortSpec<LibSelfCompPortT>::asSelfCompPort(this->libObjPtr());
544 }
545};
546
547template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
548typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
549SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::operator[](
550 const std::uint64_t index) const noexcept
551{
552 return Port {_Spec::portByIndex(this->libObjPtr(), index)};
553}
554
555template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
556typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
557SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::operator[](
558 const char * const name) const noexcept
559{
560 return Port {_Spec::portByName(this->libObjPtr(), name)};
561}
562
563template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
564typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
565SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::operator[](
566 const std::string& name) const noexcept
567{
568 return (*this)[name.data()];
569}
570
571template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
572typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Iterator
573SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::begin() const noexcept
574{
575 return Iterator {*this, 0};
576}
577
578template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
579typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Iterator
580SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::end() const noexcept
581{
582 return Iterator {*this, this->length()};
583}
584
585template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
586typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
587SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::front() const noexcept
588{
589 return (*this)[0];
590}
591
592template <typename LibSelfCompT, typename LibSelfCompPortT, typename LibPortT>
593typename SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::Port
594SelfComponentPorts<LibSelfCompT, LibSelfCompPortT, LibPortT>::back() const noexcept
595{
596 return (*this)[this->length() - 1];
597}
598
599using SelfComponentInputPort = SelfComponentPort<bt_self_component_port_input, const bt_port_input>;
600
601using SelfComponentOutputPort =
602 SelfComponentPort<bt_self_component_port_output, const bt_port_output>;
603
604template <typename DataT>
605SelfSourceComponent::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
612template <typename DataT>
613SelfSourceComponent::OutputPorts::Port SelfSourceComponent::addOutputPort(const char * const name,
614 DataT& data) const
615{
616 return this->_addOutputPort(name, &data);
617}
618
619inline SelfSourceComponent::OutputPorts::Port
620SelfSourceComponent::addOutputPort(const char * const name) const
621{
622 return this->_addOutputPort<void>(name, nullptr);
623}
624
625template <typename DataT>
626SelfSourceComponent::OutputPorts::Port SelfSourceComponent::addOutputPort(const std::string& name,
627 DataT& data) const
628{
629 return this->_addOutputPort(name.data(), &data);
630}
631
632inline SelfSourceComponent::OutputPorts::Port
633SelfSourceComponent::addOutputPort(const std::string& name) const
634{
635 return this->_addOutputPort<void>(name.data(), nullptr);
636}
637
638inline SelfSourceComponent::OutputPorts SelfSourceComponent::outputPorts() const noexcept
639{
640 return OutputPorts {this->libObjPtr()};
641}
642
643template <typename DataT>
644SelfFilterComponent::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
651template <typename DataT>
652SelfFilterComponent::OutputPorts::Port SelfFilterComponent::addOutputPort(const char * const name,
653 DataT& data) const
654{
655 return this->_addOutputPort(name, &data);
656}
657
658inline SelfFilterComponent::OutputPorts::Port
659SelfFilterComponent::addOutputPort(const char * const name) const
660{
661 return this->_addOutputPort<void>(name, nullptr);
662}
663
664template <typename DataT>
665SelfFilterComponent::OutputPorts::Port SelfFilterComponent::addOutputPort(const std::string& name,
666 DataT& data) const
667{
668 return this->_addOutputPort(name.data(), &data);
669}
670
671inline SelfFilterComponent::OutputPorts::Port
672SelfFilterComponent::addOutputPort(const std::string& name) const
673{
674 return this->_addOutputPort<void>(name.data(), nullptr);
675}
676
677inline SelfFilterComponent::OutputPorts SelfFilterComponent::outputPorts() const noexcept
678{
679 return OutputPorts {this->libObjPtr()};
680}
681
682template <typename DataT>
683SelfFilterComponent::InputPorts::Port SelfFilterComponent::_addInputPort(const char * const name,
684 DataT * const data) const
685{
686 return this->_addPort<SelfFilterComponent::InputPorts::Port, bt_self_component_port_input>(
687 name, data, bt_self_component_filter_add_input_port);
688}
689
690template <typename DataT>
691SelfFilterComponent::InputPorts::Port SelfFilterComponent::addInputPort(const char * const name,
692 DataT& data) const
693{
694 return this->_addInputPort(name, &data);
695}
696
697inline SelfFilterComponent::InputPorts::Port
698SelfFilterComponent::addInputPort(const char * const name) const
699{
700 return this->_addInputPort<void>(name, nullptr);
701}
702
703template <typename DataT>
704SelfFilterComponent::InputPorts::Port SelfFilterComponent::addInputPort(const std::string& name,
705 DataT& data) const
706{
707 return this->_addInputPort(name.data(), &data);
708}
709
710inline SelfFilterComponent::InputPorts::Port
711SelfFilterComponent::addInputPort(const std::string& name) const
712{
713 return this->_addInputPort<void>(name.data(), nullptr);
714}
715
716inline SelfFilterComponent::InputPorts SelfFilterComponent::inputPorts() const noexcept
717{
718 return InputPorts {this->libObjPtr()};
719}
720
721inline MessageIterator::Shared
722SelfSinkComponent::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
742template <typename DataT>
743SelfSinkComponent::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
750template <typename DataT>
751SelfSinkComponent::InputPorts::Port SelfSinkComponent::addInputPort(const char * const name,
752 DataT& data) const
753{
754 return this->_addInputPort(name, &data);
755}
756
757inline SelfSinkComponent::InputPorts::Port
758SelfSinkComponent::addInputPort(const char * const name) const
759{
760 return this->_addInputPort<void>(name, nullptr);
761}
762
763template <typename DataT>
764SelfSinkComponent::InputPorts::Port SelfSinkComponent::addInputPort(const std::string& name,
765 DataT& data) const
766{
767 return this->_addInputPort(name.data(), &data);
768}
769
770inline SelfSinkComponent::InputPorts::Port
771SelfSinkComponent::addInputPort(const std::string& name) const
772{
773 return this->_addInputPort<void>(name.data(), nullptr);
774}
775
776inline 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.049491 seconds and 4 git commands to generate.