From 771459c68c26970784f3beea5398d3e21bb8286a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 25 Nov 2025 10:41:06 -0500 Subject: feat! DDK: A new C++ friendly contract header file. Signed-off-by: Amlal El Mahrouss --- src/libDDK/DriverKit/c++/contract.h | 48 +++++++++++++++++++++++++++++++++++++ src/libDDK/DriverKit/dki/contract.h | 34 -------------------------- 2 files changed, 48 insertions(+), 34 deletions(-) create mode 100644 src/libDDK/DriverKit/c++/contract.h delete mode 100644 src/libDDK/DriverKit/dki/contract.h (limited to 'src') 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 +#include + +#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 +concept IsValidDriver = requires(T a) { + { a.IsActive() && a.Type() > 0 }; +}; + +/// @note This helper is consteval only. +template +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 -#include - -#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 -- cgit v1.2.3