diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-25 10:41:06 -0500 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-25 10:42:34 -0500 |
| commit | 771459c68c26970784f3beea5398d3e21bb8286a (patch) | |
| tree | 83697f985f49b0307999e018ba70186ee177ef94 | |
| parent | cdfc807e90c713a3c7e6698c8b255b4523b8d311 (diff) | |
feat! DDK: A new C++ friendly contract header file.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | src/libDDK/DriverKit/c++/contract.h | 48 | ||||
| -rw-r--r-- | src/libDDK/DriverKit/dki/contract.h | 34 |
2 files changed, 48 insertions, 34 deletions
diff --git a/src/libDDK/DriverKit/c++/contract.h b/src/libDDK/DriverKit/c++/contract.h new file mode 100644 index 00000000..e341f1a0 --- /dev/null +++ b/src/libDDK/DriverKit/c++/contract.h @@ -0,0 +1,48 @@ +/* ======================================== + + Copyright Amlal El Mahrouss 2025, licensed under the Apache 2.0 license. + + FILE: ddk.h + PURPOSE: Driver Kernel Interface Model base header. + + ======================================== */ + +#pragma once + +#include <CompilerKit/CompilerKit.h> +#include <libDDK/DriverKit/macros.h> + +#define DKI_DRIVER_IMPL \ + final: \ + public \ + ::Kernel::DDK::IDriverBase + +/// @author Amlal El Mahrouss + +namespace Kernel::DDK { +class IDriverBase { + public: + explicit IDriverBase() = default; + virtual ~IDriverBase() = default; + + NE_COPY_DEFAULT(IDriverBase); + + using PtrType = VoidPtr; + + virtual BOOL IsCastable() { return NO; } + virtual constexpr BOOL IsActive() { return NO; } + virtual PtrType Leak() { return nullptr; } + virtual constexpr Int32 Type() { return 0; } +}; + +/// @brief This concept requires the Driver to be IDriverBase compliant. +template <typename T> +concept IsValidDriver = requires(T a) { + { a.IsActive() && a.Type() > 0 }; +}; + +/// @note This helper is consteval only. +template<IsValidDriver T> +inline consteval void ce_ddk_is_valid(T) {} + +} // namespace Kernel::DDK diff --git a/src/libDDK/DriverKit/dki/contract.h b/src/libDDK/DriverKit/dki/contract.h deleted file mode 100644 index 7361d792..00000000 --- a/src/libDDK/DriverKit/dki/contract.h +++ /dev/null @@ -1,34 +0,0 @@ -/* ======================================== - - Copyright Amlal El Mahrouss 2025, licensed under the Apache 2.0 license. - - FILE: ddk.h - PURPOSE: Driver Kernel Interface Model base header. - - ======================================== */ - -#pragma once - -#include <CompilerKit/CompilerKit.h> -#include <libDDK/DriverKit/macros.h> - -#define DKI_CONTRACT_IMPL final : public ::Kernel::DKI::DKIContract - -/// @author Amlal El Mahrouss - -namespace Kernel::DKI { -class DKIContract { - public: - explicit DKIContract() = default; - virtual ~DKIContract() = default; - - NE_COPY_DEFAULT(DKIContract); - - using PtrType = VoidPtr; - - virtual BOOL IsCastable() { return NO; } - virtual BOOL IsActive() { return NO; } - virtual VoidPtr Leak() { return nullptr; } - virtual Int32 Type() { return 0; } -}; -} // namespace Kernel::DKI |
