MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
flow.h File Reference

Public flow reader, writer, payload and synchronization APIs. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <mxl/flowinfo.h>
#include <mxl/mxl.h>
Include dependency graph for flow.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mxlBufferSlice_t
struct  mxlEventInfo_t
 Metadata for one event queue entry, either a complete event or a fragment. More...
struct  mxlGrainInfo_t
struct  mxlMutableBufferSlice_t
struct  mxlMutableWrappedBufferSlice_t
struct  mxlMutableWrappedMultiBufferSlice_t
struct  mxlWrappedBufferSlice_t
struct  mxlWrappedMultiBufferSlice_t

Macros

#define MXL_GRAIN_FLAG_INVALID   0x00000001
#define MXL_GRAIN_VALID_SLICES_ALL   ((uint16_t)UINT16_MAX)
#define MXL_GRAIN_VALID_SLICES_ANY   ((uint16_t)0)

Typedefs

typedef struct mxlBufferSlice_t mxlBufferSlice
typedef struct mxlEventInfo_t mxlEventInfo
 Metadata for one event queue entry, either a complete event or a fragment.
typedef struct mxlFlowReader_t * mxlFlowReader
typedef struct mxlFlowSynchronizationGroup_t * mxlFlowSynchronizationGroup
typedef struct mxlFlowWriter_t * mxlFlowWriter
typedef struct mxlGrainInfo_t mxlGrainInfo
typedef struct mxlMutableBufferSlice_t mxlMutableBufferSlice
typedef struct mxlMutableWrappedBufferSlice_t mxlMutableWrappedBufferSlice
typedef struct mxlMutableWrappedMultiBufferSlice_t mxlMutableWrappedMultiBufferSlice
typedef struct mxlWrappedBufferSlice_t mxlWrappedBufferSlice
typedef struct mxlWrappedMultiBufferSlice_t mxlWrappedMultiBufferSlice

Functions

MXL_EXPORT mxlStatus mxlCreateFlowReader (mxlInstance instance, char const *flowId, char const *options, mxlFlowReader *reader)
MXL_EXPORT mxlStatus mxlCreateFlowSynchronizationGroup (mxlInstance instance, mxlFlowSynchronizationGroup *group)
MXL_EXPORT mxlStatus mxlCreateFlowWriter (mxlInstance instance, char const *flowDef, char const *options, mxlFlowWriter *writer, mxlFlowConfigInfo *configInfo, bool *created)
MXL_EXPORT mxlStatus mxlFlowReaderGetConfigInfo (mxlFlowReader reader, mxlFlowConfigInfo *info)
MXL_EXPORT mxlStatus mxlFlowReaderGetEvent (mxlFlowReader reader, uint64_t timeoutNs, mxlEventInfo *event, uint8_t **payload)
MXL_EXPORT mxlStatus mxlFlowReaderGetEventNonBlocking (mxlFlowReader reader, mxlEventInfo *event, uint8_t **payload)
 Attempt to read one event entry without waiting for publication.
MXL_EXPORT mxlStatus mxlFlowReaderGetGrain (mxlFlowReader reader, uint64_t index, uint64_t timeoutNs, mxlGrainInfo *grain, uint8_t **payload)
MXL_EXPORT mxlStatus mxlFlowReaderGetGrainNonBlocking (mxlFlowReader reader, uint64_t index, mxlGrainInfo *grain, uint8_t **payload)
MXL_EXPORT mxlStatus mxlFlowReaderGetGrainSlice (mxlFlowReader reader, uint64_t index, uint16_t minValidSlices, uint64_t timeoutNs, mxlGrainInfo *grain, uint8_t **payload)
MXL_EXPORT mxlStatus mxlFlowReaderGetGrainSliceNonBlocking (mxlFlowReader reader, uint64_t index, uint16_t minValidSlices, mxlGrainInfo *grain, uint8_t **payload)
MXL_EXPORT mxlStatus mxlFlowReaderGetInfo (mxlFlowReader reader, mxlFlowInfo *info)
MXL_EXPORT mxlStatus mxlFlowReaderGetMaxReadLengthSamples (mxlFlowReader reader, size_t *maxReadLength)
MXL_EXPORT mxlStatus mxlFlowReaderGetRuntimeInfo (mxlFlowReader reader, mxlFlowRuntimeInfo *info)
MXL_EXPORT mxlStatus mxlFlowReaderGetSamples (mxlFlowReader reader, uint64_t index, size_t count, uint64_t timeoutNs, mxlWrappedMultiBufferSlice *payloadBuffersSlices)
MXL_EXPORT mxlStatus mxlFlowReaderGetSamplesNonBlocking (mxlFlowReader reader, uint64_t index, size_t count, mxlWrappedMultiBufferSlice *payloadBuffersSlices)
MXL_EXPORT mxlStatus mxlFlowSynchronizationGroupAddPartialGrainReader (mxlFlowSynchronizationGroup group, mxlFlowReader reader, uint16_t minValidSlices)
MXL_EXPORT mxlStatus mxlFlowSynchronizationGroupAddReader (mxlFlowSynchronizationGroup group, mxlFlowReader reader)
MXL_EXPORT mxlStatus mxlFlowSynchronizationGroupRemoveReader (mxlFlowSynchronizationGroup group, mxlFlowReader reader)
MXL_EXPORT mxlStatus mxlFlowSynchronizationGroupWaitForDataAt (mxlFlowSynchronizationGroup group, uint64_t timestamp, uint64_t timeoutNs)
MXL_EXPORT mxlStatus mxlFlowWriterCancelEvent (mxlFlowWriter writer)
 Cancel the open event without publishing or changing timestamp ordering.
MXL_EXPORT mxlStatus mxlFlowWriterCancelGrain (mxlFlowWriter writer)
MXL_EXPORT mxlStatus mxlFlowWriterCancelSamples (mxlFlowWriter writer)
MXL_EXPORT mxlStatus mxlFlowWriterCommitEvent (mxlFlowWriter writer, mxlEventInfo const *event)
MXL_EXPORT mxlStatus mxlFlowWriterCommitGrain (mxlFlowWriter writer, mxlGrainInfo const *grain)
MXL_EXPORT mxlStatus mxlFlowWriterCommitSamples (mxlFlowWriter writer)
MXL_EXPORT mxlStatus mxlFlowWriterGetGrainInfo (mxlFlowWriter writer, uint64_t index, mxlGrainInfo *mxlGrainInfo)
MXL_EXPORT mxlStatus mxlFlowWriterGetMaxWriteLengthSamples (mxlFlowWriter writer, size_t *maxWriteLength)
MXL_EXPORT mxlStatus mxlFlowWriterOpenEvent (mxlFlowWriter writer, mxlEventInfo *event, uint8_t **payload)
MXL_EXPORT mxlStatus mxlFlowWriterOpenGrain (mxlFlowWriter writer, uint64_t index, mxlGrainInfo *mxlGrainInfo, uint8_t **payload)
MXL_EXPORT mxlStatus mxlFlowWriterOpenSamples (mxlFlowWriter writer, uint64_t index, size_t count, mxlMutableWrappedMultiBufferSlice *payloadBuffersSlices)
MXL_EXPORT mxlStatus mxlGetFlowDef (mxlInstance instance, char const *flowId, char *buffer, size_t *bufferSize)
MXL_EXPORT mxlStatus mxlIsFlowActive (mxlInstance instance, char const *flowId, bool *isActive)
MXL_EXPORT mxlStatus mxlReleaseFlowReader (mxlInstance instance, mxlFlowReader reader)
MXL_EXPORT mxlStatus mxlReleaseFlowSynchronizationGroup (mxlInstance instance, mxlFlowSynchronizationGroup group)
MXL_EXPORT mxlStatus mxlReleaseFlowWriter (mxlInstance instance, mxlFlowWriter writer)

