vrtd::Session

class Session

Owning session/connection to the V Runtime Daemon (vrtd).

A Session wraps 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 internal std::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()==true and operator bool() == false).

  • Important: Any Device or Bar previously 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 Device becomes invalid if this session is later closed or moved.

Parameters:

i – Zero-based device index; must be less than getNumDevices().

Throws:

vrtd::Error – if i is out of range or if the session is not usable.

Returns:

A lightweight Device value 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 Device value referring back to this session.

struct slash_qdma_info getQdmaInfo(const Device &device) const

Query QDMA capabilities for a device.

Parameters:

deviceDevice 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()==true and further operations on this session or on previously obtained Device/ objects will throw.

bool isClosed() const noexcept

Whether the session is closed.

explicit operator bool() const noexcept

Truthiness conversion.

Returns:

true if the session is open (not closed).