MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
EventFlowData.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
2// SPDX-License-Identifier: Apache-2.0
3
7
8#pragma once
9
10#include <memory>
11#include "EventRingBuffer.hpp"
12#include "FlowData.hpp"
13
14namespace mxl::lib
15{
17 class EventFlowData : public FlowData
18 {
19 public:
24 explicit EventFlowData(SharedMemoryInstance<Flow>&& flowSegment) noexcept
25 : FlowData{std::move(flowSegment)}
26 {}
27
35 EventFlowData(char const* flowFilePath, AccessMode mode, LockMode lockMode)
36 : FlowData{flowFilePath, mode, lockMode}
37 {}
38
40 std::size_t eventCount() const noexcept
41 {
42 return _events ? flowInfo()->config.event.eventCount : 0;
43 }
44
51 void openEventBuffer(char const* eventFilePath)
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 }
63
69 std::uint64_t oldestIndex() const noexcept
70 {
71 auto const head = EventRingBuffer::load(flowInfo()->runtime.headIndex);
72 return (head != MXL_UNDEFINED_INDEX) && (head >= eventCount()) ? head - (eventCount() - 1) : 0;
73 }
74
77 {
78 return *_ring;
79 }
80
82 EventRingBuffer const& ring() const noexcept
83 {
84 return *_ring;
85 }
86
87 private:
89 std::unique_ptr<EventRingBuffer> _ring;
90 };
91}
Atomic single-producer event ring storage and snapshot protocol.
std::size_t eventCount() const noexcept
SharedMemorySegment _events
Owner of the single events mapping.
EventRingBuffer & ring() noexcept
EventFlowData(SharedMemoryInstance< Flow > &&flowSegment) noexcept
Take ownership of an existing common flow mapping.
EventRingBuffer const & ring() const noexcept
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.
EventFlowData(char const *flowFilePath, AccessMode mode, LockMode lockMode)
Open or create the common flow mapping before attaching the event ring.
std::unique_ptr< EventRingBuffer > _ring
Non-owning ring view whose lifetime is bounded by _events.
Non-owning single-producer event ring view safe for concurrent snapshot readers.
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.
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.
constexpr AccessMode accessMode() const noexcept
Definition FlowData.hpp:67
constexpr bool created() const noexcept
Definition FlowData.hpp:72
constexpr FlowData(SharedMemoryInstance< Flow > &&flowSegement) noexcept
Definition FlowData.hpp:53
constexpr mxlFlowInfo * flowInfo() noexcept
Definition FlowData.hpp:92
std::size_t size() const noexcept
Returns the total number of writers that are registered in the DomainWatcher.
#define MXL_UNDEFINED_INDEX
Definition rational.h:17
mxlEventFlowConfigInfo event
Event queue geometry when common.format is MXL_DATA_FORMAT_EVENT.
Definition flowinfo.h:185
mxlFlowConfigInfo config
Definition flowinfo.h:227