Detailed Description

Public flow reader, writer, payload and synchronization APIs.

Definition in file flow.h.

Macro Definition Documentation

◆ MXL_GRAIN_FLAG_INVALID

#define MXL_GRAIN_FLAG_INVALID   0x00000001

Definition at line 33 of file flow.h.

◆ MXL_GRAIN_VALID_SLICES_ALL

#define MXL_GRAIN_VALID_SLICES_ALL   ((uint16_t)UINT16_MAX)

A symbolic constant that may be passed to functions as their "min valid slices" parameter, in order to indicate that all slices need to be available and partial grains are not acceptable.

Definition at line 45 of file flow.h.

◆ MXL_GRAIN_VALID_SLICES_ANY

#define MXL_GRAIN_VALID_SLICES_ANY   ((uint16_t)0)

A symbolic constant that may be passed to functions as their "min valid slices" parameter, in order to indicate that no minimum is imposed and any number of valid slices will do.

Definition at line 39 of file flow.h.

Typedef Documentation

◆ mxlBufferSlice

A helper type used to describe consecutive sequences of bytes in memory.

◆ mxlEventInfo

typedef struct mxlEventInfo_t mxlEventInfo

Metadata for one event queue entry, either a complete event or a fragment.

◆ mxlFlowReader

typedef struct mxlFlowReader_t* mxlFlowReader

Definition at line 205 of file flow.h.

◆ mxlFlowSynchronizationGroup

typedef struct mxlFlowSynchronizationGroup_t* mxlFlowSynchronizationGroup

Definition at line 208 of file flow.h.

◆ mxlFlowWriter

typedef struct mxlFlowWriter_t* mxlFlowWriter

Definition at line 206 of file flow.h.

◆ mxlGrainInfo

typedef struct mxlGrainInfo_t mxlGrainInfo

◆ mxlMutableBufferSlice

A helper type used to describe consecutive sequences of mutable bytes in memory.

◆ mxlMutableWrappedBufferSlice

A helper type used to describe consecutive sequences of mutable bytes in a ring buffer that may potentially straddle the wraparound point of the buffer.

◆ mxlMutableWrappedMultiBufferSlice

A helper type used to describe consecutive sequences of mutable bytes in memory in consecutive ring buffers separated by the specified stride of bytes.

◆ mxlWrappedBufferSlice

A helper type used to describe consecutive sequences of bytes in a ring buffer that may potentially straddle the wraparound point of the buffer.

◆ mxlWrappedMultiBufferSlice

A helper type used to describe consecutive sequences of bytes in memory in consecutive ring buffers separated by the specified stride of bytes.

Function Documentation

◆ mxlCreateFlowReader()

MXL_EXPORT mxlStatus mxlCreateFlowReader ( mxlInstance instance,
char const * flowId,
char const * options,
mxlFlowReader * reader )

Open a reader for an existing flow.

Parameters
[in]instanceThe mxl instance created using mxlCreateInstance
[in]flowIdThe id of the flow to read, as a UUID string.
[in]options(optional) Additional options, can be NULL
[out]readerA pointer to a memory location where the created flow reader will be written.
Return values
MXL_STATUS_OKThe reader was created.
MXL_ERR_INVALID_ARGThe instance, the flow id or the reader pointer is not valid.
MXL_ERR_FLOW_NOT_FOUNDThere is no flow with this id in the domain.
MXL_ERR_PERMISSION_DENIEDThe files of the flow cannot be accessed with the permissions of the process.
MXL_ERR_UNKNOWNAny other failure.

Definition at line 136 of file flow.cpp.

137{
138 try
139 {
140 if (reader != nullptr)
141 {
142 if (auto const cppInstance = to_Instance(instance); cppInstance != nullptr)
143 {
144 if ((flowId != nullptr) && uuids::uuid::is_valid_uuid(flowId))
145 {
146 *reader = reinterpret_cast<mxlFlowReader>(cppInstance->getFlowReader(flowId));
147 return MXL_STATUS_OK;
148 }
149 }
150 }
151
152 return MXL_ERR_INVALID_ARG;
153 }
154 catch (std::filesystem::filesystem_error const& e)
155 {
156 auto const code = e.code();
157 if (code.value() == ENOENT)
158 {
160 }
161
162 MXL_ERROR("Failed to create flow reader: {}", e.what());
163 if ((code == std::errc::permission_denied) || (code == std::errc::operation_not_permitted))
164 {
166 }
167 return MXL_ERR_UNKNOWN;
168 }
169 catch (...)
170 {
171 return MXL_ERR_UNKNOWN;
172 }
173}
#define MXL_ERROR(...)
Definition Logging.hpp:67
struct mxlFlowReader_t * mxlFlowReader
Definition flow.h:205
@ MXL_ERR_UNKNOWN
Definition mxl.h:27
@ MXL_ERR_PERMISSION_DENIED
Definition mxl.h:37
@ MXL_ERR_FLOW_NOT_FOUND
Definition mxl.h:29
@ MXL_ERR_INVALID_ARG
Definition mxl.h:35
@ MXL_STATUS_OK
Definition mxl.h:23
Instance * to_Instance(mxlInstance instance) noexcept
Utility function to convert from a C mxlInstance handle to a C++ Instance class.
Definition Instance.hpp:247
mxlFlowReader reader
auto const flowId

◆ mxlCreateFlowSynchronizationGroup()

MXL_EXPORT mxlStatus mxlCreateFlowSynchronizationGroup ( mxlInstance instance,
mxlFlowSynchronizationGroup * group )

Create a new, empty synchronization group that can be used to synchronize on data availability across multiple flows in parallel.

Parameters
[in]instanceThe instance to which the flow readers handled by this group belong.
[out]groupA handle referring to the newly created group.
Returns
MXL_STATUS_OK if the group was successfully created.

Definition at line 770 of file flow.cpp.

771{
772 try
773 {
774 auto const cppInstance = to_Instance(instance);
775 if (cppInstance != nullptr)
776 {
777 *group = reinterpret_cast<mxlFlowSynchronizationGroup>(cppInstance->createFlowSynchronizationGroup());
778 return MXL_STATUS_OK;
779 }
780
781 return MXL_ERR_INVALID_ARG;
782 }
783 catch (...)
784 {
785 return MXL_ERR_UNKNOWN;
786 }
787}
struct mxlFlowSynchronizationGroup_t * mxlFlowSynchronizationGroup
Definition flow.h:208

◆ mxlCreateFlowWriter()

MXL_EXPORT mxlStatus mxlCreateFlowWriter ( mxlInstance instance,
char const * flowDef,
char const * options,
mxlFlowWriter * writer,
mxlFlowConfigInfo * configInfo,
bool * created )

Attempts to create a flow writer for a given flow definition. If the flow does not exist already, it is created and 'created' will be set to true. If the flow exists, it will be opened and 'created' will be set to false. If the flow exists already it is not guaranteed that the flow definition of the existing flow is exactly equal to the flow definition supplied in flowDef. The definition of the existing flow can be retrieved using mxlGetFlowDef().

IMPORTANT NOTE
The flow definition (flowDef) is expected to have well defined fields such as label, description and grouphint tag. This is a responsibility of the media function implementer. These fields should refer to the media function instance name. For example, on a large system with mutliple software defined decoders running simultaneously, each decoder instance should use a unique name in the grouphint tag to identify itself. Please read carefully the 'natural groups' section of the group hint tag specification.

Example fields for an hypothetical video decoder media function instance named "Decoder 1":

  • label: "Decoder 1 Video Output"
  • description: "Decoder 1 MXL Flow Video Output"
  • grouphint tag: "Decoder 1:Video"

