31#ifndef DW_FRAMEWORK_MANAGEDPORT_HPP_
32#define DW_FRAMEWORK_MANAGEDPORT_HPP_
36#include <dw/core/language/Optional.hpp>
37#include <dw/core/container/RingBuffer.hpp>
73 virtual bool isBound() const noexcept = 0;
106 bool syncEnabled =
false;
151 Properties m_props{};
152 dw::core::Optional<GenericData> m_buffer{};
168 uint32_t maxBuffers = 1U;
174 dwTime_t waitTime = 0;
188 bool enableReuse =
false;
193 bool syncEnabled =
false;
198 uint32_t dataOffset = 0;
245 bool isBufferAvailable() const noexcept;
255 void releaseToChannel(
void* data);
259 bool recvSingle(dwTime_t waitTime);
260 bool stashConsumed();
262 void handleReuseDrop();
264 void releaseSingle();
269 bool m_shouldDropFirstBuffer{};
283T* getBufferTyped(
GenericData buffer,
bool isPacketSync)
291 ptr = syncPacket->data.template getData<T>();
295 ptr = buffer.template getData<T>();
300 throw Exception(DW_INVALID_ARGUMENT,
"getBufferTyped: type mismatch");
314 "Channel packet type not declared. Ensure channel packet type "
315 "handling is declared with DWFRAMEWORK_DECLARE_PACKET_TYPE_RELATION");
363 return detail::getBufferTyped<T>(getBufferGeneric(), getProperties().boundProperties.syncEnabled);
374 "Channel packet type not declared. Ensure channel packet type "
375 "handling is declared with DWFRAMEWORK_DECLARE_PACKET_TYPE_RELATION");
378 struct PacketDeleter;
401 return iterable(*
this);
411 return detail::getBufferTyped<T>(getBufferGeneric(), getProperties().boundProperties.syncEnabled);
422 return isBufferAvailable() ? getBuffer() :
nullptr;
430 auto* ptr = detail::getBufferTyped<T>(packet, getProperties().boundProperties.syncEnabled);
431 void* releasePtr = ptr;
433 if (getProperties().boundProperties.syncEnabled)
444 void operator()(T* p)
447 port->releaseToChannel(releasePtr);
449 ManagedPortInput* port;
455 explicit iterable(ManagedPortInput<T>& port)
462 class iterator :
public ManagedPortInputBase::RingBuffer::iterator
464 using Base = ManagedPortInputBase::RingBuffer::iterator;
481 return detail::getBufferTyped<TT>(buffer, m_port.getProperties().boundProperties.syncEnabled);
489 iterator<T> begin() {
return iterator<T>(m_port.m_buffers.begin(), m_port); }
492 iterator<T> end() {
return iterator<T>(m_port.m_buffers.end(), m_port); }
495 iterator<const T> begin()
const {
return iterator<const T>(m_port.m_buffers.begin(), m_port); }
498 iterator<const T> end()
const {
return iterator<const T>(m_port.m_buffers.end(), m_port); }
501 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
ManagedPortBase(ManagedPortBase &&other)=delete
ManagedPortBase & operator=(const ManagedPortBase &other)=delete
void setCycleCount(uint32_t cycleCount)
ConstructProperties constructProperties
BoundProperties boundProperties
bool isBufferAvailable() const noexcept
ManagedPortOutput(ConstructProperties props)
ManagedPortOutput(SpecimenT &ref)
ManagedPortOutput(ConstructProperties props, SpecimenT &ref)
SyncedPacketPayload * extractSyncPacket(GenericData packet)
static GenericDataReference make_specimen(typename parameter_traits< T >::SpecimenT *specimen)
constexpr ChannelPacketTypeID DWFRAMEWORK_PACKET_ID_DEFAULT
typename ManagedPortInput< T >::UniquePacketPtr UniquePacketPtr