From ab752cafbde3755e7a09b3ecae021a6727cb7112 Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Thu, 25 Jun 2026 11:19:54 +0200 Subject: Project hierarchy overhaul --- include/drm++/drm.hpp | 3 +- include/drm++/gem.hpp | 3 +- include/drm++/helper.hpp | 41 ---------------------- include/drm++/helper/ioctl.hpp | 78 +++++++++++++++++++++++++++++++++++++++++ include/drm++/helper/macros.hpp | 21 +++++++++++ include/drm++/helper/types.hpp | 22 ++++++++++++ include/drm++/ioctl.hpp | 77 ---------------------------------------- include/drm++/syncobject.hpp | 3 +- 8 files changed, 127 insertions(+), 121 deletions(-) delete mode 100644 include/drm++/helper.hpp create mode 100644 include/drm++/helper/ioctl.hpp create mode 100644 include/drm++/helper/macros.hpp create mode 100644 include/drm++/helper/types.hpp delete mode 100644 include/drm++/ioctl.hpp (limited to 'include') diff --git a/include/drm++/drm.hpp b/include/drm++/drm.hpp index c75495b..2833adf 100644 --- a/include/drm++/drm.hpp +++ b/include/drm++/drm.hpp @@ -130,7 +130,8 @@ /// This library requires a C++ compiler capable of C++20 or newer. /// -#include "drm++/helper.hpp" +#include "helper/macros.hpp" +#include "helper/types.hpp" namespace drm { diff --git a/include/drm++/gem.hpp b/include/drm++/gem.hpp index 35829ee..e3e3306 100644 --- a/include/drm++/gem.hpp +++ b/include/drm++/gem.hpp @@ -68,7 +68,8 @@ /// This table is not exhaustive, but it is not recommended to use any other values for bpp. /// -#include "drm++/helper.hpp" +#include "helper/macros.hpp" +#include "helper/types.hpp" #include diff --git a/include/drm++/helper.hpp b/include/drm++/helper.hpp deleted file mode 100644 index 7b927bf..0000000 --- a/include/drm++/helper.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/* SPDX-License-Identifier: MIT */ - -#pragma once - -#include -#include - -namespace drm { - -using u8 = uint8_t; -using u16 = uint16_t; -using u32 = uint32_t; -using u64 = uint64_t; -using s8 = int8_t; -using s16 = int16_t; -using s32 = int32_t; -using s64 = int64_t; - -template -using ref = std::reference_wrapper; - -} - -/* Helpful macros */ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-macros" - -#define GETTER(name) [[nodiscard]] auto name() const { return m_##name; } -#define DEFAULT_OPERATORS(classname) \ - classname(const classname&) = default; \ - classname& operator=(const classname&) = default; \ - classname(classname&&) = default; \ - classname& operator=(classname&&) = default; -#define NO_COPY(classname) \ - classname(const classname&) = delete; \ - classname& operator=(const classname&) = delete; -#define NO_MOVE(classname) \ - classname(classname&&) = delete; \ - classname& operator=(classname&&) = delete; - -#pragma clang diagnostic pop diff --git a/include/drm++/helper/ioctl.hpp b/include/drm++/helper/ioctl.hpp new file mode 100644 index 0000000..fe87f3c --- /dev/null +++ b/include/drm++/helper/ioctl.hpp @@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: MIT */ + +#pragma once + +#include "macros.hpp" +#include "types.hpp" + +#include +#include + +#include + +namespace drm::ioctl { + +/// Type of ioctl() error. +enum class Error : u8 { + BadFileDescriptor, + InvalidArgument, + NotSupported, + Other //!< Check errno field +}; + +/// Exception class wrapping around ioctl(). +class Exception : public std::exception { +public: + /// Construct an exception from errno. + explicit Exception(int fd, unsigned long op); + + /// Get the error message. + [[nodiscard]] const char* what() const noexcept override { + return this->m_what.c_str(); + } + + // Private access + GETTER(fd) + GETTER(op) + GETTER(code) + GETTER(syserrno) + + // Default operators and destructor + DEFAULT_OPERATORS(Exception) + ~Exception() override; +private: + int m_fd; + unsigned long m_op; + Error m_code; + int m_syserrno; + std::string m_what; +}; + +/// Perform an ioctl() call. +/// @throws drm::ioctl::Exception on failure +inline void perform(int fd, unsigned long op) { + if (::ioctl(fd, op, nullptr) < 0) + throw Exception(fd, op); +} + +/// Perform an ioctl() call. +/// @throws drm::ioctl::Exception on failure +template +inline T perform(int fd, unsigned long op) { + T data{}; + + if (::ioctl(fd, op, &data) < 0) + throw Exception(fd, op); + + return data; +} + +/// Perform an ioctl() call. +/// @throws drm::ioctl::Exception on failure +template +inline void perform(int fd, unsigned long op, T& data) { + if (::ioctl(fd, op, &data) < 0) + throw Exception(fd, op); +} + +} diff --git a/include/drm++/helper/macros.hpp b/include/drm++/helper/macros.hpp new file mode 100644 index 0000000..3187177 --- /dev/null +++ b/include/drm++/helper/macros.hpp @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: MIT */ + +#pragma once + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-macros" + +#define GETTER(name) [[nodiscard]] auto name() const { return m_##name; } +#define DEFAULT_OPERATORS(classname) \ + classname(const classname&) = default; \ + classname& operator=(const classname&) = default; \ + classname(classname&&) = default; \ + classname& operator=(classname&&) = default; +#define NO_COPY(classname) \ + classname(const classname&) = delete; \ + classname& operator=(const classname&) = delete; +#define NO_MOVE(classname) \ + classname(classname&&) = delete; \ + classname& operator=(classname&&) = delete; + +#pragma clang diagnostic pop diff --git a/include/drm++/helper/types.hpp b/include/drm++/helper/types.hpp new file mode 100644 index 0000000..0669700 --- /dev/null +++ b/include/drm++/helper/types.hpp @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: MIT */ + +#pragma once + +#include +#include + +namespace drm { + +using u8 = uint8_t; +using u16 = uint16_t; +using u32 = uint32_t; +using u64 = uint64_t; +using s8 = int8_t; +using s16 = int16_t; +using s32 = int32_t; +using s64 = int64_t; + +template +using ref = std::reference_wrapper; + +} diff --git a/include/drm++/ioctl.hpp b/include/drm++/ioctl.hpp deleted file mode 100644 index 49f8a1c..0000000 --- a/include/drm++/ioctl.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/* SPDX-License-Identifier: MIT */ - -#pragma once - -#include "drm++/helper.hpp" - -#include -#include - -#include - -namespace drm::ioctl { - -/// Type of ioctl() error. -enum class Error : u8 { - BadFileDescriptor, - InvalidArgument, - NotSupported, - Other //!< Check errno field -}; - -/// Exception class wrapping around ioctl(). -class Exception : public std::exception { -public: - /// Construct an exception from errno. - explicit Exception(int fd, unsigned long op); - - /// Get the error message. - [[nodiscard]] const char* what() const noexcept override { - return this->m_what.c_str(); - } - - // Private access - GETTER(fd) - GETTER(op) - GETTER(code) - GETTER(syserrno) - - // Default operators and destructor - DEFAULT_OPERATORS(Exception) - ~Exception() override; -private: - int m_fd; - unsigned long m_op; - Error m_code; - int m_syserrno; - std::string m_what; -}; - -/// Perform an ioctl() call. -/// @throws drm::ioctl::Exception on failure -inline void perform(int fd, unsigned long op) { - if (::ioctl(fd, op, nullptr) < 0) - throw Exception(fd, op); -} - -/// Perform an ioctl() call. -/// @throws drm::ioctl::Exception on failure -template -inline T perform(int fd, unsigned long op) { - T data{}; - - if (::ioctl(fd, op, &data) < 0) - throw Exception(fd, op); - - return data; -} - -/// Perform an ioctl() call. -/// @throws drm::ioctl::Exception on failure -template -inline void perform(int fd, unsigned long op, T& data) { - if (::ioctl(fd, op, &data) < 0) - throw Exception(fd, op); -} - -} diff --git a/include/drm++/syncobject.hpp b/include/drm++/syncobject.hpp index beee332..b5a032d 100644 --- a/include/drm++/syncobject.hpp +++ b/include/drm++/syncobject.hpp @@ -37,7 +37,8 @@ /// this by providing separate classes for each type of sync object. /// -#include "drm++/helper.hpp" +#include "helper/macros.hpp" +#include "helper/types.hpp" #include #include -- cgit v1.3.1