Example fields for a multi-flow audio receiver media function instance named "Audio Receiver A": Flow 1:

  • label: "Audio Receiver A Audio Output #1"
  • description: "Audio Receiver A MXL Flow Audio Output #1"
  • grouphint tag: "Audio Receiver A:Audio #1"

Flow 2:

  • label: "Audio Receiver A Audio Output #2"
  • description: "Audio Receiver A MXL Flow Audio Output #2"
  • grouphint tag: "Audio Receiver A:Audio #2"

Having a well formed grouphint tag refering to the media function instance name is essential to ensure proper flow discovery and management by higher level applications using MXL.

Parameters
[in]instanceThe mxl instance created using mxlCreateInstance
[in]flowDefThe flow definition from which a flow should be created if there is not already a flow with the same flow id.
[in]options(optional) Additional options, can be NULL
[out]writerA pointer to a memory location where the created flow writer will be written.
[out]configInfo(optional) A pointer to an mxlFlowConfigInfo structure. If not the null pointer, this structure will be updated with the flow information after the flow is created.
[out]created(optional) A pointer to a boolean. If not the null pointer, this variable will be set to true if a new flow was created, and to false if an existing flow was opened instead.

Definition at line 198 of file flow.cpp.

200{
201 if ((instance == nullptr) || (flowDef == nullptr) || (writer == nullptr))
202 {
203 return MXL_ERR_INVALID_ARG;
204 }
205
206 auto flowData = std::unique_ptr<FlowData>{};
207 auto cppInstance = to_Instance(instance);
208
209 if (cppInstance == nullptr)
210 {
211 return MXL_ERR_INVALID_ARG;
212 }
213
214 try
215 {
216 static_assert(std::is_trivially_copy_assignable_v<mxlFlowConfigInfo>, "The type mxlFlowConfigInfo must be trivially copy assignable.");
217 static_assert(std::is_nothrow_copy_assignable_v<mxlFlowConfigInfo>, "Copying mxlFlowConfigInfo cannot throw.");
218
219 auto [flowConfigInfo, flowWriter, flowCreated] = cppInstance->createFlowWriter(flowDef,
220 (options == nullptr) ? std::nullopt : std::make_optional(options));
221
222 *writer = reinterpret_cast<mxlFlowWriter>(flowWriter);
223
224 if (configInfo != nullptr)
225 {
226 *configInfo = flowConfigInfo;
227 }
228 if (created != nullptr)
229 {
230 *created = flowCreated;
231 }
232 }
233 catch (std::filesystem::filesystem_error const& e)
234 {
235 MXL_ERROR("Failed to create flow writer: {}", e.what());
236 auto const code = e.code();
237 if ((code == std::errc::permission_denied) || (code == std::errc::operation_not_permitted) || (code == std::errc::read_only_file_system))
238 {
240 }
241 else
242 {
243 MXL_ERROR("Filesystem error: {}", code.message());
244 return MXL_ERR_UNKNOWN;
245 }
246 }
247 catch (std::exception const& e)
248 {
249 MXL_ERROR("Failed to create flow : {}", e.what());
250 return MXL_ERR_UNKNOWN;
251 }
252 catch (...)
253 {
254 return MXL_ERR_UNKNOWN;
255 }
256
257 return MXL_STATUS_OK;
258}
struct mxlFlowWriter_t * mxlFlowWriter
Definition flow.h:206
mxlFlowConfigInfo configInfo
mxlFlowWriter writer
auto flowDef

◆ mxlFlowReaderGetConfigInfo()

MXL_EXPORT mxlStatus mxlFlowReaderGetConfigInfo ( mxlFlowReader reader,
mxlFlowConfigInfo * info )

Get a copy of the immutable descriptive header of a Flow

Parameters
[in]readerA valid flow reader
[out]infoA valid pointer to an mxlFlowConfigInfo structure. On return, the structure will be updated with a copy of the current flow config info value.
Returns
The result code.
See also
mxlStatus

Definition at line 316 of file flow.cpp.

317{
318 try
319 {
320 if (info != nullptr)
321 {
322 if (auto const cppReader = to_FlowReader(reader); cppReader != nullptr)
323 {
324 *info = cppReader->getFlowInfo().config;
325 return MXL_STATUS_OK;
326 }
328 }
329 return MXL_ERR_INVALID_ARG;
330 }
331 catch (...)
332 {
333 return MXL_ERR_UNKNOWN;
334 }
335}
@ MXL_ERR_INVALID_FLOW_READER
Definition mxl.h:32
FlowReader * to_FlowReader(mxlFlowReader reader) noexcept
Utility function to convert from a C mxlFlowReader handle to a C++ FlowReader instance.
Definition Instance.hpp:252

◆ mxlFlowReaderGetEvent()

MXL_EXPORT mxlStatus mxlFlowReaderGetEvent ( mxlFlowReader reader,
uint64_t timeoutNs,
mxlEventInfo * event,
uint8_t ** payload )

Read the next event using this reader's queue cursor, starting with the oldest retained event. An overrun advances the cursor past lost entries; retry to resume reading. Each reader handle must be accessed by a single thread at a time. Payload is a private snapshot, valid until the next read attempt on this reader or reader release. Producers and independent readers cannot overwrite it. Metadata includes the queue index on success; event and payload output arguments are unchanged on failure.

Parameters
[in]readerEvent flow reader acquired with mxlCreateFlowReader.
[in]timeoutNsMaximum wait in nanoseconds; zero requests a nonblocking read.
[out]eventReceives metadata on success; must not be NULL.
[out]payloadReceives the private payload snapshot on success; must not be NULL.
Return values
MXL_STATUS_OKOne entry was copied and the cursor advanced.
MXL_ERR_OUT_OF_RANGE_TOO_EARLYNo entry was available before the deadline.
MXL_ERR_OUT_OF_RANGE_TOO_LATEAn entry was lost to ring overwrite.
MXL_ERR_FLOW_INVALIDStored metadata is invalid or a removed/replaced flow was detected.
MXL_ERR_INVALID_ARGAn output pointer is NULL.
MXL_ERR_INVALID_FLOW_READERThe handle is NULL or is not an event reader.
MXL_ERR_UNKNOWNAn internal exception occurred.

Definition at line 726 of file flow.cpp.

727{
728 if ((info == nullptr) || (payload == nullptr))
729 {
730 return MXL_ERR_INVALID_ARG;
731 }
732 try
733 {
734 if (auto object = dynamic_cast<EventFlowReader*>(to_FlowReader(handle)); object != nullptr)
735 {
736 return object->getEvent(toDeadline(timeoutNs), info, payload);
737 }
739 }
740 catch (...)
741 {
742 return MXL_ERR_UNKNOWN;
743 }
744}
Backend contract for reading complete event entries or fragments in queue order. Each reader has one ...

◆ mxlFlowReaderGetEventNonBlocking()

MXL_EXPORT mxlStatus mxlFlowReaderGetEventNonBlocking ( mxlFlowReader reader,
mxlEventInfo * event,
uint8_t ** payload )

Attempt to read one event entry without waiting for publication.

Parameters
[in]readerEvent flow reader to advance.
[out]eventReceives metadata on success; must not be NULL.
[out]payloadReceives a private payload snapshot on success; must not be NULL.
Returns
The same statuses as mxlFlowReaderGetEvent with timeoutNs equal to zero.

Definition at line 748 of file flow.cpp.

749{
750 if ((info == nullptr) || (payload == nullptr))
751 {
752 return MXL_ERR_INVALID_ARG;
753 }
754 try
755 {
756 if (auto object = dynamic_cast<EventFlowReader*>(to_FlowReader(handle)); object != nullptr)
757 {
758 return object->getEvent(toDeadline(0), info, payload);
759 }
761 }
762 catch (...)
763 {
764 return MXL_ERR_UNKNOWN;
765 }
766}

◆ mxlFlowReaderGetGrain()

MXL_EXPORT mxlStatus mxlFlowReaderGetGrain ( mxlFlowReader reader,
uint64_t index,
uint64_t timeoutNs,
mxlGrainInfo * grain,
uint8_t ** payload )

Accessors for a flow grain at a specific index This method is expected to wait until the full grain is available (or the timeout expires). For partial grain access use mxlFlowReaderGetGrainSlice()

Parameters
[in]readerA valid discrete flow reader.
[in]indexThe index of the grain to obtain
[in]timeoutNsHow long should we wait for the grain (in nanoseconds)
[out]grainThe requested mxlGrainInfo structure.
[out]payloadThe requested grain payload.
Returns
The result code.
See also
mxlStatus
Note
Please note that this function can only be called on readers that operate on discrete flows. Any attempt to call this function on a reader that operates on another type of flow will result in an error.

Definition at line 362 of file flow.cpp.

363{
364 return mxlFlowReaderGetGrainSlice(reader, index, MXL_GRAIN_VALID_SLICES_ALL, timeoutNs, grainInfo, payload);
365}
MXL_EXPORT mxlStatus mxlFlowReaderGetGrainSlice(mxlFlowReader reader, uint64_t index, uint16_t minValidSlices, uint64_t timeoutNs, mxlGrainInfo *grainInfo, uint8_t **payload)
Definition flow.cpp:369
#define MXL_GRAIN_VALID_SLICES_ALL
Definition flow.h:45
uint64_t index

◆ mxlFlowReaderGetGrainNonBlocking()

MXL_EXPORT mxlStatus mxlFlowReaderGetGrainNonBlocking ( mxlFlowReader reader,
uint64_t index,
mxlGrainInfo * grain,
uint8_t ** payload )

Non-blocking accessor for a flow grain at a specific index

Parameters
[in]readerA valid flow reader
[in]indexThe index of the grain to obtain
[out]grainThe requested mxlGrainInfo structure.
[out]payloadThe requested grain payload.
Returns
The result code.
See also
mxlStatus
Note
Please note that this function can only be called on readers that operate on discrete flows. Any attempt to call this function on a reader that operates on another type of flow will result in an error.

Definition at line 392 of file flow.cpp.

393{
395}
MXL_EXPORT mxlStatus mxlFlowReaderGetGrainSliceNonBlocking(mxlFlowReader reader, uint64_t index, uint16_t minValidSlices, mxlGrainInfo *grainInfo, uint8_t **payload)
Definition flow.cpp:399

◆ mxlFlowReaderGetGrainSlice()

MXL_EXPORT mxlStatus mxlFlowReaderGetGrainSlice ( mxlFlowReader reader,
uint64_t index,
uint16_t minValidSlices,
uint64_t timeoutNs,
mxlGrainInfo * grain,
uint8_t ** payload )

Accessors for a flow grain at a specific index, with a minimum number of valid slices.

Parameters
[in]readerA valid discrete flow reader.
[in]indexThe index of the grain to obtain
[in]minValidSlicesThe minimum number of valid slices required in the returned grain.
[in]timeoutNsHow long should we wait for the slice (in nanoseconds)
[out]grainThe requested mxlGrainInfo structure.
[out]payloadThe requested grain payload.
Returns
The result code.
See also
mxlStatus
Note
Please note that this function can only be called on readers that operate on discrete flows. Any attempt to call this function on a reader that operates on another type of flow will result in an error.

Definition at line 369 of file flow.cpp.

371{
372 try
373 {
374 if ((grainInfo != nullptr) && (payload != nullptr))
375 {
376 if (auto const cppReader = dynamic_cast<DiscreteFlowReader*>(to_FlowReader(reader)); cppReader != nullptr)
377 {
378 return cppReader->getGrain(index, minValidSlices, toDeadline(timeoutNs), grainInfo, payload);
379 }
381 }
382 return MXL_ERR_INVALID_ARG;
383 }
384 catch (...)
385 {
386 return MXL_ERR_UNKNOWN;
387 }
388}

◆ mxlFlowReaderGetGrainSliceNonBlocking()

MXL_EXPORT mxlStatus mxlFlowReaderGetGrainSliceNonBlocking ( mxlFlowReader reader,
uint64_t index,
uint16_t minValidSlices,
mxlGrainInfo * grain,
uint8_t ** payload )

Non-blocking accessor for a flow grain at a specific index, with a minimum number of valid slices.

Parameters
[in]readerA valid discrete flow reader.
[in]indexThe index of the grain to obtain
[in]minValidSlicesThe minimum number of valid slices required in the returned grain.
[out]grainThe requested mxlGrainInfo structure.
[out]payloadThe requested grain payload.
Returns
The result code.
See also
mxlStatus
Note
Please note that this function can only be called on readers that operate on discrete flows. Any attempt to call this function on a reader that operates on another type of flow will result in an error.

Definition at line 399 of file flow.cpp.

401{
402 try
403 {
404 if ((grainInfo != nullptr) && (payload != nullptr))
405 {
406 if (auto const cppReader = dynamic_cast<DiscreteFlowReader*>(to_FlowReader(reader)); cppReader != nullptr)
407 {
408 return cppReader->getGrain(index, minValidSlices, grainInfo, payload);
409 }
411 }
412 return MXL_ERR_INVALID_ARG;
413 }
414 catch (...)
415 {
416 return MXL_ERR_UNKNOWN;
417 }
418}

◆ mxlFlowReaderGetInfo()

MXL_EXPORT mxlStatus mxlFlowReaderGetInfo ( mxlFlowReader reader,
mxlFlowInfo * info )

Get a copy of the header of a Flow

Parameters
[in]readerA valid flow reader
[out]infoA valid pointer to an mxlFlowInfo structure. On return, the structure will be updated with a copy of the current flow config info value.
Returns
The result code.
See also
mxlStatus

Definition at line 293 of file flow.cpp.

294{
295 try
296 {
297 if (info != nullptr)
298 {
299 if (auto const cppReader = to_FlowReader(reader); cppReader != nullptr)
300 {
301 *info = cppReader->getFlowInfo();
302 return MXL_STATUS_OK;
303 }
305 }
306 return MXL_ERR_INVALID_ARG;
307 }
308 catch (...)
309 {
310 return MXL_ERR_UNKNOWN;
311 }
312}

◆ mxlFlowReaderGetMaxReadLengthSamples()

MXL_EXPORT mxlStatus mxlFlowReaderGetMaxReadLengthSamples ( mxlFlowReader reader,
size_t * maxReadLength )

Return the absolute maximum number of samples a read operation may retrieve from a flow.

Parameters
[in]readerA valid flow reader
[out]maxReadLengthA valid pointer referring to the location, in which to store the maximum number of samples a read operation may retrieve from the flow reader operates on.
Returns
The result code.
See also
mxlStatus
Note
Please note that a read of the specified length is only guaranteed to be possible, if
  1. enough history is available, and
  2. the read is performed at the current head index.

Definition at line 510 of file flow.cpp.

511{
512 try
513 {
514 if (maxReadLength != nullptr)
515 {
516 if (auto const cppReader = dynamic_cast<ContinuousFlowReader*>(to_FlowReader(reader)); cppReader != nullptr)
517 {
518 *maxReadLength = cppReader->getMaxReadLength();
519 return MXL_STATUS_OK;
520 }
521
523 }
524 return MXL_ERR_INVALID_ARG;
525 }
526 catch (...)
527 {
528 return MXL_ERR_UNKNOWN;
529 }
530}

◆ mxlFlowReaderGetRuntimeInfo()

MXL_EXPORT mxlStatus mxlFlowReaderGetRuntimeInfo ( mxlFlowReader reader,
mxlFlowRuntimeInfo * info )

