MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
mxl::lib::fabrics::ofi::TargetWrapper Class Reference

A wrapper around Target implementations. More...

#include <Target.hpp>

Public Member Functions

std::optional< Target::ReadResult > read ()
std::optional< Target::ReadResult > readBlocking (std::chrono::steady_clock::duration timeout)
std::unique_ptr< TargetInfo > setup (mxlFabricsTargetConfig const &config, TargetSetupOptions const &options={})
 Set up the target with the specified configuration.
mxlFabricsTarget toAPI () noexcept
 Convert this TargetWrapper to its API representation.
 ~TargetWrapper ()
 Shut down the underlying target before it is destroyed.

Static Public Member Functions

static TargetWrapper * fromAPI (mxlFabricsTarget api) noexcept
 Convert an mxlFabricsTarget API object to its underlying TargetWrapper.

Private Member Functions

void destroyInner () noexcept
 Shut down and destroy the underlying target. Errors are logged, because this runs in the destructor.
template<typename TargetT>
std::unique_ptr< TargetInfo > setup (mxlFabricsTargetConfig const &config, FabricInfoView info, TargetSetupOptions const &options={})
 Set up the correct concrete target type internally and returns the target info.

Private Attributes

std::unique_ptr< Target > _inner

Detailed Description

A wrapper around Target implementations.

This wrapper creates an unspecified target that can be configured for a specific type by calling the setup() method.

Definition at line 98 of file Target.hpp.

Constructor & Destructor Documentation

◆ ~TargetWrapper()

mxl::lib::fabrics::ofi::TargetWrapper::~TargetWrapper ( )

Shut down the underlying target before it is destroyed.

Definition at line 31 of file Target.cpp.

32 {
34 }
void destroyInner() noexcept
Shut down and destroy the underlying target. Errors are logged, because this runs in the destructor.
Definition Target.cpp:36

Member Function Documentation

◆ destroyInner()

void mxl::lib::fabrics::ofi::TargetWrapper::destroyInner ( )
privatenoexcept

Shut down and destroy the underlying target. Errors are logged, because this runs in the destructor.

Definition at line 36 of file Target.cpp.

37 {
38 if (!_inner)
39 {
40 return;
41 }
42
43 try
44 {
45 _inner->shutdown();
46 }
47 catch (std::exception const& e)
48 {
49 MXL_ERROR("Failed to shut down the target: {}", e.what());
50 }
51
52 _inner.reset();
53 }
#define MXL_ERROR(...)
Definition Logging.hpp:67
std::unique_ptr< Target > _inner
Definition Target.hpp:152

◆ fromAPI()

TargetWrapper * mxl::lib::fabrics::ofi::TargetWrapper::fromAPI ( mxlFabricsTarget api)
staticnodiscardnoexcept

Convert an mxlFabricsTarget API object to its underlying TargetWrapper.

Parameters
apiThe mxlFabricsTarget to convert.
Returns
The TargetWrapper underlying the given mxlFabricsTarget.

Definition at line 55 of file Target.cpp.

56 {
57 return reinterpret_cast<TargetWrapper*>(api);
58 }

◆ read()

std::optional< Target::ReadResult > mxl::lib::fabrics::ofi::TargetWrapper::read ( )

Definition at line 65 of file Target.cpp.

66 {
67 if (!_inner)
68 {
69 throw Exception::invalidState("Target is not set up.");
70 }
71
72 return _inner->read();
73 }
static Exception invalidState(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_STATE exception.
Definition Exception.hpp:59

◆ readBlocking()

std::optional< Target::ReadResult > mxl::lib::fabrics::ofi::TargetWrapper::readBlocking ( std::chrono::steady_clock::duration timeout)

Definition at line 75 of file Target.cpp.

76 {
77 if (!_inner)
78 {
79 throw Exception::invalidState("Target is not set up.");
80 }
81
82 return _inner->readBlocking(timeout);
83 }

◆ setup() [1/2]

template<typename TargetT>
std::unique_ptr< TargetInfo > mxl::lib::fabrics::ofi::TargetWrapper::setup ( mxlFabricsTargetConfig const & config,
FabricInfoView info,
TargetSetupOptions const & options = {} )
nodiscardprivate

Set up the correct concrete target type internally and returns the target info.

Parameters
configTarget configuration passed by the user.
infoFabric info already resolved from the interface config.

Definition at line 86 of file Target.cpp.

87 {
88 auto [inner, targetInfo] = TargetT::setup(config, info, options);
89 _inner = std::move(inner);
90 return std::move(targetInfo);
91 }

◆ setup() [2/2]

std::unique_ptr< TargetInfo > mxl::lib::fabrics::ofi::TargetWrapper::setup ( mxlFabricsTargetConfig const & config,
TargetSetupOptions const & options = {} )
nodiscard

Set up the target with the specified configuration.

This method initializes the underlying target implementation based on the provided configuration.

Parameters
configThe configuration to use for setting up the target.
optionsOptional tuning parameters (e.g. completion queue depth).

Definition at line 93 of file Target.cpp.

94 {
96
97 auto [info, providerConfig] = selectSourceInterface(config.interface, /* target */ true);
98 switch (info->ep_attr->type)
99 {
100 case FI_EP_MSG: return setup<RCTarget>(config, info.view(), options);
101 case FI_EP_RDM: return setup<RDMTarget>(config, info.view(), options);
102 default: throw Exception::invalidState("unsupported endpoint type");
103 }
104 }
std::unique_ptr< TargetInfo > setup(mxlFabricsTargetConfig const &config, TargetSetupOptions const &options={})
Set up the target with the specified configuration.
Definition Target.cpp:93
std::pair< FabricInfo, ProviderConfig > selectSourceInterface(::mxlFabricsInterfaceConfig const &interfaceConfig, bool isTarget)

◆ toAPI()

mxlFabricsTarget mxl::lib::fabrics::ofi::TargetWrapper::toAPI ( )
nodiscardnoexcept

Convert this TargetWrapper to its API representation.

Returns
The mxlFabricsTarget representing this TargetWrapper.

Definition at line 60 of file Target.cpp.

61 {
62 return reinterpret_cast<mxlFabricsTarget>(this);
63 }
struct mxlFabricsTarget_t * mxlFabricsTarget
Definition fabrics.h:34

Member Data Documentation

◆ _inner

std::unique_ptr<Target> mxl::lib::fabrics::ofi::TargetWrapper::_inner
private

The underlying target implementation.

Definition at line 152 of file Target.hpp.


The documentation for this class was generated from the following files: