32 if (isActive !=
nullptr)
34 if (
auto const cppInstance =
to_Instance(instance); cppInstance !=
nullptr)
36 if ((
flowId !=
nullptr) && uuids::uuid::is_valid_uuid(
flowId))
38 auto const id = uuids::uuid::from_string(
flowId);
41 auto const domain = cppInstance->getDomain();
47 auto const fd = ::open(flowDataFile.c_str(), O_RDONLY | O_CLOEXEC);
50 auto const error = errno;
56 MXL_ERROR(
"Failed to open flow data file {} : {}", flowDataFile.string(), std::strerror(error));
61 auto const active = ::flock(fd, LOCK_EX | LOCK_NB) < 0;
73 catch (std::exception
const& e)
75 MXL_ERROR(
"Failed to check if flow is active : {}", e.what());
79 MXL_ERROR(
"Failed to check if flow is active : {}",
"An unknown error occured.");
88 if (
flowId ==
nullptr || bufferSize ==
nullptr)
95 if (
auto const cppInstance =
to_Instance(instance); cppInstance !=
nullptr)
97 if (
auto const id = uuids::uuid::from_string(
flowId);
id.has_value())
99 auto const flowDef = cppInstance->getFlowDef(*
id);
100 auto const requiredSize =
flowDef.size() + 1;
101 if (
buffer ==
nullptr || *bufferSize < requiredSize)
103 *bufferSize = requiredSize;
106 *bufferSize = requiredSize;
113 catch (std::filesystem::filesystem_error
const& e)
115 if (e.code().value() == ENOENT)
120 MXL_ERROR(
"Failed to get flow definition : {}", e.what());
123 catch (std::exception
const& e)
125 MXL_ERROR(
"Failed to get flow definition : {}", e.what());
129 MXL_ERROR(
"Failed to get flow definition : {}",
"An unknown error occured.");
142 if (
auto const cppInstance =
to_Instance(instance); cppInstance !=
nullptr)
144 if ((
flowId !=
nullptr) && uuids::uuid::is_valid_uuid(
flowId))
154 catch (std::filesystem::filesystem_error
const& e)
156 auto const code = e.code();
157 if (code.value() == ENOENT)
162 MXL_ERROR(
"Failed to create flow reader: {}", e.what());
163 if ((code == std::errc::permission_denied) || (code == std::errc::operation_not_permitted))
183 if ((cppInstance !=
nullptr) && (cppReader !=
nullptr))
185 cppInstance->releaseReader(cppReader);
201 if ((instance ==
nullptr) || (
flowDef ==
nullptr) || (
writer ==
nullptr))
206 auto flowData = std::unique_ptr<FlowData>{};
209 if (cppInstance ==
nullptr)
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.");
219 auto [flowConfigInfo, flowWriter, flowCreated] = cppInstance->createFlowWriter(
flowDef,
220 (options ==
nullptr) ? std::nullopt : std::make_optional(options));
228 if (created !=
nullptr)
230 *created = flowCreated;
233 catch (std::filesystem::filesystem_error
const& e)
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))
243 MXL_ERROR(
"Filesystem error: {}", code.message());
247 catch (std::exception
const& e)
249 MXL_ERROR(
"Failed to create flow : {}", e.what());
264 if ((instance ==
nullptr) || (
writer ==
nullptr))
273 if ((cppInstance ==
nullptr) || (cppWriter ==
nullptr))
280 cppInstance->releaseWriter(cppWriter);
282 catch (std::exception
const& ex)
284 MXL_ERROR(
"Failed to release writer: {}", ex.what());
301 *info = cppReader->getFlowInfo();
324 *info = cppReader->getFlowInfo().config;
347 *info = cppReader->getFlowInfo().runtime;
374 if ((grainInfo !=
nullptr) && (payload !=
nullptr))
378 return cppReader->getGrain(
index, minValidSlices, toDeadline(timeoutNs), grainInfo, payload);
404 if ((grainInfo !=
nullptr) && (payload !=
nullptr))
408 return cppReader->getGrain(
index, minValidSlices, grainInfo, payload);
426 if (grainInfo !=
nullptr)
430 *grainInfo = cppWriter->getGrainInfo(
index);
450 if ((grainInfo !=
nullptr) && (payload !=
nullptr))
454 return cppWriter->openGrain(
index, grainInfo, payload);
475 return cppWriter->cancel();
489 if (grainInfo ==
nullptr)
498 return cppWriter->commit(*grainInfo);
514 if (maxReadLength !=
nullptr)
518 *maxReadLength = cppReader->getMaxReadLength();
539 if (payloadBuffersSlices !=
nullptr)
543 return cppReader->getSamples(
index,
count, toDeadline(timeoutNs), *payloadBuffersSlices);
562 if (payloadBuffersSlices !=
nullptr)
566 return cppReader->getSamples(
index,
count, *payloadBuffersSlices);
585 if (maxWriteLength !=
nullptr)
589 *maxWriteLength = cppWriter->getMaxWriteLength();
609 if (payloadBuffersSlices !=
nullptr)
613 return cppWriter->openSamples(
index,
count, *payloadBuffersSlices);
634 return cppWriter->cancel();
652 return cppWriter->commit();
666 if ((info ==
nullptr) || (payload ==
nullptr))
674 return object->openEvent(info, payload);
696 return object->commit(*info);
714 return object->cancel();
728 if ((info ==
nullptr) || (payload ==
nullptr))
736 return object->getEvent(toDeadline(timeoutNs), info, payload);
750 if ((info ==
nullptr) || (payload ==
nullptr))
758 return object->getEvent(toDeadline(0), info, payload);
775 if (cppInstance !=
nullptr)
797 if ((cppInstance !=
nullptr) && (cppGroup !=
nullptr))
799 cppInstance->releaseFlowSynchronizationGroup(cppGroup);
821 if (
auto const discreteReader =
dynamic_cast<DiscreteFlowReader const*
>(cppReader); discreteReader !=
nullptr)
826 if (
auto const continuousReader =
dynamic_cast<ContinuousFlowReader const*
>(cppReader); continuousReader !=
nullptr)
828 cppGroup->addReader(*continuousReader);
854 cppGroup->addReader(*cppReader, minValidSlices);
877 if ((cppGroup !=
nullptr) && (cppReader !=
nullptr))
879 cppGroup->removeReader(*cppReader);
899 return cppGroup->waitForDataAt(
Timepoint{
static_cast<std::int64_t
>(
timestamp)}, toDeadline(timeoutNs));
Paths and filenames utilities used by the MXL SDK.
Backend contract for reading complete event entries or fragments in queue order. Each reader has one ...
Backend contract for a single event producer with private write staging. Callers guarantee one writer...
MXL_EXPORT mxlStatus mxlCreateFlowReader(mxlInstance instance, char const *flowId, char const *, mxlFlowReader *reader)
MXL_EXPORT mxlStatus mxlFlowWriterCommitGrain(mxlFlowWriter writer, mxlGrainInfo const *grainInfo)
MXL_EXPORT mxlStatus mxlFlowReaderGetEvent(mxlFlowReader handle, uint64_t timeoutNs, mxlEventInfo *info, uint8_t **payload)
MXL_EXPORT mxlStatus mxlReleaseFlowReader(mxlInstance instance, mxlFlowReader reader)
MXL_EXPORT mxlStatus mxlFlowSynchronizationGroupRemoveReader(mxlFlowSynchronizationGroup group, mxlFlowReader reader)
MXL_EXPORT mxlStatus mxlFlowReaderGetGrainSlice(mxlFlowReader reader, uint64_t index, uint16_t minValidSlices, uint64_t timeoutNs, mxlGrainInfo *grainInfo, uint8_t **payload)
MXL_EXPORT mxlStatus mxlFlowSynchronizationGroupWaitForDataAt(mxlFlowSynchronizationGroup group, uint64_t timestamp, uint64_t timeoutNs)
MXL_EXPORT mxlStatus mxlFlowReaderGetMaxReadLengthSamples(mxlFlowReader reader, size_t *maxReadLength)
MXL_EXPORT mxlStatus mxlCreateFlowSynchronizationGroup(mxlInstance instance, mxlFlowSynchronizationGroup *group)
MXL_EXPORT mxlStatus mxlFlowReaderGetGrainSliceNonBlocking(mxlFlowReader reader, uint64_t index, uint16_t minValidSlices, mxlGrainInfo *grainInfo, uint8_t **payload)
MXL_EXPORT mxlStatus mxlFlowReaderGetSamplesNonBlocking(mxlFlowReader reader, uint64_t index, size_t count, mxlWrappedMultiBufferSlice *payloadBuffersSlices)
MXL_EXPORT mxlStatus mxlFlowReaderGetGrain(mxlFlowReader reader, uint64_t index, uint64_t timeoutNs, mxlGrainInfo *grainInfo, uint8_t **payload)
MXL_EXPORT mxlStatus mxlFlowWriterCommitSamples(mxlFlowWriter writer)
MXL_EXPORT mxlStatus mxlReleaseFlowSynchronizationGroup(mxlInstance instance, mxlFlowSynchronizationGroup group)
MXL_EXPORT mxlStatus mxlFlowWriterGetGrainInfo(mxlFlowWriter writer, uint64_t index, mxlGrainInfo *grainInfo)
MXL_EXPORT mxlStatus mxlFlowSynchronizationGroupAddReader(mxlFlowSynchronizationGroup group, mxlFlowReader reader)
MXL_EXPORT mxlStatus mxlFlowSynchronizationGroupAddPartialGrainReader(mxlFlowSynchronizationGroup group, mxlFlowReader reader, uint16_t minValidSlices)
MXL_EXPORT mxlStatus mxlFlowWriterCancelSamples(mxlFlowWriter writer)
MXL_EXPORT mxlStatus mxlFlowReaderGetSamples(mxlFlowReader reader, uint64_t index, size_t count, uint64_t timeoutNs, mxlWrappedMultiBufferSlice *payloadBuffersSlices)
MXL_EXPORT mxlStatus mxlFlowWriterGetMaxWriteLengthSamples(mxlFlowWriter writer, size_t *maxWriteLength)
MXL_EXPORT mxlStatus mxlFlowWriterCommitEvent(mxlFlowWriter handle, mxlEventInfo const *info)
MXL_EXPORT mxlStatus mxlReleaseFlowWriter(mxlInstance instance, mxlFlowWriter writer)
MXL_EXPORT mxlStatus mxlFlowReaderGetRuntimeInfo(mxlFlowReader reader, mxlFlowRuntimeInfo *info)
MXL_EXPORT mxlStatus mxlFlowReaderGetConfigInfo(mxlFlowReader reader, mxlFlowConfigInfo *info)
MXL_EXPORT mxlStatus mxlFlowWriterOpenGrain(mxlFlowWriter writer, uint64_t index, mxlGrainInfo *grainInfo, uint8_t **payload)
MXL_EXPORT mxlStatus mxlFlowReaderGetInfo(mxlFlowReader reader, mxlFlowInfo *info)
MXL_EXPORT mxlStatus mxlFlowWriterOpenEvent(mxlFlowWriter handle, mxlEventInfo *info, uint8_t **payload)
MXL_EXPORT mxlStatus mxlFlowWriterCancelGrain(mxlFlowWriter writer)
MXL_EXPORT mxlStatus mxlCreateFlowWriter(mxlInstance instance, char const *flowDef, char const *options, mxlFlowWriter *writer, mxlFlowConfigInfo *configInfo, bool *created)
MXL_EXPORT mxlStatus mxlFlowWriterOpenSamples(mxlFlowWriter writer, uint64_t index, size_t count, mxlMutableWrappedMultiBufferSlice *payloadBuffersSlices)
MXL_EXPORT mxlStatus mxlFlowReaderGetEventNonBlocking(mxlFlowReader handle, mxlEventInfo *info, uint8_t **payload)
Attempt to read one event entry without waiting for publication.
MXL_EXPORT mxlStatus mxlFlowWriterCancelEvent(mxlFlowWriter handle)
Cancel the open event without publishing or changing timestamp ordering.
MXL_EXPORT mxlStatus mxlFlowReaderGetGrainNonBlocking(mxlFlowReader reader, uint64_t index, mxlGrainInfo *grainInfo, uint8_t **payload)
MXL_EXPORT mxlStatus mxlIsFlowActive(mxlInstance instance, char const *flowId, bool *isActive)
MXL_EXPORT mxlStatus mxlGetFlowDef(mxlInstance instance, char const *flowId, char *buffer, size_t *bufferSize)
Public flow reader, writer, payload and synchronization APIs.
struct mxlFlowReader_t * mxlFlowReader
struct mxlGrainInfo_t mxlGrainInfo
struct mxlEventInfo_t mxlEventInfo
Metadata for one event queue entry, either a complete event or a fragment.
struct mxlWrappedMultiBufferSlice_t mxlWrappedMultiBufferSlice
struct mxlFlowWriter_t * mxlFlowWriter
struct mxlMutableWrappedMultiBufferSlice_t mxlMutableWrappedMultiBufferSlice
struct mxlFlowSynchronizationGroup_t * mxlFlowSynchronizationGroup
#define MXL_GRAIN_VALID_SLICES_ALL
struct mxlFlowRuntimeInfo_t mxlFlowRuntimeInfo
struct mxlFlowConfigInfo_t mxlFlowConfigInfo
struct mxlFlowInfo_t mxlFlowInfo
mxlStatus
MXL SDK Status codes.
@ MXL_ERR_PERMISSION_DENIED
@ MXL_ERR_INVALID_FLOW_WRITER
@ MXL_ERR_INVALID_FLOW_READER
struct mxlInstance_t * mxlInstance
FlowWriter * to_FlowWriter(mxlFlowWriter writer) noexcept
Utility function to convert from a C mxlFlowWriter handle to a C++ FlowWriter instance.
std::filesystem::path makeFlowDataFilePath(std::filesystem::path const &flowDirectory)
FlowReader * to_FlowReader(mxlFlowReader reader) noexcept
Utility function to convert from a C mxlFlowReader handle to a C++ FlowReader instance.
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.
FlowSynchronizationGroup * to_FlowSynchronizationGroup(mxlFlowSynchronizationGroup group) noexcept
Utility function to convert from a C mxlFlowSynchronizationGroup handle to a C++ FlowSynchronizationG...
Instance * to_Instance(mxlInstance instance) noexcept
Utility function to convert from a C mxlInstance handle to a C++ Instance class.
uint8_t * buffer
Set a mark at the beginning and the end of the grain payload.
mxlFlowConfigInfo configInfo