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> 38 #include <type_traits> 73 virtual bool isBound()
const noexcept = 0;
106 bool syncEnabled =
false;
117 bool isBufferAvailable() const noexcept;
137 const
Properties& getProperties() const noexcept;
141 bool isBound() const noexcept override;
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;
216 const Properties& getProperties() const noexcept;
240 void reset() override;
245 bool isBufferAvailable() const noexcept;
249 bool isBound() const noexcept override;
255 void releaseToChannel(
void* data);
259 bool recvSingle(dwTime_t waitTime);
260 bool stashConsumed();
262 void handleReuseDrop();
264 void releaseSingle();
269 bool m_shouldDropFirstBuffer{};
282 template <
typename T>
283 T* 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");
310 template <
typename T>
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);
370 template <
typename T>
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)
435 releasePtr = packet.getPointer();
444 void operator()(T* p)
447 port->releaseToChannel(releasePtr);
462 class iterator :
public ManagedPortInputBase::RingBuffer::iterator
464 using Base = ManagedPortInputBase::RingBuffer::iterator;
481 return detail::getBufferTyped<TT>(buffer, m_port.getProperties().boundProperties.syncEnabled);
505 template <
typename T>
511 #endif // DW_FRAMEWORK_MANAGEDPORT_HPP_
virtual void reset()
Resets the port's cycle count to 0.
void setCycleCount(uint32_t cycleCount)
ConstructProperties constructProperties
virtual bool isBound() const noexcept=0
ManagedPortBase & operator=(const ManagedPortBase &other)=delete
auto getBuffer()
Get a pointer to the acquired buffer.
constexpr ChannelPacketTypeID DWFRAMEWORK_PACKET_ID_DEFAULT
ManagedPortOutput(SpecimenT &ref)
virtual void bindChannel(ChannelObject *channel)=0
Bind channel to the port.
static GenericDataReference make_specimen(typename parameter_traits< T >::SpecimenT *specimen)
ManagedPortOutput(ConstructProperties props)
SyncedPacketPayload * extractSyncPacket(GenericData packet)
virtual ~ManagedPortBase()=default
BoundProperties boundProperties
Base class encapsulates ownership of buffers and interactions with channel in type-agnostic way...
ManagedPortOutput(ConstructProperties props, SpecimenT &ref)
typename ManagedPortInput< T >::UniquePacketPtr UniquePacketPtr
Derived ManagedPortOutput<T> provides type-specific interfaces for accessing buffers.