Get a copy of the current runtime header of a Flow

Parameters
[in]readerA valid flow reader
[out]infoA valid pointer to an mxlFlowRuntimeInfo structure. On return, the structure will be updated with a copy of the current flow config info value.
Returns
The result code.
See also
mxlStatus

Definition at line 339 of file flow.cpp.

340{
341 try
342 {
343 if (info != nullptr)
344 {
345 if (auto const cppReader = to_FlowReader(reader); cppReader != nullptr)
346 {
347 *info = cppReader->getFlowInfo().runtime;
348 return MXL_STATUS_OK;
349 }
351 }
352 return MXL_ERR_INVALID_ARG;
353 }
354 catch (...)
355 {
356 return MXL_ERR_UNKNOWN;
357 }
358}

◆ mxlFlowReaderGetSamples()

MXL_EXPORT mxlStatus mxlFlowReaderGetSamples ( mxlFlowReader reader,
uint64_t index,
size_t count,
uint64_t timeoutNs,
mxlWrappedMultiBufferSlice * payloadBuffersSlices )

Accessor for a specific set of samples across all channels ending at a specific index (count samples up to index).

Parameters
[in]indexThe head index of the samples to obtain.
[in]countThe number of samples to obtain.
[in]timeoutNsHow long to wait in nanoseconds for the range of samples to become available.
[out]payloadBuffersSlicesA pointer to a wrapped multi buffer slice that represents the requested range across all channel buffers.
Returns
A status code describing the outcome of the call. Please note that this method will never return MXL_ERR_TIMEOUT, because the actual error that is being encountered in this case is MXL_ERR_OUT_OF_RANGE_TOO_EARLY, even after waiting.
Note
No guarantees are made as to how long the caller may safely hang on to the returned range of samples without the risk of these samples being overwritten.

Definition at line 534 of file flow.cpp.

536{
537 try
538 {
539 if (payloadBuffersSlices != nullptr)
540 {
541 if (auto const cppReader = dynamic_cast<ContinuousFlowReader*>(to_FlowReader(reader)); cppReader != nullptr)
542 {
543 return cppReader->getSamples(index, count, toDeadline(timeoutNs), *payloadBuffersSlices);
544 }
545
547 }
548 return MXL_ERR_INVALID_ARG;
549 }
550 catch (...)
551 {
552 return MXL_ERR_UNKNOWN;
553 }
554}
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.

◆ mxlFlowReaderGetSamplesNonBlocking()

MXL_EXPORT mxlStatus mxlFlowReaderGetSamplesNonBlocking ( mxlFlowReader reader,
uint64_t index,
size_t count,
mxlWrappedMultiBufferSlice * payloadBuffersSlices )

Non-blocking accessor for a specific set of samples across all channels ending at a specific index (count samples up to index).

Parameters
[in]indexThe head index of the samples to obtain.
[in]countThe number of samples to obtain.
[out]payloadBuffersSlicesA pointer to a wrapped multi buffer slice that represents the requested range across all channel buffers.
Returns
A status code describing the outcome of the call.
Note
No guarantees are made as to how long the caller may safely hang on to the returned range of samples without the risk of these samples being overwritten.

Definition at line 558 of file flow.cpp.

559{
560 try
561 {
562 if (payloadBuffersSlices != nullptr)
563 {
564 if (auto const cppReader = dynamic_cast<ContinuousFlowReader*>(to_FlowReader(reader)); cppReader != nullptr)
565 {
566 return cppReader->getSamples(index, count, *payloadBuffersSlices);
567 }
568
570 }
571 return MXL_ERR_INVALID_ARG;
572 }
573 catch (...)
574 {
575 return MXL_ERR_UNKNOWN;
576 }
577}

◆ mxlFlowSynchronizationGroupAddPartialGrainReader()

MXL_EXPORT mxlStatus mxlFlowSynchronizationGroupAddPartialGrainReader ( mxlFlowSynchronizationGroup group,
mxlFlowReader reader,
uint16_t minValidSlices )

Add a grain based flow reader to a synchronization group. This causes the wait operation of the group to wait for at least minValidSlices of the grain belonging to the specified timestamp to become.

Parameters
[in]groupA handle to the synchronization group, to which the flow reader shall be added.
[in]readerA handle to a discrete flow reader that shall be added to the synchronization group.
[in]minValidSlicesThe number of valid slices to wait for within a grain of the flow the reader operates on.
Returns
MXL_STATUS_OK if the reader was successfully added to the synchronization group.
Note
Please note that a reader can only be added to a group once and attempts to add the same reader multiple times are ignored, except that the number of valid slices to wait for is updated to the value matching the last add operation.

Definition at line 846 of file flow.cpp.

847{
848 try
849 {
850 if (auto const cppGroup = to_FlowSynchronizationGroup(group); cppGroup != nullptr)
851 {
852 if (auto const cppReader = dynamic_cast<DiscreteFlowReader const*>(to_FlowReader(reader)); cppReader != nullptr)
853 {
854 cppGroup->addReader(*cppReader, minValidSlices);
855 return MXL_STATUS_OK;
856 }
857
859 }
860
861 return MXL_ERR_INVALID_ARG;
862 }
863 catch (...)
864 {
865 return MXL_ERR_UNKNOWN;
866 }
867}
FlowSynchronizationGroup * to_FlowSynchronizationGroup(mxlFlowSynchronizationGroup group) noexcept
Utility function to convert from a C mxlFlowSynchronizationGroup handle to a C++ FlowSynchronizationG...
Definition Instance.hpp:262

◆ mxlFlowSynchronizationGroupAddReader()

MXL_EXPORT mxlStatus mxlFlowSynchronizationGroupAddReader ( mxlFlowSynchronizationGroup group,
mxlFlowReader reader )

Add a flow reader to a synchronization group. This can either be a reader for a continuous, sample based flow or a discrete, grain based flow. For sample based flows this causes the wait operation of the group to wait for the sample belonging to the specified timestamp to become available. For grain based flows this causes the wait operation of the group to wait for the grain belonging to the specified timestamp to become fully available.

Parameters
[in]groupA handle to the synchronization group, to which the flow reader shall be added.
[in]readerA handle to a flow reader that shall be added to the synchronization group.
Returns
MXL_STATUS_OK if the reader was successfully added to the synchronization group.
Note
Please note that a reader can only be added to a group once and attempts to add the same reader multiple times are ignored, except that for grain based readers the number of valid slices to wait for is updated to the value matching the last add operation.

Definition at line 813 of file flow.cpp.

814{
815 try
816 {
817 if (auto const cppGroup = to_FlowSynchronizationGroup(group); cppGroup != nullptr)
818 {
819 if (auto const cppReader = to_FlowReader(reader); cppReader != nullptr)
820 {
821 if (auto const discreteReader = dynamic_cast<DiscreteFlowReader const*>(cppReader); discreteReader != nullptr)
822 {
823 cppGroup->addReader(*discreteReader, MXL_GRAIN_VALID_SLICES_ALL);
824 return MXL_STATUS_OK;
825 }
826 if (auto const continuousReader = dynamic_cast<ContinuousFlowReader const*>(cppReader); continuousReader != nullptr)
827 {
828 cppGroup->addReader(*continuousReader);
829 return MXL_STATUS_OK;
830 }
831 }
832
834 }
835
836 return MXL_ERR_INVALID_ARG;
837 }
838 catch (...)
839 {
840 return MXL_ERR_UNKNOWN;
841 }
842}

◆ mxlFlowSynchronizationGroupRemoveReader()

MXL_EXPORT mxlStatus mxlFlowSynchronizationGroupRemoveReader ( mxlFlowSynchronizationGroup group,
mxlFlowReader reader )

