From cf7e9496e92e496840c5cd235f4cd52a6789a11d Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Thu, 25 Jun 2026 12:33:32 +0200 Subject: Generalize device class --- include/drm++/drm.hpp | 20 ++++++++++++++++---- include/drm++/helper/ioctl.hpp | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/drm++/drm.hpp b/include/drm++/drm.hpp index 2833adf..4e94010 100644 --- a/include/drm++/drm.hpp +++ b/include/drm++/drm.hpp @@ -133,6 +133,8 @@ #include "helper/macros.hpp" #include "helper/types.hpp" +#include + namespace drm { /// @@ -146,6 +148,11 @@ public: /// @throws std::invalid_argument if fd is invalid Device(int fd); + /// Set the client name for this file descriptor, useful for debugging and tracking. + void setClientName(const std::string& name) const; + + /* Authentication */ + /// Attempt to acquire DRM master on the device. This will fail if another process is /// already DRM master. void acquireMaster() const; @@ -153,16 +160,23 @@ public: /// Release DRM master on the device. void releaseMaster() const; + /// Fetch the magic token. + [[nodiscard]] u32 magic() const; + /// Authenticate a file descriptor via magic token, allowing for access to /// restricted ioctls (such as mode setting). void authenticate(u32 magic) const; + /* Device information */ + + /// Get the unique string for this device. This operation is restricted to the DRM master. + [[nodiscard]] std::string unique() const; + // Private access GETTER(fd) - GETTER(magic) // Move constructor/operator - Device(Device&& other) noexcept : m_fd(other.m_fd), m_magic(other.m_magic) { + Device(Device&& other) noexcept : m_fd(other.m_fd) { other.m_fd = -1; // invalidate other } @@ -170,7 +184,6 @@ public: if (this != &other) { this->destruct(); this->m_fd = other.m_fd; - this->m_magic = other.m_magic; other.m_fd = -1; // invalidate other } @@ -187,7 +200,6 @@ public: private: int m_fd; // indicates device validity (>= 0) - u32 m_magic; void destruct() noexcept; }; diff --git a/include/drm++/helper/ioctl.hpp b/include/drm++/helper/ioctl.hpp index fe87f3c..bd6c44a 100644 --- a/include/drm++/helper/ioctl.hpp +++ b/include/drm++/helper/ioctl.hpp @@ -15,6 +15,7 @@ namespace drm::ioctl { /// Type of ioctl() error. enum class Error : u8 { BadFileDescriptor, + NoAccess, InvalidArgument, NotSupported, Other //!< Check errno field -- cgit v1.3.1