31#ifndef DW_FRAMEWORK_MANAGEDPORT_HPP_
32#define DW_FRAMEWORK_MANAGEDPORT_HPP_
38#include <dwshared/dwfoundation/dw/core/language/Optional.hpp>
39#include <dwshared/dwfoundation/dw/core/container/RingBuffer.hpp>
40#include <dwshared/dwfoundation/dw/core/language/Function.hpp>
83 virtual bool isBound() const noexcept = 0;
122 static constexpr char LOG_TAG[]{
"ManagedPortOutputBase"};
134 bool syncEnabled =
false;
175 void setCallbackBeforeSend(
dw::core::Function<dwStatus()> callback);
196 void sendAdvTimestamp();
209 dw::core::Function<dwStatus()> m_callbackBeforeSend;
210 uint32_t m_sendSeqNum;
226 uint32_t maxBuffers = 1U;
232 dwTime_t waitTime = 0;
246 bool enableReuse =
false;
251 bool syncEnabled =
false;
256 uint32_t dataOffset = 0U;
303 bool isBufferAvailable() const noexcept;
318 void setCallbackAfterRecv(
dw::core::Function<dwStatus()> callback);
329 void sendAdvTimestamp();
335 void releaseToChannel(
void* data);
339 bool recvSingle(dwTime_t waitTime);
340 bool stashConsumed();
342 void handleReuseDrop();
344 void releaseSingle();
345 bool postProcessLockstepReplayData(
GenericData packet);
346 dwTime_t getWaitTime();
349 void handleWaitFailure(dwStatus status);
350 void handleCallbackAfterRecv();
355 bool m_shouldDropFirstBuffer;
356 dw::core::Function<dwStatus()> m_callbackAfterRecv;
372 T* ptr{metadataPacket->
data.template getData<T>()};
376 throw ExceptionWithStatus(DW_INVALID_ARGUMENT,
"getBufferTyped: type mismatch");
385 explicit vectorIterable(dw::core::VectorFixed<GenericData> allBuffers)
386 : m_allBuffers(std::move(allBuffers))
394 class iterator :
public dw::core::VectorFixed<GenericData>::iterator
397 using Base = dw::core::VectorFixed<GenericData>::iterator;
400 iterator(Base&& base)
405 const Base& baseFromThis()
const
410 auto operator*()
const
413 return getBufferTyped<TT>(buffer);
418 iterator<T> begin() {
return iterator<T>(m_allBuffers.begin()); }
421 iterator<T> end() {
return iterator<T>(m_allBuffers.end()); }
424 iterator<const T> begin()
const {
return iterator<const T>(m_allBuffers.begin()); }
427 iterator<const T> end()
const {
return iterator<const T>(m_allBuffers.end()); }
430 dw::core::VectorFixed<GenericData> m_allBuffers;
442 "Channel packet type not declared. Ensure channel packet type "
443 "handling is declared with DWFRAMEWORK_DECLARE_PACKET_TYPE_POD "
444 "or DWFRAMEWORK_DECLARE_PACKET_TYPE_RELATION");
491 return detail::vectorIterable<T>(getAllBuffers());
501 return detail::getBufferTyped<T>(getBufferGeneric());
512 "Channel packet type not declared. Ensure channel packet type "
513 "handling is declared with DWFRAMEWORK_DECLARE_PACKET_TYPE_POD "
514 "or DWFRAMEWORK_DECLARE_PACKET_TYPE_RELATION");
518 struct PacketDeleter;
545 return detail::vectorIterable<T>(getAllBuffers());
555 return iterable(*
this);
565 return detail::getBufferTyped<T>(getBufferGeneric());
576 return isBufferAvailable() ? getBuffer() :
nullptr;
584 T* ptr{detail::getBufferTyped<T>(packet)};
592 void operator()(T* p)
594 static_cast<void>(p);
595 port->releaseToChannel(releasePtr);
597 ManagedPortInput* port;
603 explicit iterable(ManagedPortInput<T>& port)
612 class iterator :
public ManagedPortInputBase::RingBuffer::iterator
614 using Base = ManagedPortInputBase::RingBuffer::iterator;
620 : Base(std::move(base))
633 return detail::getBufferTyped<TT>(buffer);
641 iterator<T> begin() {
return iterator<T>(m_port.m_buffers.begin(), m_port); }
644 iterator<T> end() {
return iterator<T>(m_port.m_buffers.end(), m_port); }
647 iterator<const T> begin()
const {
return iterator<const T>(m_port.m_buffers.begin(), m_port); }
650 iterator<const T> end()
const {
return iterator<const T>(m_port.m_buffers.end(), m_port); }
653 ManagedPortInput<T>& m_port;
void * getPointer() const
ManagedPortBase & operator=(ManagedPortBase &&other)=delete
virtual bool isBound() const noexcept=0
virtual ~ManagedPortBase()=default
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
void bindLockstepSyncClient(dw::framework::lockstep::ILockstepSyncClient *syncClient)
dw::framework::lockstep::ILockstepSyncClient * m_lockstepSyncClient
void setCycleCount(uint32_t cycleCount)
void setPeriod(uint32_t period)
ConstructProperties constructProperties
BoundProperties boundProperties
bool isBufferAvailable() const noexcept
ManagedPortOutput(ConstructProperties props)
ManagedPortOutput(SpecimenT &ref)
ManagedPortOutput(ConstructProperties props, SpecimenT &ref)
static GenericDataReference make_specimen(typename parameter_traits< T >::SpecimenT *specimen)
MetadataPayload * extractMetadata(GenericData packet)
constexpr ChannelPacketTypeID DWFRAMEWORK_PACKET_ID_DEFAULT
typename ManagedPortInput< T >::UniquePacketPtr UniquePacketPtr