Remove a flow reader from a synchronization group.

Parameters
[in]groupA handle to the synchronization group, from which the flow reader shall be removed.
[in]readerA handle to a flow reader that shall be removed from the synchronization group.
Returns
MXL_STATUS_OK if the reader was successfully removed from the synchronization group.

Definition at line 871 of file flow.cpp.

872{
873 try
874 {
875 auto const cppGroup = to_FlowSynchronizationGroup(group);
876 auto const cppReader = to_FlowReader(reader);
877 if ((cppGroup != nullptr) && (cppReader != nullptr))
878 {
879 cppGroup->removeReader(*cppReader);
880 return MXL_STATUS_OK;
881 }
882
883 return MXL_ERR_INVALID_ARG;
884 }
885 catch (...)
886 {
887 return MXL_ERR_UNKNOWN;
888 }
889}

◆ mxlFlowSynchronizationGroupWaitForDataAt()

MXL_EXPORT mxlStatus mxlFlowSynchronizationGroupWaitForDataAt ( mxlFlowSynchronizationGroup group,
uint64_t timestamp,
uint64_t timeoutNs )

Wait for the data corresponding to the specified timestamp to become available accross all flows currently added to the group.

Parameters
[in]groupA handle to the synchronization group that specifies the flows on which to wait for data.
[in]timestampThe timestamp for which to wait for corresponding data on each flow.
[in]timeoutNsHow long to wait for all data to become available (in nanoseconds).
Returns
MXL_STATUS_OK if the data corresponding to the specified timestamp has become available.

Definition at line 893 of file flow.cpp.

894{
895 try
896 {
897 if (auto const cppGroup = to_FlowSynchronizationGroup(group); cppGroup != nullptr)
898 {
899 return cppGroup->waitForDataAt(Timepoint{static_cast<std::int64_t>(timestamp)}, toDeadline(timeoutNs));
900 }
901
902 return MXL_ERR_INVALID_ARG;
903 }
904 catch (...)
905 {
906 return MXL_ERR_UNKNOWN;
907 }
908}
auto const timestamp
Definition test_time.cpp:61

◆ mxlFlowWriterCancelEvent()

MXL_EXPORT mxlStatus mxlFlowWriterCancelEvent ( mxlFlowWriter writer)

Cancel the open event without publishing or changing timestamp ordering.

Parameters
[in]writerWriter whose open event is to be discarded.
Return values
MXL_STATUS_OKThe write transaction was closed.
MXL_ERR_INVALID_ARGNo event is open.
MXL_ERR_INVALID_FLOW_WRITERThe handle is NULL or is not an event writer.
MXL_ERR_UNKNOWNAn internal exception occurred.

Definition at line 708 of file flow.cpp.

709{
710 try
711 {
712 if (auto object = dynamic_cast<EventFlowWriter*>(to_FlowWriter(handle)); object != nullptr)
713 {
714 return object->cancel();
715 }
717 }
718 catch (...)
719 {
720 return MXL_ERR_UNKNOWN;
721 }
722}
Backend contract for a single event producer with private write staging. Callers guarantee one writer...
@ MXL_ERR_INVALID_FLOW_WRITER
Definition mxl.h:33
FlowWriter * to_FlowWriter(mxlFlowWriter writer) noexcept
Utility function to convert from a C mxlFlowWriter handle to a C++ FlowWriter instance.
Definition Instance.hpp:257

◆ mxlFlowWriterCancelGrain()

MXL_EXPORT mxlStatus mxlFlowWriterCancelGrain ( mxlFlowWriter writer)
Parameters
[in]writerA valid flow writer

Definition at line 469 of file flow.cpp.

470{
471 try
472 {
473 if (auto const cppWriter = dynamic_cast<DiscreteFlowWriter*>(to_FlowWriter(writer)); cppWriter != nullptr)
474 {
475 return cppWriter->cancel();
476 }
478 }
479 catch (...)
480 {
481 return MXL_ERR_UNKNOWN;
482 }
483}

◆ mxlFlowWriterCancelSamples()

MXL_EXPORT mxlStatus mxlFlowWriterCancelSamples ( mxlFlowWriter writer)

Cancel the mutation of the previously opened range of samples.

Parameters
[in]writerA valid flow writer
Returns
The result code.
See also
mxlStatus

Definition at line 628 of file flow.cpp.

629{
630 try
631 {
632 if (auto const cppWriter = dynamic_cast<ContinuousFlowWriter*>(to_FlowWriter(writer)); cppWriter != nullptr)
633 {
634 return cppWriter->cancel();
635 }
637 }
638 catch (...)
639 {
640 return MXL_ERR_UNKNOWN;
641 }
642}

◆ mxlFlowWriterCommitEvent()

MXL_EXPORT mxlStatus mxlFlowWriterCommitEvent ( mxlFlowWriter writer,
mxlEventInfo const * event )

Publish one event entry (a complete event or one fragment) and wake waiting readers. Timestamps must be nondecreasing relative to the last committed event in this flow. Equal timestamps are allowed, including for fragments of the same event. An earlier timestamp returns MXL_ERR_INVALID_ARG without publishing or advancing the queue. A failed commit leaves the event open for correction or cancellation. Queue positions advance in commit order, independently of timestamps. The producer must commit all fragments of one logical event consecutively, ending with complete = 1 before starting any other event in this flow. Interleaving is forbidden even when events have different timestamps or DITs. This is a producer requirement; the API does not enforce fragment continuity or detect interleaving. Queue indices identify entries, not logical events.

Parameters
[in]writerWriter that owns the open event.
[in]eventMetadata to publish with the staged payload; must not be NULL.
Return values
MXL_STATUS_OKThe entry was published and the write transaction closed.
MXL_ERR_INVALID_ARGNo event is open, metadata is invalid, the timestamp decreases, the payload exceeds capacity, or event is NULL.
MXL_ERR_INVALID_FLOW_WRITERThe handle is NULL or is not an event writer.
MXL_ERR_FLOW_INVALIDPublication would overwrite an already-published or newer sequence tag.
MXL_ERR_OUT_OF_RANGE_TOO_LATEThe queue sequence index is exhausted.
MXL_ERR_UNKNOWNAn internal exception occurred.

Definition at line 686 of file flow.cpp.

687{
688 if (info == nullptr)
689 {
690 return MXL_ERR_INVALID_ARG;
691 }
692 try
693 {
694 if (auto object = dynamic_cast<EventFlowWriter*>(to_FlowWriter(handle)); object != nullptr)
695 {
696 return object->commit(*info);
697 }
699 }
700 catch (...)
701 {
702 return MXL_ERR_UNKNOWN;
703 }
704}

◆ mxlFlowWriterCommitGrain()

MXL_EXPORT mxlStatus mxlFlowWriterCommitGrain ( mxlFlowWriter writer,
mxlGrainInfo const * grain )

Inform mxl that a user is done writing the grain that was previously opened. This will in turn signal all readers waiting on the ringbuffer that a new grain is available. The mxlGrainInfo flags field in shared memory will be updated based on grain->flags This will increase the head and potentially the tail IF this grain is the new head.

Returns
The result code.
See also
mxlStatus
Return values
MXL_ERR_INVALID_ARGThe grain index is not the open grain, grainSize is larger than the grain payload, or validSlices is larger than totalSlices. Nothing is published.

Definition at line 487 of file flow.cpp.

488{
489 if (grainInfo == nullptr)
490 {
491 return MXL_ERR_INVALID_ARG;
492 }
493
494 try
495 {
496 if (auto const cppWriter = dynamic_cast<DiscreteFlowWriter*>(to_FlowWriter(writer)); cppWriter != nullptr)
497 {
498 return cppWriter->commit(*grainInfo);
499 }
501 }
502 catch (...)
503 {
504 return MXL_ERR_UNKNOWN;
505 }
506}

