MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
mxl.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <mxl/platform.h>
Include dependency graph for mxl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mxlVersionType
 MXL SDK Semantic versionning structure. More...

Typedefs

typedef struct mxlInstance_t * mxlInstance
typedef enum mxlStatus mxlStatus
 MXL SDK Status codes.
typedef struct mxlVersionType mxlVersionType
 MXL SDK Semantic versionning structure.

Enumerations

enum  mxlStatus {
  MXL_STATUS_OK , MXL_ERR_UNKNOWN , MXL_ERR_FLOW_NOT_FOUND , MXL_ERR_OUT_OF_RANGE_TOO_LATE ,
  MXL_ERR_OUT_OF_RANGE_TOO_EARLY , MXL_ERR_INVALID_FLOW_READER , MXL_ERR_INVALID_FLOW_WRITER , MXL_ERR_TIMEOUT ,
  MXL_ERR_INVALID_ARG , MXL_ERR_CONFLICT , MXL_ERR_PERMISSION_DENIED , MXL_ERR_FLOW_INVALID ,
  MXL_ERR_STRLEN = 1024 , MXL_ERR_INTERRUPTED , MXL_ERR_NO_FABRIC , MXL_ERR_INVALID_STATE ,
  MXL_ERR_INTERNAL , MXL_ERR_NOT_READY , MXL_ERR_NOT_FOUND , MXL_ERR_EXISTS ,
  MXL_ERR_UNSUPPORTED_OPERATION
}
 MXL SDK Status codes. More...

Functions

MXL_EXPORT mxlInstance mxlCreateInstance (char const *in_mxlDomain, char const *in_options)
MXL_EXPORT mxlStatus mxlDestroyInstance (mxlInstance in_instance)
MXL_EXPORT mxlStatus mxlGarbageCollectFlows (mxlInstance in_instance)
MXL_EXPORT mxlStatus mxlGetVersion (mxlVersionType *out_version)
MXL_EXPORT mxlStatus mxlIsTmpFs (char const *in_path, bool *out_isTmpFs)

Typedef Documentation

◆ mxlInstance

typedef struct mxlInstance_t* mxlInstance

An opaque type representing an MXL instance.

Definition at line 74 of file mxl.h.

◆ mxlStatus

typedef enum mxlStatus mxlStatus

MXL SDK Status codes.

◆ mxlVersionType

typedef struct mxlVersionType mxlVersionType

MXL SDK Semantic versionning structure.

Enumeration Type Documentation

◆ mxlStatus

enum mxlStatus

MXL SDK Status codes.

Enumerator
MXL_STATUS_OK 
MXL_ERR_UNKNOWN 
MXL_ERR_FLOW_NOT_FOUND 
MXL_ERR_OUT_OF_RANGE_TOO_LATE 
MXL_ERR_OUT_OF_RANGE_TOO_EARLY 
MXL_ERR_INVALID_FLOW_READER 
MXL_ERR_INVALID_FLOW_WRITER 
MXL_ERR_TIMEOUT 
MXL_ERR_INVALID_ARG 
MXL_ERR_CONFLICT 
MXL_ERR_PERMISSION_DENIED 
MXL_ERR_FLOW_INVALID 
MXL_ERR_STRLEN 
MXL_ERR_INTERRUPTED 
MXL_ERR_NO_FABRIC 
MXL_ERR_INVALID_STATE 
MXL_ERR_INTERNAL 
MXL_ERR_NOT_READY 
MXL_ERR_NOT_FOUND 
MXL_ERR_EXISTS 
MXL_ERR_UNSUPPORTED_OPERATION 

Definition at line 21 of file mxl.h.

