31#ifndef DW_FRAMEWORK_PORT_H_
32#define DW_FRAMEWORK_PORT_H_
35#include <dw/core/base/Exception.hpp>
36#include <dw/core/logger/Logger.hpp>
97 static_assert(std::is_copy_constructible<SpecimenT>::value,
"SpecimenT is not copy constructible");
99 static constexpr char LOG_TAG[] =
"PortOutput";
106 uint32_t m_sendSeqNum{};
114 : m_reference(std::move(ref))
122 , m_waiterAttrs(waiterAttrs)
123 , m_signalerAttrs(signalerAttrs)
130 auto ref = make_specimen<T>(&m_reference);
136 return Exception::guard([&] {
141 DW_LOGE <<
"PortOutput: bindChannel: attempted to bind the same port twice, ignoring this bind!" << Logger::State::endl;
144 if (channel ==
nullptr)
146 throw ExceptionWithStatus(DW_INVALID_ARGUMENT,
"PortOutput: bindChannel: expected channel != nullptr");
155 if (m_channelProducer ==
nullptr)
157 throw ExceptionWithStatus(DW_INTERNAL_ERROR,
"PortOutput bindChannel: wrong channel implementations returned.");
160 dw::core::Logger::Verbosity::DEBUG);
167 throw ExceptionWithStatus(DW_NOT_AVAILABLE,
"PortOutput: setOnDataReady: no bound channel");
174 return (m_channelProducer !=
nullptr);
177 dwStatus
wait(dwTime_t timeout)
181 throw ExceptionWithStatus(DW_NOT_AVAILABLE,
"PortInput: wait: no bound channel");
184 return m_channelProducer->
wait(timeout);
191 dwStatus status = DW_FAILURE;
193 if (m_channelProducer)
195 status = m_channelProducer->
get(&genericData);
198 if (status != DW_SUCCESS)
208 virtual dwStatus
send(T* frame)
210 if (!m_channelProducer)
212 throw ExceptionWithStatus(DW_NOT_AVAILABLE,
"PortOutput: channel not bound");
217 return m_channelProducer->
send(payload);
222 if (!m_channelProducer)
224 throw ExceptionWithStatus(DW_NOT_AVAILABLE,
"PortOutput: channel not bound");
233 if (!m_channelProducer)
235 throw ExceptionWithStatus(DW_NOT_AVAILABLE,
"PortOutput: channel not bound");
247 if (!m_channelProducer)
249 throw ExceptionWithStatus(DW_NOT_AVAILABLE,
"PortOutput: channel not bound");
289 "Channel packet type not declared. Ensure channel packet type "
290 "handling is declared with DWFRAMEWORK_DECLARE_PACKET_TYPE_RELATION");
292 static constexpr char LOG_TAG[] =
"PortInput";
300 static_assert(std::is_copy_constructible<SpecimenT>::value,
"SpecimenT is not copy constructible");
307 : m_reference(std::move(ref))
317 : m_waiterAttrs(waiterAttrs)
318 , m_signalerAttrs(signalerAttrs)
326 , m_waiterAttrs(waiterAttrs)
327 , m_signalerAttrs(signalerAttrs)
336 return Exception::guard([&] {
341 DW_LOGE <<
"PortInput: bindChannel: attempted to bind the same port twice, ignoring this bind!" << Logger::State::endl;
344 if (channel ==
nullptr)
346 throw ExceptionWithStatus(DW_INVALID_ARGUMENT,
"PortInput: bindChannel: expected channel != nullptr");
351 auto ref = make_specimen<T>(
nullptr);
355 ref = make_specimen<T>(&m_reference.value());
359 ref.setWaiterAttributes = m_waiterAttrs;
360 ref.setSignalerAttributes = m_signalerAttrs;
363 if (m_channelConsumer ==
nullptr)
365 throw ExceptionWithStatus(DW_INTERNAL_ERROR,
"PortInput bindChannel: wrong channel implementations returned.");
369 dw::core::Logger::Verbosity::DEBUG);
374 return !(m_channelConsumer ==
nullptr);
381 throw ExceptionWithStatus(DW_NOT_AVAILABLE,
"PortInput: setOnDataReady: no bound channel");
387 dwStatus
wait(dwTime_t timeout)
391 throw ExceptionWithStatus(DW_NOT_AVAILABLE,
"PortInput: wait: no bound channel");
403 return DW_NOT_AVAILABLE;
410 dwTime_t waitTime = m_last ? 0 : timeout;
411 dwStatus status = m_channelConsumer->
wait(waitTime);
412 if (m_last && (status == DW_TIME_OUT || status == DW_NOT_AVAILABLE))
421 virtual std::shared_ptr<T>
recv()
424 std::shared_ptr<T> result;
430 T* typedData =
nullptr;
431 void* releasePtr =
nullptr;
437 releasePtr = data.getPointer();
447 dwStatus status = m_channelConsumer->
recv(&data);
448 if (status != DW_SUCCESS)
450 if (m_last !=
nullptr)
459 releasePtr = data.getPointer();
476 auto* channelConsumer = m_channelConsumer;
477 result = std::shared_ptr<T>(typedData, [channelConsumer, releasePtr](T*) {
478 channelConsumer->release(releasePtr);
490 if (!m_channelConsumer)
492 throw ExceptionWithStatus(DW_NOT_AVAILABLE,
"PortInput: channel not bound");
501 if (!m_channelConsumer)
503 throw ExceptionWithStatus(DW_NOT_AVAILABLE,
"PortInput: channel not bound");
515 if (!m_channelConsumer)
517 throw ExceptionWithStatus(DW_NOT_AVAILABLE,
"PortInput: channel not bound");
530 std::shared_ptr<T> m_last{};
531 dw::core::Optional<SpecimenT> m_reference{};
537constexpr char PortInput<T>::LOG_TAG[];
virtual dwStatus recv(GenericData *data)=0
virtual dwStatus wait(dwTime_t timeout)=0
virtual void setOnDataReady(void *opaque, OnDataReady onDataReady)=0
dw::core::Function< void()> OnDataReady
SyncWaiter & getSyncWaiter()
SyncSignaler & getSyncSignaler()
virtual dwStatus get(GenericData *data)=0
virtual dwStatus send(void *data)=0
virtual void setSignalFences(void *data, dw::core::span< const NvSciSyncFence > postFences)=0
virtual void getWaitFences(void *data, dw::core::span< NvSciSyncFence > &waitFences)=0
virtual Producer * getProducer(GenericDataReference ref)=0
virtual const ChannelParams & getParams() const =0
virtual Consumer * getConsumer(GenericDataReference ref)=0
bool getReuseEnabled() const
virtual ~PortBase()=default
dwStatus wait(dwTime_t timeout)
static constexpr char LOG_TAG[]
dwStatus bindChannelWithReference(ChannelObject *channel, GenericDataReference &ref)
ChannelMetadata & getMetadata(T *frame)
dwStatus bindChannel(ChannelObject *channel) override
void setOnDataReady(void *opaque, ChannelObject::PacketPool::OnDataReady onDataReady)
PortOutput(SpecimenT const &ref)
typename parameter_traits< T >::SpecimenT SpecimenT
ChannelObject::SyncSignaler & getSyncSignaler()
void populateDefaultMetadata(ChannelMetadata &header)
PortOutput(SpecimenT const &ref, OnSetSyncAttrs signalerAttrs, OnSetSyncAttrs waiterAttrs={})
void setSignalFences(T *frame, dw::core::span< NvSciSyncFence > fences)
ChannelObject::SyncWaiter & getSyncWaiter()
void getWaitFences(T *frame, dw::core::span< NvSciSyncFence > fences)
static constexpr PortDirection DIRECTION
PortOutput(SpecimenT &&ref)
virtual dwStatus send(T *frame)
ChannelObject * m_channel
virtual dwStatus bindChannel(ChannelObject *channel)=0
virtual dwStatus initialize()
virtual ChannelObject * getChannel()
T * extractInternalPacket(GenericData genericData)
void parseDataSynced(const ChannelParams ¶ms) override
MetadataPayload * getMetadataPacket(T *frame)
MetadataPayload * extractMetadata(GenericData packet)
dw::core::Function< void(NvSciSyncAttrList)> OnSetSyncAttrs
OnSetSyncAttrs setSignalerAttributes
lambda to set the signaler attributes of the endpoint.
ChannelPacketTypeID packetTypeID
The ID of the type of the endpoint.
OnSetSyncAttrs setWaiterAttributes
lambda to set the waiter attributes of the endpoint.
@ METADATA_ITERATION_COUNT
ChannelPacketTypeID getNewPacketID(ChannelPacketTypeID packetTypeID)
void stampSyncCount(uint32_t &syncCountOut) const