X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fcpp-common%2Fbt2%2Fself-component-port.hpp;h=e2bbe80742af9a3350cebe23caf2b27c2a211316;hb=6133c94191474e358f8c0688c8f9d3f5cc323836;hp=e41dd09c8cde3d3259236861244c9f627f99f3c3;hpb=7c9d996f00a4172ab5ce40ae7f1d8506a469c03a;p=babeltrace.git diff --git a/src/cpp-common/bt2/self-component-port.hpp b/src/cpp-common/bt2/self-component-port.hpp index e41dd09c..e2bbe807 100644 --- a/src/cpp-common/bt2/self-component-port.hpp +++ b/src/cpp-common/bt2/self-component-port.hpp @@ -13,7 +13,6 @@ #include "logging.hpp" -#include "common/assert.h" #include "cpp-common/bt2c/c-string-view.hpp" #include "borrowed-object-iterator.hpp" @@ -102,10 +101,35 @@ public: template void data(T& obj) const noexcept { - bt_self_component_set_data(this->libObjPtr(), static_cast(&obj)); + bt_self_component_set_data(this->libObjPtr(), + const_cast(static_cast(&obj))); + } + + bt2::TraceClass::Shared createTraceClass() const + { + const auto libObjPtr = bt_trace_class_create(this->libObjPtr()); + + if (!libObjPtr) { + throw MemoryError {}; + } + + return bt2::TraceClass::Shared::createWithoutRef(libObjPtr); + } + + bt2::ClockClass::Shared createClockClass() const + { + const auto libObjPtr = bt_clock_class_create(this->libObjPtr()); + + if (!libObjPtr) { + throw MemoryError {}; + } + + return bt2::ClockClass::Shared::createWithoutRef(libObjPtr); } }; +namespace internal { + template class SelfSpecificComponent : public BorrowedObject { @@ -126,7 +150,8 @@ protected: { LibPortT *libPortPtr; - const auto status = func(this->libObjPtr(), name, static_cast(data), &libPortPtr); + const auto status = func(this->libObjPtr(), name, + const_cast(static_cast(data)), &libPortPtr); switch (status) { case BT_SELF_COMPONENT_ADD_PORT_STATUS_OK: @@ -175,8 +200,6 @@ private: } }; -namespace internal { - template struct SelfComponentPortsSpec; @@ -303,7 +326,7 @@ public: Port back() const noexcept; }; -class SelfSourceComponent final : public SelfSpecificComponent +class SelfSourceComponent final : public internal::SelfSpecificComponent { public: using OutputPorts = SelfComponentPorts +class SelfFilterComponent final : public internal::SelfSpecificComponent { public: using InputPorts = SelfComponentPorts +class SelfSinkComponent final : public internal::SelfSpecificComponent { public: using InputPorts = SelfComponentPorts T& data() const noexcept { - *static_cast(bt_self_component_port_get_data(this->_libSelfCompPortPtr())); + return *static_cast(bt_self_component_port_get_data(this->_libSelfCompPortPtr())); } private: @@ -664,7 +687,6 @@ SelfSinkComponent::createMessageIterator(const InputPorts::Port port) const switch (status) { case BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK: - BT_ASSERT(libMsgIterPtr); return MessageIterator::Shared::createWithoutRef(libMsgIterPtr); case BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_MEMORY_ERROR: throw MemoryError {};