MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
mxl::lib::EventFlowData Class Reference

Own the common flow mapping, single event ring mapping and ring view. More...

#include <EventFlowData.hpp>

Inheritance diagram for mxl::lib::EventFlowData:
Collaboration diagram for mxl::lib::EventFlowData:

Public Member Functions

std::size_t eventCount () const noexcept
 EventFlowData (char const *flowFilePath, AccessMode mode, LockMode lockMode)
 Open or create the common flow mapping before attaching the event ring.
 EventFlowData (SharedMemoryInstance< Flow > &&flowSegment) noexcept
 Take ownership of an existing common flow mapping.
std::uint64_t oldestIndex () const noexcept
 Compute the retained window from the last committed index and capacity.
void openEventBuffer (char const *eventFilePath)
 Map the complete ring file and initialize it if newly created.
EventRingBuffer const & ring () const noexcept
EventRingBuffer & ring () noexcept
Public Member Functions inherited from mxl::lib::FlowData
constexpr AccessMode accessMode () const noexcept
constexpr bool created () const noexcept
constexpr Flow const * flow () const noexcept
constexpr Flow * flow () noexcept
constexpr mxlFlowInfo const * flowInfo () const noexcept
constexpr mxlFlowInfo * flowInfo () noexcept
constexpr FlowState const * flowState () const noexcept
constexpr FlowState * flowState () noexcept
bool isExclusive () const
constexpr bool isValid () const noexcept
bool makeExclusive ()
constexpr std::size_t mappedSize () const noexcept
constexpr operator bool () const noexcept
virtual ~FlowData ()

Private Attributes

SharedMemorySegment _events
 Owner of the single events mapping.
std::unique_ptr< EventRingBuffer > _ring
 Non-owning ring view whose lifetime is bounded by _events.

Additional Inherited Members

Protected Member Functions inherited from mxl::lib::FlowData
 FlowData (char const *flowFilePath, AccessMode mode, LockMode lockMode)
constexpr FlowData (SharedMemoryInstance< Flow > &&flowSegement) noexcept

Detailed Description

Own the common flow mapping, single event ring mapping and ring view.

Definition at line 17 of file EventFlowData.hpp.

Constructor & Destructor Documentation

◆ EventFlowData() [1/2]

mxl::lib::EventFlowData::EventFlowData ( SharedMemoryInstance< Flow > && flowSegment)
inlineexplicitnoexcept

Take ownership of an existing common flow mapping.

Parameters
flowSegmentMapping to move into the base FlowData object.

Definition at line 24 of file EventFlowData.hpp.

25 : FlowData{std::move(flowSegment)}
26 {}
constexpr FlowData(SharedMemoryInstance< Flow > &&flowSegement) noexcept
Definition FlowData.hpp:53

◆ EventFlowData() [2/2]

mxl::lib::EventFlowData::EventFlowData ( char const * flowFilePath,
AccessMode mode,
LockMode lockMode )
inline

Open or create the common flow mapping before attaching the event ring.

Parameters
flowFilePathPath to the flow's data file.
modeShared-memory access mode.
lockModeAdvisory lock mode for the common flow file.
Exceptions
std::exceptionThe file cannot be mapped or locked.

Definition at line 35 of file EventFlowData.hpp.

36 : FlowData{flowFilePath, mode, lockMode}
37 {}

Member Function Documentation

◆ eventCount()

std::size_t mxl::lib::EventFlowData::eventCount ( ) const
inlinenoexcept
Returns
Configured number of slots, or zero before the ring file is open.

Definition at line 40 of file EventFlowData.hpp.

41 {
42 return _events ? flowInfo()->config.event.eventCount : 0;
43 }
SharedMemorySegment _events
Owner of the single events mapping.
constexpr mxlFlowInfo * flowInfo() noexcept
Definition FlowData.hpp:92
mxlEventFlowConfigInfo event
Event queue geometry when common.format is MXL_DATA_FORMAT_EVENT.
Definition flowinfo.h:185
mxlFlowConfigInfo config
Definition flowinfo.h:227

◆ oldestIndex()

std::uint64_t mxl::lib::EventFlowData::oldestIndex ( ) const
inlinenoexcept

Compute the retained window from the last committed index and capacity.

Returns
Oldest nominally retained index, or zero before the first commit.
Note
A producer overwriting a slot can make it unavailable before the head advances.

Definition at line 69 of file EventFlowData.hpp.

70 {
71 auto const head = EventRingBuffer::load(flowInfo()->runtime.headIndex);
72 return (head != MXL_UNDEFINED_INDEX) && (head >= eventCount()) ? head - (eventCount() - 1) : 0;
73 }
std::size_t eventCount() const noexcept
static std::uint64_t load(std::uint64_t const &value) noexcept
Load a shared 64-bit word with acquire ordering, including from a read-only mapping.
#define MXL_UNDEFINED_INDEX
Definition rational.h:17

◆ openEventBuffer()

void mxl::lib::EventFlowData::openEventBuffer ( char const * eventFilePath)
inline

Map the complete ring file and initialize it if newly created.

Parameters
eventFilePathPath to the events file for this flow.
Precondition
The common flow configuration contains valid event geometry.
Exceptions
std::exceptionMapping fails or stored ring geometry is invalid.

Definition at line 51 of file EventFlowData.hpp.

52 {
53 auto const config = flowInfo()->config.event;
54 auto const size = EventRingBuffer::bufferSize(config.eventCount, config.eventPayloadSize);
55 auto const mode = created() ? AccessMode::CREATE_READ_WRITE : accessMode();
56 _events = SharedMemorySegment{eventFilePath, mode, size, LockMode::None};
57 if (_events.created())
58 {
59 EventRingBuffer::initialize(_events.data(), config.eventCount, config.eventPayloadSize);
60 }
61 _ring = std::make_unique<EventRingBuffer>(_events.data(), config.eventCount, config.eventPayloadSize);
62 }
std::unique_ptr< EventRingBuffer > _ring
Non-owning ring view whose lifetime is bounded by _events.
static void initialize(void *memory, std::uint32_t count, std::uint32_t payloadSize)
Construct headers, empty sequence tags and payload words in a fresh mapping.
static std::size_t bufferSize(std::uint32_t count, std::uint32_t payloadSize)
Validate geometry and compute the complete mapping length.
constexpr AccessMode accessMode() const noexcept
Definition FlowData.hpp:67
constexpr bool created() const noexcept
Definition FlowData.hpp:72
std::size_t size() const noexcept
Returns the total number of writers that are registered in the DomainWatcher.

◆ ring() [1/2]

EventRingBuffer const & mxl::lib::EventFlowData::ring ( ) const
inlinenoexcept
Returns
Read-only ring view; openEventBuffer must have succeeded.

Definition at line 82 of file EventFlowData.hpp.

83 {
84 return *_ring;
85 }

◆ ring() [2/2]

EventRingBuffer & mxl::lib::EventFlowData::ring ( )
inlinenoexcept
Returns
Mutable ring view; openEventBuffer must have succeeded.

Definition at line 76 of file EventFlowData.hpp.

77 {
78 return *_ring;
79 }

Member Data Documentation

◆ _events

SharedMemorySegment mxl::lib::EventFlowData::_events
private

Owner of the single events mapping.

Definition at line 88 of file EventFlowData.hpp.

◆ _ring

std::unique_ptr<EventRingBuffer> mxl::lib::EventFlowData::_ring
private

Non-owning ring view whose lifetime is bounded by _events.

Definition at line 89 of file EventFlowData.hpp.


The documentation for this class was generated from the following file: