vrtd::Session
-
class Session
Owning session/connection to the V Runtime Daemon (vrtd).
A
Sessionwraps a connected libvrtd socket and provides typed, exception-based access to devices and BARs. All public member functions are thread-safe; calls synchronize on an internalstd::mutex.- Exceptions
Most member functions throw vrtd::Error on failure. The destructor never throws.
- Lifetime and moves
The session is non-copyable and movable.
Moving a session leaves the moved-from object in the closed state (i.e.,
isClosed()==trueandoperatorbool() == false).Important: Any
DeviceorBarpreviously obtained from a session becomes invalid once that session is closed or moved; subsequent operations on those objects will throw.
Public Functions
-
explicit Session(const char *socket_path = VRTD_STANDARD_PATH)
Construct and connect to the vrtd socket.
- Parameters:
socket_path – Filesystem path to the vrtd UNIX socket. Defaults to the standard path.
- Throws:
vrtd::Error – if the connection cannot be established.
-
~Session() noexcept
Destructor; closes the session if still open.
-
Session(Session &&other) noexcept
Move-construct a session.
The moved-from session becomes closed.
- Parameters:
other – The session to move from.
-
Session &operator=(Session &&other) noexcept
Move-assign a session.
Closes any existing connection, then takes ownership from
other. The moved-from session becomes closed.- Parameters:
other – The session to move from.
-
uint32_t getNumDevices() const
Number of devices visible via vrtd.
- Thread safety
Safe for concurrent calls across threads.
- Throws:
vrtd::Error – on error.
- Returns:
Device count.
-
Device getDevice(size_t i) const
Retrieve a device handle by index.
- Notes
The returned
Devicebecomes invalid if this session is later closed or moved.
- Parameters:
i – Zero-based device index; must be less than
getNumDevices().- Throws:
vrtd::Error – if
iis out of range or if the session is not usable.- Returns:
A lightweight
Devicevalue referring back to this session.
-
Device getDeviceByBdf(std::string_view bdf) const
Retrieve a device handle by PCI BDF string.
- Parameters:
bdf – PCI BDF string (e.g., “0000:65:00.0”).
- Throws:
vrtd::Error – if the device cannot be found or if the session is not usable.
- Returns:
A lightweight
Devicevalue referring back to this session.
-
struct slash_qdma_info getQdmaInfo(const Device &device) const
Query QDMA capabilities for a device.
- Parameters:
device – Device for which to query QDMA info.
- Throws:
vrtd::Error – on error.
- Returns:
A copy of the QDMA capability struct as reported by the daemon.
-
void close() noexcept
Explicitly close the session.
Idempotent. After closing,
isClosed()==trueand further operations on this session or on previously obtainedDevice/ objectswill throw.
-
bool isClosed() const noexcept
Whether the session is closed.
-
explicit operator bool() const noexcept
Truthiness conversion.
- Returns:
trueif the session is open (not closed).