31#ifndef DW_FRAMEWORK_MANAGEDPORT_HPP_
32#define DW_FRAMEWORK_MANAGEDPORT_HPP_
39#include <dwshared/dwfoundation/dw/core/language/Optional.hpp>
40#include <dwshared/dwfoundation/dw/core/container/RingBuffer.hpp>
41#include <dwshared/dwfoundation/dw/core/container/StringView.hpp>
42#include <dwshared/dwfoundation/dw/core/language/Function.hpp>
47#include <fiu/FaultRegistry.hpp>
89 virtual bool isBound() const noexcept = 0;
98 virtual
void setNodeName(const
dw::core::StringView& nodeName) noexcept;
142 static constexpr char LOG_TAG[]{
"ManagedPortOutputBase"};
154 bool syncEnabled =
false;
195 void setCallbackBeforeSend(
dw::core::Function<dwStatus()> callback);
216 void sendAdvTimestamp();
231 dw::core::Function<dwStatus()> m_callbackBeforeSend;
232 uint32_t m_sendSeqNum;
233 std::type_index m_typeIndex;
234 bool m_isNvsci{
false};
250 uint32_t maxBuffers = 1U;
256 dwTime_t waitTime = 0;
270 bool enableReuse =
false;
275 bool syncEnabled =
false;
280 uint32_t dataOffset = 0U;
327 bool isBufferAvailable() const noexcept;
342 void setCallbackAfterRecv(
dw::core::Function<dwStatus()> callback);
353 void sendAdvTimestamp();
359 void releaseToChannel(
void* data);
363 bool recvSingle(dwTime_t waitTime);
364 bool stashConsumed();
366 void handleReuseDrop();
368 void releaseSingle();
369 bool postProcessLockstepReplayData(
GenericData packet);
370 dwTime_t getWaitTime();
373 void handleWaitFailure(dwStatus status);
374 void handleCallbackAfterRecv();
379 bool m_shouldDropFirstBuffer;
380 dw::core::Function<dwStatus()> m_callbackAfterRecv;
395 "Channel packet type not declared. Ensure channel packet type "
396 "handling is declared with DWFRAMEWORK_DECLARE_PACKET_TYPE_POD "
397 "or DWFRAMEWORK_DECLARE_PACKET_TYPE_RELATION");
449 return detail::vectorIterable<T>(getAllBuffers());
459 return detail::getBufferTyped<T>(getBufferGeneric());
470 "Channel packet type not declared. Ensure channel packet type "
471 "handling is declared with DWFRAMEWORK_DECLARE_PACKET_TYPE_POD "
472 "or DWFRAMEWORK_DECLARE_PACKET_TYPE_RELATION");
476 struct PacketDeleter;
505 return detail::vectorIterable<T>(getAllBuffers());
525 return detail::getBufferTyped<T>(getBufferGeneric());
535 if (isBufferAvailable())
537 const dw::core::Optional<dwValidityStatus> valid{
getValidityStatus(getMetadata())};
540 const bool isValid{!valid.has_value() || (DW_VALIDITY_VALID == valid->validity)};
557 return isBufferAvailable() ? getBuffer() :
nullptr;
565 T* ptr{detail::getBufferTyped<T>(packet)};
581 class iterator :
public ManagedPortInputBase::RingBuffer::iterator
583 using Base = ManagedPortInputBase::RingBuffer::iterator;
589 : Base(std::move(base))
602 return detail::getBufferTyped<TT>(buffer);
628 void operator()(T* p)
630 static_cast<void>(p);
633 ManagedPortInput* port;
647 uint64_t DescriptorIndex>
648struct IsOutputNonPOD : std::integral_constant<bool, Direction == PortDirection::OUTPUT && parameter_traits<decltype(portDescriptorType<NodeT, Direction, DescriptorIndex>())>::PacketTID != DWFRAMEWORK_PACKET_ID_DEFAULT>
651 static_assert(DescriptorIndex < portDescriptorSize<NodeT, Direction>(),
"Invalid PortIndex.");
657 uint64_t DescriptorIndex>
658typename std::enable_if<
659 !IsOutputNonPOD<NodeT, Direction, DescriptorIndex>::value,
662 createPortSpecimenByStaticIndex()
664 GenericDataReference ref{make_specimen<decltype(portDescriptorType<NodeT, Direction, DescriptorIndex>())>(
nullptr)};
672 uint64_t DescriptorIndex>
673typename std::enable_if<
674 IsOutputNonPOD<NodeT, Direction, DescriptorIndex>::value,
677 createPortSpecimenByStaticIndex()
679 throw ExceptionWithStatus(DW_NOT_SUPPORTED,
"createPortSpecimenByStaticIndex: Non POD output port is not supported");
688 createPortSpecimenImpl(
size_t descriptorIndex, std::index_sequence<Idx...>)
690 constexpr size_t ArraySize{
sizeof...(Idx)};
694 std::array<GenericDataReference, ArraySize> specimens{
698 throw ExceptionWithStatus(DW_OUT_OF_BOUNDS,
"createPortSpecimenImpl: index out of bound.");
710 createPortSpecimenImpl(
size_t descriptorIndex, std::index_sequence<Idx...>)
712 constexpr size_t ArraySize{
sizeof...(Idx)};
715 return createPortSpecimenByStaticIndex<NodeT, Direction, 0>();
717 throw ExceptionWithStatus(DW_OUT_OF_BOUNDS,
"createPortSpecimenImpl: index out of bound.");
726 createPortSpecimenImpl(
size_t, std::index_sequence<Idx...>)
728 throw ExceptionWithStatus(DW_OUT_OF_BOUNDS,
"createPortSpecimenImpl: index out of bound.");
737 return detail::createPortSpecimenImpl<NodeT, Direction>(
739 std::make_index_sequence<portDescriptorSize<NodeT, Direction>()>{});
void * getPointer() const
dw::core::StringView m_name
The unique name within set of ports with the same direction.
ManagedPortBase & operator=(ManagedPortBase &&other)=delete
virtual bool isBound() const noexcept=0
FI_DECLARE_INSTANCE_SET_HANDLE(m_fiHandle)
virtual ~ManagedPortBase()=default
const dw::core::StringView & getNodeName() const
Get the name of the node this port belongs to.
virtual void setNodeName(const dw::core::StringView &nodeName) noexcept
Set the name of the node this port belongs to.
ManagedPortBase(const ManagedPortBase &other)=delete
virtual void bindChannel(ChannelObject *channel)=0
ChannelObject * getChannel()
ChannelObject * m_channel
ManagedPortBase(ManagedPortBase &&other)=delete
ManagedPortBase & operator=(const ManagedPortBase &other)=delete
const dw::core::StringView & getName() const
Get the name of the port.
void bindLockstepSyncClient(dw::framework::lockstep::ILockstepSyncClient *syncClient)
dw::framework::lockstep::ILockstepSyncClient * m_lockstepSyncClient
ManagedPortBase(const dw::core::StringView &name)
dw::core::StringView m_nodeName
The name of the node this port belongs to.
void setCycleCount(uint32_t cycleCount)
void setPeriod(uint32_t period)
ConstructProperties constructProperties
BoundProperties boundProperties
bool isBufferAvailable() const noexcept
ManagedPortOutput(const dw::core::StringView &name, SpecimenT &ref)
ManagedPortOutput(const dw::core::StringView &name, ConstructProperties props)
ManagedPortOutput(const dw::core::StringView &name)
ManagedPortOutput(const dw::core::StringView &name, ConstructProperties props, SpecimenT &ref)
detail::vectorIterable< T > getAllBufferIter()
static constexpr const uint32_t DWFRAMEWORK_METADATA_PACKET_TYPE_ID_OFFSET
static GenericDataReference make_specimen(typename parameter_traits< T >::SpecimenT *specimen)
ChannelPacketTypeID packetTypeID
The ID of the type of the endpoint.
dw::core::Optional< dwValidityStatus > getValidityStatus(ChannelMetadata const &header)
uint32_t ChannelPacketTypeID
constexpr ChannelPacketTypeID DWFRAMEWORK_PACKET_ID_DEFAULT
typename ManagedPortInput< T >::UniquePacketPtr UniquePacketPtr
constexpr size_t descriptorIndex()