22 {
24
25 // Do not check for MXL_ERR_UNKNOWN. Functions that return MXL_ERR_UNKNOWN in a certain situation, may return
26 // a more descriptive error code in the future and this would not be considered a breaking change.
28
38
39 // A flow is invalid from a reader point of view if its data file has been replaced
40 // (for example, if a writer restarted and recreated the flow)
42
43 /* fabrics.h errors */
44 MXL_ERR_STRLEN = 1024,
53 } mxlStatus;
mxlStatus
MXL SDK Status codes.
Definition mxl.h:22
@ MXL_ERR_FLOW_INVALID
Definition mxl.h:41
@ MXL_ERR_NOT_READY
Definition mxl.h:49
@ MXL_ERR_TIMEOUT
Definition mxl.h:34
@ MXL_ERR_INVALID_STATE
Definition mxl.h:47
@ MXL_ERR_UNKNOWN
Definition mxl.h:27
@ MXL_ERR_PERMISSION_DENIED
Definition mxl.h:37
@ MXL_ERR_OUT_OF_RANGE_TOO_EARLY
Definition mxl.h:31
@ MXL_ERR_CONFLICT
Definition mxl.h:36
@ MXL_ERR_INTERRUPTED
Definition mxl.h:45
@ MXL_ERR_INTERNAL
Definition mxl.h:48
@ MXL_ERR_FLOW_NOT_FOUND
Definition mxl.h:29
@ MXL_ERR_INVALID_ARG
Definition mxl.h:35
@ MXL_ERR_INVALID_FLOW_WRITER
Definition mxl.h:33
@ MXL_ERR_UNSUPPORTED_OPERATION
Definition mxl.h:52
@ MXL_STATUS_OK
Definition mxl.h:23
@ MXL_ERR_INVALID_FLOW_READER
Definition mxl.h:32
@ MXL_ERR_EXISTS
Definition mxl.h:51
@ MXL_ERR_STRLEN
Definition mxl.h:44
@ MXL_ERR_NO_FABRIC
Definition mxl.h:46
@ MXL_ERR_OUT_OF_RANGE_TOO_LATE
Definition mxl.h:30
@ MXL_ERR_NOT_FOUND
Definition mxl.h:50

Function Documentation

◆ mxlCreateInstance()

MXL_EXPORT mxlInstance mxlCreateInstance ( char const * in_mxlDomain,
char const * in_options )

Create a new MXL instance for a specific domain.

Parameters
in_mxlDomainThe domain is the directory where the MXL ringbuffers files are stored. It should live on a tmpfs filesystem.
in_optionsOptional JSON string containing additional SDK options. Currently not used.
Returns
A pointer to the MXL instance or NULL if the instance could not be created or in_mxlDomain is NULL.

Definition at line 45 of file mxl.cpp.

46{
47 if (in_mxlDomain == nullptr)
48 {
49 MXL_ERROR("Failed to create instance : the domain is NULL");
50 return nullptr;
51 }
52
53 try
54 {
55 auto const opts = (in_options != nullptr) ? in_options : "";
56 auto domainWatcher = std::make_shared<mxl::lib::DomainWatcher>(in_mxlDomain);
57 auto flowIoFactory = std::make_unique<mxl::lib::PosixFlowIoFactory>(domainWatcher);
58 return reinterpret_cast<mxlInstance>(new mxl::lib::Instance{in_mxlDomain, opts, std::move(flowIoFactory), std::move(domainWatcher)});
59 }
60 catch (std::exception& e)
61 {
62 MXL_ERROR("Failed to create instance : {}", e.what());
63 return nullptr;
64 }
65 catch (...)
66 {
67 MXL_ERROR("Failed to create instance");
68 return nullptr;
69 }
70}
#define MXL_ERROR(...)
Definition Logging.hpp:67
struct mxlInstance_t * mxlInstance
Definition mxl.h:74

◆ mxlDestroyInstance()

MXL_EXPORT mxlStatus mxlDestroyInstance ( mxlInstance in_instance)

Destroy the MXL instance. This will also release all flows readers/writers associated with the instance.

Parameters
in_instanceThe MXL instance to destroy.
Returns
MXL_STATUS_OK if the instance was successfully destroyed, MXL_ERR_INVALID_ARG if the pointer passed was NULL. MXL_ERR_UNKNOWN if an error occurred during destruction.

Definition at line 106 of file mxl.cpp.

107{
108 try
109 {
110 delete mxl::lib::to_Instance(in_instance);
111 return (in_instance != nullptr) ? MXL_STATUS_OK : MXL_ERR_INVALID_ARG;
112 }
113 catch (...)
114 {
115 return MXL_ERR_UNKNOWN;
116 }
117}
Instance * to_Instance(mxlInstance instance) noexcept
Utility function to convert from a C mxlInstance handle to a C++ Instance class.
Definition Instance.hpp:247

◆ mxlGarbageCollectFlows()

MXL_EXPORT mxlStatus mxlGarbageCollectFlows ( mxlInstance in_instance)

Iterates over all flows in the MXL domain and deletes any flows that are no longer active (in other words, no readers or writers are using them. This typically happens when an application creating flows writers crashes or exits without cleaning up. A flow is considered active if a shared advisory lock is held on the data file of the flow.

Definition at line 121 of file mxl.cpp.

122{
123 try
124 {
125 if (auto const instance = mxl::lib::to_Instance(in_instance); instance != nullptr)
126 {
127 MXL_DEBUG("Starting garbage collection of flows");
128 [[maybe_unused]]
129 auto count = instance->garbageCollect();
130 MXL_DEBUG("Garbage collected {} flows", count);
131 return MXL_STATUS_OK;
132 }
133 else
134 {
135 return MXL_ERR_INVALID_ARG;
136 }
137 }
138 catch (...)
139 {
140 return MXL_ERR_UNKNOWN;
141 }
142}
#define MXL_DEBUG(...)
Definition Logging.hpp:34
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.

◆ mxlGetVersion()

MXL_EXPORT mxlStatus mxlGetVersion ( mxlVersionType * out_version)

Accessor for the version of the MXL SDK.

Parameters
out_versionPointer to a mxlVersionType structure to be filled with the version information.
Returns
MXL_STATUS_OK if the version was successfully retrieved, MXL_ERR_INVALID_ARG if the pointer passed was NULL.

Definition at line 27 of file mxl.cpp.

28{
29 if (out_version != nullptr)
30 {
31 out_version->major = MXL_VERSION_MAJOR;
32 out_version->minor = MXL_VERSION_MINOR;
33 out_version->bugfix = MXL_VERSION_PATCH;
34 out_version->build = MXL_VERSION_BUILD;
35 out_version->full = g_mxl_version_string;
36 return MXL_STATUS_OK;
37 }
38 else
39 {
41 }
42}
static char const g_mxl_version_string[]
Definition mxl.cpp:23
uint16_t minor
Definition mxl.h:59
char const * full
Definition mxl.h:62
uint16_t build
Definition mxl.h:61
uint16_t bugfix
Definition mxl.h:60
uint16_t major
Definition mxl.h:58

◆ mxlIsTmpFs()

MXL_EXPORT mxlStatus mxlIsTmpFs ( char const * in_path,
bool * out_isTmpFs )

Checks whether the given path resides on a RAM-backed filesystem.

On Linux, this detects tmpfs and ramfs using statfs(). On macOS, this checks the filesystem type name reported by statfs(). On other platforms, this always sets out_isTmpFs to false.

Parameters
in_pathThe filesystem path to check.
out_isTmpFsPointer to a bool that will be set to true if the path is on a RAM-backed filesystem, false otherwise.
Returns
MXL_STATUS_OK on success, MXL_ERR_INVALID_ARG if in_path or out_isTmpFs is NULL, MXL_ERR_UNKNOWN if the filesystem type could not be determined.

Definition at line 73 of file mxl.cpp.

74{
75 if ((in_path == nullptr) || (out_isTmpFs == nullptr))
76 {
78 }
79
80#ifdef __linux__
81 using statfs_t = struct statfs;
82 auto buf = statfs_t{};
83 if (::statfs(in_path, &buf) != 0)
84 {
85 return MXL_ERR_UNKNOWN;
86 }
87 *out_isTmpFs = (buf.f_type == TMPFS_MAGIC) || (buf.f_type == RAMFS_MAGIC);
88 return MXL_STATUS_OK;
89#elif defined(__APPLE__)
90 using statfs_t = struct statfs;
91 auto buf = statfs_t{};
92 if (::statfs(in_path, &buf) != 0)
93 {
94 return MXL_ERR_UNKNOWN;
95 }
96 *out_isTmpFs = std::strcmp(buf.f_fstypename, "tmpfs") == 0;
97 return MXL_STATUS_OK;
98#else
99 *out_isTmpFs = false;
100 return MXL_STATUS_OK;
101#endif
102}