◆ mxlFlowWriterCommitSamples()

MXL_EXPORT mxlStatus mxlFlowWriterCommitSamples ( mxlFlowWriter writer)

Inform mxl that a user is done writing the sample range that was previously opened.

Parameters
[in]writerA valid flow writer
Returns
The result code.
See also
mxlStatus

Definition at line 646 of file flow.cpp.

647{
648 try
649 {
650 if (auto const cppWriter = dynamic_cast<ContinuousFlowWriter*>(to_FlowWriter(writer)); cppWriter != nullptr)
651 {
652 return cppWriter->commit();
653 }
655 }
656 catch (...)
657 {
658 return MXL_ERR_UNKNOWN;
659 }
660}

◆ mxlFlowWriterGetGrainInfo()

MXL_EXPORT mxlStatus mxlFlowWriterGetGrainInfo ( mxlFlowWriter writer,
uint64_t index,
mxlGrainInfo * mxlGrainInfo )

Get grain info for a given index. This is used to inspect the grain info without opening the grain for mutation.

Parameters
[in]writerA valid flow writer
[in]indexThe index of the grain to obtain.
[out]mxlGrainInfoThe requested mxlGrainInfo structure.
Returns
The result code.
See also
mxlStatus
Note
Please note that this function can only be called on writers that operate on discrete flows. Any attempt to call this function on a writer that operates on another type of flow will result in an error.

Definition at line 422 of file flow.cpp.

423{
424 try
425 {
426 if (grainInfo != nullptr)
427 {
428 if (auto const cppWriter = dynamic_cast<DiscreteFlowWriter*>(to_FlowWriter(writer)); cppWriter != nullptr)
429 {
430 *grainInfo = cppWriter->getGrainInfo(index);
431 return MXL_STATUS_OK;
432 }
433
435 }
436 return MXL_ERR_INVALID_ARG;
437 }
438 catch (...)
439 {
440 return MXL_ERR_UNKNOWN;
441 }
442}

◆ mxlFlowWriterGetMaxWriteLengthSamples()

MXL_EXPORT mxlStatus mxlFlowWriterGetMaxWriteLengthSamples ( mxlFlowWriter writer,
size_t * maxWriteLength )

Return the absolute maximum number of samples a write operation may write to a flow.

Parameters
[in]writerA valid flow writer
[out]maxWriteLengthA valid pointer referring to the location, at which to store the maximum number of samples a write operation may write to the flow writer operates on.
Returns
The result code.
See also
mxlStatus

Definition at line 581 of file flow.cpp.

582{
583 try
584 {
585 if (maxWriteLength != nullptr)
586 {
587 if (auto const cppWriter = dynamic_cast<ContinuousFlowWriter*>(to_FlowWriter(writer)); cppWriter != nullptr)
588 {
589 *maxWriteLength = cppWriter->getMaxWriteLength();
590 return MXL_STATUS_OK;
591 }
592
594 }
595 return MXL_ERR_INVALID_ARG;
596 }
597 catch (...)
598 {
599 return MXL_ERR_UNKNOWN;
600 }
601}

◆ mxlFlowWriterOpenEvent()

MXL_EXPORT mxlStatus mxlFlowWriterOpenEvent ( mxlFlowWriter writer,
mxlEventInfo * event,
uint8_t ** payload )

Open an event for writing

Parameters
[in]writerEvent flow writer acquired with mxlCreateFlowWriter.
[out]eventReceives initialized metadata; must not be NULL.
[out]payloadReceives the private writable buffer; must not be NULL. The buffer contents are not cleared on open. eventSize starts at zero; obtain capacity from mxlFlowConfigInfo.event.eventPayloadSize and set the actual size before commit.
Return values
MXL_STATUS_OKThe event is open for editing.
MXL_ERR_INVALID_ARGAn output pointer is NULL or an event is already open.
MXL_ERR_INVALID_FLOW_WRITERThe handle is NULL or is not an event writer.
MXL_ERR_UNKNOWNAn internal exception occurred.

Definition at line 664 of file flow.cpp.

665{
666 if ((info == nullptr) || (payload == nullptr))
667 {
668 return MXL_ERR_INVALID_ARG;
669 }
670 try
671 {
672 if (auto object = dynamic_cast<EventFlowWriter*>(to_FlowWriter(handle)); object != nullptr)
673 {
674 return object->openEvent(info, payload);
675 }
677 }
678 catch (...)
679 {
680 return MXL_ERR_UNKNOWN;
681 }
682}

◆ mxlFlowWriterOpenGrain()

MXL_EXPORT mxlStatus mxlFlowWriterOpenGrain ( mxlFlowWriter writer,
uint64_t index,
mxlGrainInfo * mxlGrainInfo,
uint8_t ** payload )

Open a grain for mutation. The flow writer will remember which index is currently opened. Before opening a new grain for mutation, the user must either cancel the mutation using mxlFlowWriterCancelGrain or mxlFlowWriterCommitGrain.

If the ring buffer entry for this index still holds an older grain, its header is reset: validSlices is set to 0 and MXL_GRAIN_FLAG_INVALID is cleared. If the entry already holds this index, the header is returned unchanged. This keeps the progress of an incomplete grain that is opened again, and it keeps the header that a fabrics initiator wrote into a target flow, so that the target application can commit the returned grain info as is.

Todo
Allow operating on multiple grains simultaneously, by making this function return a handle that has to be passed to mxlFlowWriterCommitGrain or mxlFlowWriterCancelGrain to identify the grain the call refers to.
Parameters
[in]writerA valid flow writer
[in]indexThe index of the grain to obtain
[out]mxlGrainInfoThe requested mxlGrainInfo structure.
[out]payloadThe requested grain payload.
Returns
The result code.
See also
mxlStatus
Note
Please note that this function can only be called on writers that operate on discrete flows. Any attempt to call this function on a writer that operates on another type of flow will result in an error.

Definition at line 446 of file flow.cpp.

447{
448 try
449 {
450 if ((grainInfo != nullptr) && (payload != nullptr))
451 {
452 if (auto const cppWriter = dynamic_cast<DiscreteFlowWriter*>(to_FlowWriter(writer)); cppWriter != nullptr)
453 {
454 return cppWriter->openGrain(index, grainInfo, payload);
455 }
456
458 }
459 return MXL_ERR_INVALID_ARG;
460 }
461 catch (...)
462 {
463 return MXL_ERR_UNKNOWN;
464 }
465}

◆ mxlFlowWriterOpenSamples()

MXL_EXPORT mxlStatus mxlFlowWriterOpenSamples ( mxlFlowWriter writer,
uint64_t index,
size_t count,
mxlMutableWrappedMultiBufferSlice * payloadBuffersSlices )

Open a specific set of mutable samples across all channels starting at a specific index for mutation.

Parameters
[in]indexThe head index of the samples that will be mutated.
[in]countThe number of samples in each channel that will be mutated.
[out]payloadBuffersSlicesA pointer to a mutable wrapped multi buffer slice that represents the requested range across all channel buffers.
Returns
A status code describing the outcome of the call.

Definition at line 605 of file flow.cpp.

606{
607 try
608 {
609 if (payloadBuffersSlices != nullptr)
610 {
611 if (auto const cppWriter = dynamic_cast<ContinuousFlowWriter*>(to_FlowWriter(writer)); cppWriter != nullptr)
612 {
613 return cppWriter->openSamples(index, count, *payloadBuffersSlices);
614 }
615
617 }
618 return MXL_ERR_INVALID_ARG;
619 }
620 catch (...)
621 {
622 return MXL_ERR_UNKNOWN;
623 }
624}

◆ mxlGetFlowDef()

