MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
Event.hpp
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#pragma once
6
7#include <cstdint>
8#include <memory>
9#include <vector>
10#include <rdma/fi_eq.h>
11#include "FabricInfo.hpp"
12#include "variant"
13
15{
16 class EventQueue;
17
20 class Event
21 {
22 public:
26 {
27 public:
29
32 [[nodiscard]]
33 ::fid_t fid() const noexcept;
34
37 [[nodiscard]]
38 FabricInfoView info() const noexcept;
39
40 private:
41 ::fid_t _fid;
43 };
44
47 class Connected final
48 {
49 public:
50 Connected(::fid_t fid);
51
54 [[nodiscard]]
55 ::fid_t fid() const noexcept;
56
57 private:
58 ::fid_t _fid;
59 };
60
63 class Shutdown final
64 {
65 public:
66 Shutdown(::fid_t fid);
67
70 [[nodiscard]]
71 ::fid_t fid() const noexcept;
72
73 private:
74 ::fid_t _fid;
75 };
76
79 class Error final
80 {
81 public:
82 Error(std::shared_ptr<EventQueue> eq, ::fid_t fid, int err, int providerErr, std::vector<std::uint8_t> errData);
83
86 [[nodiscard]]
87 int code() const noexcept;
88
91 [[nodiscard]]
92 int providerCode() const noexcept;
93
96 [[nodiscard]]
97 ::fid_t fid() const noexcept;
98
101 [[nodiscard]]
102 std::string toString() const;
103
104 private:
105 std::shared_ptr<EventQueue> _eq;
106 ::fid_t _fid;
107 int _err;
109 std::vector<std::uint8_t> _errData;
110 };
111
112 using Inner = std::variant<ConnectionRequested, Connected, Shutdown, Error>;
113
114 public:
115 static Event fromRawEntry(::fi_eq_entry const& raw, std::uint32_t eventType);
116
119 static Event fromRawCMEntry(::fi_eq_cm_entry const& raw, std::uint32_t eventType);
120
123 static Event fromError(std::shared_ptr<EventQueue> queue, ::fi_eq_err_entry const* raw);
124
127 [[nodiscard]]
128 bool isConnReq() const noexcept;
129
133 [[nodiscard]]
134 ConnectionRequested const& connReq() const;
135
138 [[nodiscard]]
139 bool isConnected() const noexcept;
140
144 [[nodiscard]]
145 Connected const& connected() const;
146
149 [[nodiscard]]
150 bool isShutdown() const noexcept;
151
155 [[nodiscard]]
156 Shutdown const& shutdown() const;
157
160 [[nodiscard]]
161 bool isError() const noexcept;
162
166 [[nodiscard]]
167 Error const& error() const;
168
171 [[nodiscard]]
172 fid_t fid() noexcept;
173
174 private:
175 Event(Inner);
176
177 private:
179 };
180}
RAII Wrapper around a libfabric event queue (fi_eq).
A type that wraps a "FI_CONNECTED" event type.
Definition Event.hpp:48
::fid_t fid() const noexcept
fabric descriptor associated with the event
Definition Event.cpp:34
A type that wraps a "FI_CONNREQ" event type.
Definition Event.hpp:26
FabricInfoView info() const noexcept
libfabric info struct of the endpoint that requested connection
Definition Event.cpp:25
::fid_t fid() const noexcept
fabric descriptor associated with the event
Definition Event.cpp:20
ConnectionRequested(::fid_t fid, FabricInfo info)
Definition Event.cpp:15
A type that wraps an error received from the event queue.
Definition Event.hpp:80
int providerCode() const noexcept
return the provider-specific error code.
Definition Event.cpp:61
Error(std::shared_ptr< EventQueue > eq, ::fid_t fid, int err, int providerErr, std::vector< std::uint8_t > errData)
Definition Event.cpp:48
::fid_t fid() const noexcept
fabric descriptor associated with the event
Definition Event.cpp:66
int code() const noexcept
return the libfabric error code.
Definition Event.cpp:56
std::shared_ptr< EventQueue > _eq
Definition Event.hpp:105
std::string toString() const
Convert the error to a human-readable string.
Definition Event.cpp:71
std::vector< std::uint8_t > _errData
Definition Event.hpp:109
A type that wraps a "FI_SHUTDOWN" event type.
Definition Event.hpp:64
::fid_t fid() const noexcept
fabric descriptor associated with the event
Definition Event.cpp:43
fid_t fid() noexcept
fabric descriptor associated with the event
Definition Event.cpp:159
bool isConnected() const noexcept
Returns true if this event is a FI_CONNECTED.
Definition Event.cpp:129
std::variant< ConnectionRequested, Connected, Shutdown, Error > Inner
Definition Event.hpp:112
Connected const & connected() const
Get a connected representation of the event. Throws if the event is not a connected event....
Definition Event.cpp:134
bool isError() const noexcept
Returns true if this event is an error entry.
Definition Event.cpp:149
static Event fromRawCMEntry(::fi_eq_cm_entry const &raw, std::uint32_t eventType)
create an Event from a libfabric Connection Management event
Definition Event.cpp:91
static Event fromRawEntry(::fi_eq_entry const &raw, std::uint32_t eventType)
Definition Event.cpp:86
bool isShutdown() const noexcept
returns true if this event is a FI_SHUTDOWN
Definition Event.cpp:139
Error const & error() const
Get an error representation of the event. Throws if the event is an error. Users should previously ch...
Definition Event.cpp:154
static Event fromError(std::shared_ptr< EventQueue > queue, ::fi_eq_err_entry const *raw)
create an Event from a libfabric event error entry
Definition Event.cpp:104
ConnectionRequested const & connReq() const
Get a connection request representation of the event. Throws if the event is not a connection request...
Definition Event.cpp:124
Shutdown const & shutdown() const
Get a shutdown representation of the event. Throws if the event is not a shutdown event....
Definition Event.cpp:144
bool isConnReq() const noexcept
returns true if this event is a FI_CONNREQ
Definition Event.cpp:119
Non-owning view of a FabricInfo. Returned when iterating over a FabricInfoList.
FabricInfo(FabricInfoView) noexcept
Create an owning FabricInfo object from a non-owning view.
::fi_info * raw() noexcept
Returns the raw fi_info object managed by this FabricInfo instance.