MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
Initiator.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#include "Initiator.hpp"
6#include <exception>
8#include "mxl/fabrics.h"
9#include "Exception.hpp"
11#include "RCInitiator.hpp"
12#include "RDMInitiator.hpp"
13
15{
16
21
23 {
24 if (!_inner)
25 {
26 return;
27 }
28
29 try
30 {
31 _inner->shutdown();
32 }
33 catch (std::exception const& e)
34 {
35 MXL_ERROR("Failed to shut down the initiator: {}", e.what());
36 }
37
38 _inner.reset();
39 }
40
42 {
43 return reinterpret_cast<InitiatorWrapper*>(api);
44 }
45
47 {
48 return reinterpret_cast<mxlFabricsInitiator>(this);
49 }
50
52 {
54
55 auto const [info, provierConfig] = selectSourceInterface(config.interface, /* target */ false);
56 switch (info.view().endpointType())
57 {
58 case FI_EP_MSG: _inner = RCInitiator::setup(config, info.view(), options); break;
59 case FI_EP_RDM: _inner = RDMInitiator::setup(config, info.view(), options); break;
60 default: throw Exception::invalidState("unsupported endpoint type");
61 }
62 }
63
65 {
66 if (!_inner)
67 {
68 throw Exception::invalidState("Initiator is not set up");
69 }
70
71 _inner->addTarget(targetInfo);
72 }
73
75 {
76 if (!_inner)
77 {
78 throw Exception::invalidState("Initiator is not set up");
79 }
80
81 _inner->removeTarget(targetInfo);
82 }
83
84 void InitiatorWrapper::transferGrain(std::uint64_t grainIndex, std::uint16_t startSlice, std::uint16_t endSlice)
85 {
86 if (!_inner)
87 {
88 throw Exception::invalidState("Initiator is not set up");
89 }
90
91 _inner->transferGrain(grainIndex, startSlice, endSlice);
92 }
93
94 void InitiatorWrapper::transferGrainToTarget(Endpoint::Id targetId, std::uint64_t localIndex, std::uint64_t remoteIndex,
95 std::uint64_t payloadOffset, std::uint16_t startSlice, std::uint16_t endSlice)
96 {
97 if (!_inner)
98 {
99 throw Exception::invalidState("Initiator is not set up");
100 }
101
102 _inner->transferGrainToTarget(targetId, localIndex, remoteIndex, payloadOffset, startSlice, endSlice);
103 }
104
105 void InitiatorWrapper::transferSamples(std::uint64_t headIndex, std::size_t count)
106 {
107 if (!_inner)
108 {
109 throw Exception::invalidState("Initiator is not set up");
110 }
111
112 _inner->transferSamples(headIndex, count);
113 }
114
116 {
117 if (!_inner)
118 {
119 throw Exception::invalidState("Initiator is not set up");
120 }
121
122 return _inner->makeProgress();
123 }
124
126 {
127 if (!_inner)
128 {
129 throw Exception::invalidState("Initiator is not set up");
130 }
131
132 return _inner->makeProgressBlocking(timeout);
133 }
134
135}
#define MXL_ERROR(...)
Definition Logging.hpp:67
std::uintptr_t Id
An id type that can be used to reference this endpoint from completions and events.
Definition Endpoint.hpp:38
static Exception invalidState(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_STATE exception.
Definition Exception.hpp:59
A wrapper around Initiator implementations.
Initiator::MakeProgressResult makeProgressBlocking(std::chrono::steady_clock::duration)
Attempts to progress execution, including connection management and data operations.
void addTarget(TargetInfo const &targetInfo)
Add a target to the initiator.
Definition Initiator.cpp:64
~InitiatorWrapper()
Shut down the underlying initiator before it is destroyed.
Definition Initiator.cpp:17
void setup(mxlFabricsInitiatorConfig const &config, InitiatorSetupOptions const &options={})
Set up the initiator with the specified configuration.
Definition Initiator.cpp:51
static InitiatorWrapper * fromAPI(mxlFabricsInitiator api) noexcept
Convert an mxlFabricsInitiator API object to its underlying InitiatorWrapper.
Definition Initiator.cpp:41
void transferGrain(std::uint64_t grainIndex, std::uint16_t startSlice, std::uint16_t endSlice)
Transfer a grain to all targets.
Definition Initiator.cpp:84
void removeTarget(TargetInfo const &targetInfo)
Remove a target from the initiator.
Definition Initiator.cpp:74
mxlFabricsInitiator toAPI() noexcept
Convert this InitiatorWrapper to its API representation.
Definition Initiator.cpp:46
void transferGrainToTarget(Endpoint::Id targetId, std::uint64_t localIndex, std::uint64_t remoteIndex, std::uint64_t payloadOffset, std::uint16_t startSlice, std::uint16_t endSlice)
Transfer a grain to a specific target.
Definition Initiator.cpp:94
Initiator::MakeProgressResult makeProgress()
Attempts to progress execution, including connection management and data operations.
void destroyInner() noexcept
Shut down and destroy the underlying initiator. Errors are logged, because this runs in the destructo...
Definition Initiator.cpp:22
std::unique_ptr< Initiator > _inner
void transferSamples(std::uint64_t headIndex, std::size_t count)
Transfer samples to all targets.
std::variant< Ready, NotReady, Interrupted > MakeProgressResult
Definition Initiator.hpp:42
static std::unique_ptr< RCInitiator > setup(mxlFabricsInitiatorConfig const &config, FabricInfoView info, InitiatorSetupOptions const &options={})
Set up a fresh initiator without any targets assigned to it.
static std::unique_ptr< RDMInitiator > setup(mxlFabricsInitiatorConfig const &config, FabricInfoView info, InitiatorSetupOptions const &options={})
Set up a new RDMInitiator.
struct mxlFabricsInitiator_t * mxlFabricsInitiator
Definition fabrics.h:44
struct mxlFabricsInitiatorConfig_t mxlFabricsInitiatorConfig
std::pair< FabricInfo, ProviderConfig > selectSourceInterface(::mxlFabricsInterfaceConfig const &interfaceConfig, bool isTarget)
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.
mxlFabricsInterfaceConfig interface
Definition fabrics.h:139
Provider-independent tuning options for initiator setup.
Definition Initiator.hpp:19
TargetInfo contains all the information required by an initiator to operate transfers to the given ta...