MXL_EXPORT mxlStatus mxlGetFlowDef ( mxlInstance instance,
char const * flowId,
char * buffer,
size_t * bufferSize )

Get the flow definition used to create the given flow.

Parameters
[in]instanceThe mxl instance tied to domain we want to get the flow definition from. If invalid instance is provided, the function will return MXL_ERR_INVALID_ARG and do nothing.
[in]flowIdThe id of the flow we want to get the definition for. If nullptr, the function will return MXL_ERR_INVALID_ARG and do nothing.
[out]bufferA pointer to a buffer that will be filled with the flow definition. If nullptr, or if the buffer does not contain enough space to return the result (based on the bufferSize provided later), the function will return MXL_ERR_INVALID_ARG and update the value pointed to by the bufferSize with the required buffer size.
[in,out]bufferSizeA pointer to a variable with the length of the supplied buffer. If nullptr, the function will return MXL_ERR_INVALID_ARG and do nothing. If function succeeds, the value pointed to by this variable will be updated with the number of bytes written to the buffer (including the null terminator).
Returns
MXL_STATUS_OK when buffer was successfully filled with the flow definition, or other error codes based on the previous parameter description or other encountered errors.

Definition at line 86 of file flow.cpp.

87{
88 if (flowId == nullptr || bufferSize == nullptr)
89 {
91 }
92
93 try
94 {
95 if (auto const cppInstance = to_Instance(instance); cppInstance != nullptr)
96 {
97 if (auto const id = uuids::uuid::from_string(flowId); id.has_value())
98 {
99 auto const flowDef = cppInstance->getFlowDef(*id);
100 auto const requiredSize = flowDef.size() + 1; // +1 for the null terminator
101 if (buffer == nullptr || *bufferSize < requiredSize)
102 {
103 *bufferSize = requiredSize;
104 return MXL_ERR_INVALID_ARG;
105 }
106 *bufferSize = requiredSize;
107 std::strncpy(buffer, flowDef.c_str(), requiredSize);
108 return MXL_STATUS_OK;
109 }
110 }
111 return MXL_ERR_INVALID_ARG;
112 }
113 catch (std::filesystem::filesystem_error const& e)
114 {
115 if (e.code().value() == ENOENT)
116 {
118 }
119
120 MXL_ERROR("Failed to get flow definition : {}", e.what());
121 return MXL_ERR_UNKNOWN;
122 }
123 catch (std::exception const& e)
124 {
125 MXL_ERROR("Failed to get flow definition : {}", e.what());
126 }
127 catch (...)
128 {
129 MXL_ERROR("Failed to get flow definition : {}", "An unknown error occured.");
130 }
131 return MXL_ERR_UNKNOWN;
132}
uint8_t * buffer
Set a mark at the beginning and the end of the grain payload.

◆ mxlIsFlowActive()

MXL_EXPORT mxlStatus mxlIsFlowActive ( mxlInstance instance,
char const * flowId,
bool * isActive )

Verify if a flow has an active writer or not

Parameters
[in]instanceThe mxl instance created using mxlCreateInstance
[in]flowIdThe ID of the flow to check.
[out]isActiveA pointer to a boolean that will be set to true if the flow has an active writer, false otherwise.
Returns
MXL_STATUS_OK if the flow exists and has been tested successfully, or an error code otherwise.

Definition at line 28 of file flow.cpp.

29{
30 try
31 {
32 if (isActive != nullptr)
33 {
34 if (auto const cppInstance = to_Instance(instance); cppInstance != nullptr)
35 {
36 if ((flowId != nullptr) && uuids::uuid::is_valid_uuid(flowId))
37 {
38 auto const id = uuids::uuid::from_string(flowId);
39 if (id.has_value())
40 {
41 auto const domain = cppInstance->getDomain();
42
43 // Try to obtain an exclusive lock on the flow data file. If we can obtain one it means that no
44 // other process is writing to the flow.
45 auto flowDataFile = mxl::lib::makeFlowDataFilePath(domain, flowId);
46
47 auto const fd = ::open(flowDataFile.c_str(), O_RDONLY | O_CLOEXEC);
48 if (fd < 0)
49 {
50 auto const error = errno;
51 if (error == ENOENT)
52 {
54 }
55
56 MXL_ERROR("Failed to open flow data file {} : {}", flowDataFile.string(), std::strerror(error));
58 }
59
60 // Try to obtain an exclusive lock on the file descriptor. Do not block if the lock cannot be obtained.
61 auto const active = ::flock(fd, LOCK_EX | LOCK_NB) < 0;
62 close(fd);
63
64 *isActive = active;
65 return MXL_STATUS_OK;
66 }
67 }
68 }
70 }
72 }
73 catch (std::exception const& e)
74 {
75 MXL_ERROR("Failed to check if flow is active : {}", e.what());
76 }
77 catch (...)
78 {
79 MXL_ERROR("Failed to check if flow is active : {}", "An unknown error occured.");
80 }
81 return MXL_ERR_UNKNOWN;
82}
std::filesystem::path makeFlowDataFilePath(std::filesystem::path const &flowDirectory)
Definition PathUtils.cpp:17
bool active

◆ mxlReleaseFlowReader()

MXL_EXPORT mxlStatus mxlReleaseFlowReader ( mxlInstance instance,
mxlFlowReader reader )

Definition at line 177 of file flow.cpp.

178{
179 try
180 {
181 auto const cppInstance = to_Instance(instance);
182 auto const cppReader = to_FlowReader(reader);
183 if ((cppInstance != nullptr) && (cppReader != nullptr))
184 {
185 cppInstance->releaseReader(cppReader);
186 return MXL_STATUS_OK;
187 }
188 return MXL_ERR_INVALID_ARG;
189 }
190 catch (...)
191 {
192 return MXL_ERR_UNKNOWN;
193 }
194}

◆ mxlReleaseFlowSynchronizationGroup()

MXL_EXPORT mxlStatus mxlReleaseFlowSynchronizationGroup ( mxlInstance instance,
mxlFlowSynchronizationGroup group )

Release a synchronization group that is no longer needed and free all underlying resources associated with it.

Parameters
[in]instancethe instance on which the group was previously created.
[in]groupA handle referring to the group that should be released.
Returns
MXL_STATUS_OK if the group was successfully released.

Definition at line 791 of file flow.cpp.

792{
793 try
794 {
795 auto const cppInstance = to_Instance(instance);
796 auto const cppGroup = to_FlowSynchronizationGroup(group);
797 if ((cppInstance != nullptr) && (cppGroup != nullptr))
798 {
799 cppInstance->releaseFlowSynchronizationGroup(cppGroup);
800 return MXL_STATUS_OK;
801 }
802
803 return MXL_ERR_INVALID_ARG;
804 }
805 catch (...)
806 {
807 return MXL_ERR_UNKNOWN;
808 }
809}

◆ mxlReleaseFlowWriter()

MXL_EXPORT mxlStatus mxlReleaseFlowWriter ( mxlInstance instance,
mxlFlowWriter writer )

Definition at line 262 of file flow.cpp.

263{
264 if ((instance == nullptr) || (writer == nullptr))
265 {
266 return MXL_ERR_INVALID_ARG;
267 }
268
269 auto err = MXL_STATUS_OK;
270 auto const cppInstance = to_Instance(instance);
271 auto const cppWriter = to_FlowWriter(writer);
272
273 if ((cppInstance == nullptr) || (cppWriter == nullptr))
274 {
275 return MXL_ERR_INVALID_ARG;
276 }
277
278 try
279 {
280 cppInstance->releaseWriter(cppWriter);
281 }
282 catch (std::exception const& ex)
283 {
284 MXL_ERROR("Failed to release writer: {}", ex.what());
285 return MXL_ERR_UNKNOWN;
286 }
287
288 return err;
289}