From 0e92d4841f0d1b6a5f2e1b093d9d0b6864dfac93 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 30 May 2025 10:56:29 +0200 Subject: refactor: Refactor IDeviceObject to DeviceInterface and its usages. refactor: Cleanup UPS (UserProcessScheduler) implementation. Signed-off-by: Amlal El Mahrouss --- dev/kernel/GfxKit/FB.h | 6 +++--- dev/kernel/HALKit/AMD64/HalDebugOutput.cc | 8 ++++---- dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 4 ++-- dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc | 4 ++-- dev/kernel/HALKit/ARM64/HalDebugOutput.cc | 4 ++-- dev/kernel/KernelKit/DebugOutput.h | 12 ++++++------ dev/kernel/KernelKit/DeviceMgr.h | 24 ++++++++++++------------ dev/kernel/NetworkKit/NetworkDevice.h | 4 ++-- dev/kernel/NetworkKit/NetworkDevice.inl | 6 +++--- dev/kernel/StorageKit/AHCI.h | 6 +++--- dev/kernel/StorageKit/ATA.h | 6 +++--- dev/kernel/StorageKit/NVME.h | 4 ++-- dev/kernel/StorageKit/StorageKit.h | 2 +- dev/kernel/src/Gfx/FBDeviceInterface.cc | 6 +++--- dev/kernel/src/Storage/AHCIDeviceInterface.cc | 10 +++++----- dev/kernel/src/Storage/ATADeviceInterface.cc | 10 +++++----- dev/kernel/src/Storage/NVMEDeviceInterface.cc | 6 +++--- dev/kernel/src/UserProcessScheduler.cc | 4 ---- 18 files changed, 61 insertions(+), 65 deletions(-) (limited to 'dev/kernel') diff --git a/dev/kernel/GfxKit/FB.h b/dev/kernel/GfxKit/FB.h index e30f1800..14f0393c 100644 --- a/dev/kernel/GfxKit/FB.h +++ b/dev/kernel/GfxKit/FB.h @@ -32,11 +32,11 @@ struct PACKED FBDevicePacket final { /// @brief Framebuffer device interface. /// @details This class is used to send and receive data from the framebuffer device. -/// @note The class is derived from the IDeviceObject class. +/// @note The class is derived from the DeviceInterface class. class FBDeviceInterface NE_DEVICE { public: - explicit FBDeviceInterface(void (*out)(IDeviceObject* self, FBDevicePacket* out), - void (*in)(IDeviceObject* self, FBDevicePacket* in)); + explicit FBDeviceInterface(void (*out)(DeviceInterface* self, FBDevicePacket* out), + void (*in)(DeviceInterface* self, FBDevicePacket* in)); virtual ~FBDeviceInterface() override; diff --git a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc index b0463eb5..1e9fbab3 100644 --- a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc +++ b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc @@ -59,7 +59,7 @@ TerminalDevice::~TerminalDevice() = default; STATIC SizeT kX = kFontSizeX, kY = kFontSizeY; -EXTERN_C void ke_utf_io_write(IDeviceObject* obj, const Utf8Char* bytes) { +EXTERN_C void ke_utf_io_write(DeviceInterface* obj, const Utf8Char* bytes) { NE_UNUSED(bytes); NE_UNUSED(obj); @@ -115,7 +115,7 @@ EXTERN_C void ke_utf_io_write(IDeviceObject* obj, const Utf8Cha #endif // __DEBUG__ } -EXTERN_C void ke_io_write(IDeviceObject* obj, const Char* bytes) { +EXTERN_C void ke_io_write(DeviceInterface* obj, const Char* bytes) { NE_UNUSED(bytes); NE_UNUSED(obj); @@ -171,7 +171,7 @@ EXTERN_C void ke_io_write(IDeviceObject* obj, const Char* bytes) { #endif // __DEBUG__ } -EXTERN_C void ke_io_read(IDeviceObject*, const Char* bytes) { +EXTERN_C void ke_io_read(DeviceInterface*, const Char* bytes) { NE_UNUSED(bytes); #ifdef __DEBUG__ @@ -218,7 +218,7 @@ Utf8TerminalDevice::~Utf8TerminalDevice() = default; Utf8TerminalDevice Utf8TerminalDevice::The() noexcept { Utf8TerminalDevice out(Kernel::ke_utf_io_write, - [](IDeviceObject*, const Utf8Char*) -> Void {}); + [](DeviceInterface*, const Utf8Char*) -> Void {}); return out; } diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index b30bfc32..a9bdc89b 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -546,7 +546,7 @@ namespace Detail { /// @brief Read AHCI device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_read_ahci(IDeviceObject* self, MountpointInterface* mnt) { + STATIC Void sk_io_read_ahci(DeviceInterface* self, MountpointInterface* mnt) { AHCIDeviceInterface* dev = (AHCIDeviceInterface*) self; err_global_get() = kErrorDisk; @@ -567,7 +567,7 @@ namespace Detail { /// @brief Write AHCI device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_write_ahci(IDeviceObject* self, + STATIC Void sk_io_write_ahci(DeviceInterface* self, MountpointInterface* mnt) { AHCIDeviceInterface* dev = (AHCIDeviceInterface*) self; diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc index 99e1c619..7b121c64 100644 --- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc @@ -200,7 +200,7 @@ namespace Detail { /// @brief Read PIO device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_read_pio(IDeviceObject* self, MountpointInterface* mnt) { + STATIC Void sk_io_read_pio(DeviceInterface* self, MountpointInterface* mnt) { ATADeviceInterface* dev = (ATADeviceInterface*) self; err_global_get() = kErrorDisk; @@ -221,7 +221,7 @@ namespace Detail { /// @brief Write PIO device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_write_pio(IDeviceObject* self, MountpointInterface* mnt) { + STATIC Void sk_io_write_pio(DeviceInterface* self, MountpointInterface* mnt) { ATADeviceInterface* dev = (ATADeviceInterface*) self; err_global_get() = kErrorDisk; diff --git a/dev/kernel/HALKit/ARM64/HalDebugOutput.cc b/dev/kernel/HALKit/ARM64/HalDebugOutput.cc index 3c518e2f..64004ac3 100644 --- a/dev/kernel/HALKit/ARM64/HalDebugOutput.cc +++ b/dev/kernel/HALKit/ARM64/HalDebugOutput.cc @@ -10,7 +10,7 @@ #include namespace Kernel { -EXTERN_C void ke_io_write(IDeviceObject* self, const Char* bytes) { +EXTERN_C void ke_io_write(DeviceInterface* self, const Char* bytes) { #ifdef __DEBUG__ if (*bytes == 0) return; @@ -33,7 +33,7 @@ EXTERN_C void ke_io_write(IDeviceObject* self, const Char* bytes) { TerminalDevice::~TerminalDevice() = default; -EXTERN_C void ke_io_read(IDeviceObject* self, const Char* bytes) { +EXTERN_C void ke_io_read(DeviceInterface* self, const Char* bytes) { #ifdef __DEBUG__ SizeT index = 0; diff --git a/dev/kernel/KernelKit/DebugOutput.h b/dev/kernel/KernelKit/DebugOutput.h index 9598f590..de3bc997 100644 --- a/dev/kernel/KernelKit/DebugOutput.h +++ b/dev/kernel/KernelKit/DebugOutput.h @@ -37,9 +37,9 @@ inline TerminalDevice hex_number(const Long& x); // @brief Emulates a VT100 terminal. class TerminalDevice final NE_DEVICE { public: - TerminalDevice(void (*print)(IDeviceObject*, const Char*), - void (*gets)(IDeviceObject*, const Char*)) - : IDeviceObject(print, gets) {} + TerminalDevice(void (*print)(DeviceInterface*, const Char*), + void (*gets)(DeviceInterface*, const Char*)) + : DeviceInterface(print, gets) {} ~TerminalDevice() override; @@ -54,9 +54,9 @@ class TerminalDevice final NE_DEVICE { class Utf8TerminalDevice final NE_DEVICE { public: - Utf8TerminalDevice(void (*print)(IDeviceObject*, const Utf8Char*), - void (*gets)(IDeviceObject*, const Utf8Char*)) - : IDeviceObject(print, gets) {} + Utf8TerminalDevice(void (*print)(DeviceInterface*, const Utf8Char*), + void (*gets)(DeviceInterface*, const Utf8Char*)) + : DeviceInterface(print, gets) {} ~Utf8TerminalDevice() override; diff --git a/dev/kernel/KernelKit/DeviceMgr.h b/dev/kernel/KernelKit/DeviceMgr.h index 0a21710d..d82b43dc 100644 --- a/dev/kernel/KernelKit/DeviceMgr.h +++ b/dev/kernel/KernelKit/DeviceMgr.h @@ -24,13 +24,13 @@ #define kDeviceMgrRootDirPath "/devices/" -#define NE_DEVICE : public ::Kernel::IDeviceObject +#define NE_DEVICE : public ::Kernel::DeviceInterface // Last Rev: Wed, May 27, 2025 6:22 PM namespace Kernel { template -class IDeviceObject; +class DeviceInterface; template class IOBuf; @@ -39,26 +39,26 @@ class IOBuf; /// @brief Device contract interface, represents an HW device. /***********************************************************************************/ template -class IDeviceObject { +class DeviceInterface { public: - IDeviceObject() = default; + DeviceInterface() = default; - explicit IDeviceObject(void (*Out)(IDeviceObject*, T), void (*In)(IDeviceObject*, T)) + explicit DeviceInterface(void (*Out)(DeviceInterface*, T), void (*In)(DeviceInterface*, T)) : fOut(Out), fIn(In) {} - virtual ~IDeviceObject() = default; + virtual ~DeviceInterface() = default; public: - IDeviceObject& operator=(const IDeviceObject&) = default; - IDeviceObject(const IDeviceObject&) = default; + DeviceInterface& operator=(const DeviceInterface&) = default; + DeviceInterface(const DeviceInterface&) = default; public: - virtual IDeviceObject& operator<<(T Data) { + virtual DeviceInterface& operator<<(T Data) { fOut(this, Data); return *this; } - virtual IDeviceObject& operator>>(T Data) { + virtual DeviceInterface& operator>>(T Data) { fIn(this, Data); return *this; } @@ -70,8 +70,8 @@ class IDeviceObject { Bool operator!() { return !fOut || !fIn; } protected: - Void (*fOut)(IDeviceObject*, T Data) = {nullptr}; - Void (*fIn)(IDeviceObject*, T Data) = {nullptr}; + Void (*fOut)(DeviceInterface*, T Data) = {nullptr}; + Void (*fIn)(DeviceInterface*, T Data) = {nullptr}; }; /// diff --git a/dev/kernel/NetworkKit/NetworkDevice.h b/dev/kernel/NetworkKit/NetworkDevice.h index c37d8504..04d208c5 100644 --- a/dev/kernel/NetworkKit/NetworkDevice.h +++ b/dev/kernel/NetworkKit/NetworkDevice.h @@ -21,8 +21,8 @@ class NetworkDevice; */ class NetworkDevice final NE_DEVICE { public: - NetworkDevice(void (*out)(IDeviceObject*, NetworkDeviceCommand), - void (*in)(IDeviceObject*, NetworkDeviceCommand), + NetworkDevice(void (*out)(DeviceInterface*, NetworkDeviceCommand), + void (*in)(DeviceInterface*, NetworkDeviceCommand), void (*cleanup)(void) = nullptr); ~NetworkDevice() override; diff --git a/dev/kernel/NetworkKit/NetworkDevice.inl b/dev/kernel/NetworkKit/NetworkDevice.inl index 84ec9edc..6ef480a9 100644 --- a/dev/kernel/NetworkKit/NetworkDevice.inl +++ b/dev/kernel/NetworkKit/NetworkDevice.inl @@ -13,12 +13,12 @@ #endif // __INC_NETWORK_DEVICE_H__ namespace Kernel { -inline NetworkDevice::NetworkDevice(void (*out)(IDeviceObject*, +inline NetworkDevice::NetworkDevice(void (*out)(DeviceInterface*, NetworkDeviceCommand), - void (*in)(IDeviceObject*, + void (*in)(DeviceInterface*, NetworkDeviceCommand), void (*on_cleanup)(void)) - : IDeviceObject(out, in), fCleanup(on_cleanup) { + : DeviceInterface(out, in), fCleanup(on_cleanup) { kout << "NetworkDevice initialized.\r"; MUST_PASS(out && in && on_cleanup); diff --git a/dev/kernel/StorageKit/AHCI.h b/dev/kernel/StorageKit/AHCI.h index e2220719..3b9dac67 100644 --- a/dev/kernel/StorageKit/AHCI.h +++ b/dev/kernel/StorageKit/AHCI.h @@ -13,11 +13,11 @@ namespace Kernel { /// @brief AHCIDeviceInterface class /// @details This class is used to send and receive data from the AHCI device. -/// @note The class is derived from the IDeviceObject class. +/// @note The class is derived from the DeviceInterface class. class AHCIDeviceInterface NE_DEVICE { public: - explicit AHCIDeviceInterface(void (*out)(IDeviceObject* self, MountpointInterface* out), - void (*in)(IDeviceObject* self, MountpointInterface* in)); + explicit AHCIDeviceInterface(void (*out)(DeviceInterface* self, MountpointInterface* out), + void (*in)(DeviceInterface* self, MountpointInterface* in)); virtual ~AHCIDeviceInterface() override; diff --git a/dev/kernel/StorageKit/ATA.h b/dev/kernel/StorageKit/ATA.h index abf255a5..d4c894a3 100644 --- a/dev/kernel/StorageKit/ATA.h +++ b/dev/kernel/StorageKit/ATA.h @@ -13,10 +13,10 @@ namespace Kernel { /// @brief ATA device interface class. -class ATADeviceInterface : public IDeviceObject { +class ATADeviceInterface : public DeviceInterface { public: - explicit ATADeviceInterface(void (*Out)(IDeviceObject*, MountpointInterface* outpacket), - void (*In)(IDeviceObject*, MountpointInterface* inpacket)); + explicit ATADeviceInterface(void (*Out)(DeviceInterface*, MountpointInterface* outpacket), + void (*In)(DeviceInterface*, MountpointInterface* inpacket)); virtual ~ATADeviceInterface(); diff --git a/dev/kernel/StorageKit/NVME.h b/dev/kernel/StorageKit/NVME.h index aae36a94..1b2b6358 100644 --- a/dev/kernel/StorageKit/NVME.h +++ b/dev/kernel/StorageKit/NVME.h @@ -12,8 +12,8 @@ namespace Kernel { class NVMEDeviceInterface final NE_DEVICE { public: - explicit NVMEDeviceInterface(Void (*out)(IDeviceObject*, MountpointInterface* out_packet), - Void (*in)(IDeviceObject*, MountpointInterface* in_packet), + explicit NVMEDeviceInterface(Void (*out)(DeviceInterface*, MountpointInterface* out_packet), + Void (*in)(DeviceInterface*, MountpointInterface* in_packet), Void (*cleanup)(Void)); ~NVMEDeviceInterface() override; diff --git a/dev/kernel/StorageKit/StorageKit.h b/dev/kernel/StorageKit/StorageKit.h index adb9f5dc..411aa6ae 100644 --- a/dev/kernel/StorageKit/StorageKit.h +++ b/dev/kernel/StorageKit/StorageKit.h @@ -12,7 +12,7 @@ namespace Kernel { template -class IDeviceObject; +class DeviceInterface; class NVMEDeviceInterface; class AHCIDeviceInterface; diff --git a/dev/kernel/src/Gfx/FBDeviceInterface.cc b/dev/kernel/src/Gfx/FBDeviceInterface.cc index d588e8c8..f1867b45 100644 --- a/dev/kernel/src/Gfx/FBDeviceInterface.cc +++ b/dev/kernel/src/Gfx/FBDeviceInterface.cc @@ -12,9 +12,9 @@ using namespace Kernel; /// @param Out Drive output /// @param In Drive input /// @param Cleanup Drive cleanup. -FBDeviceInterface::FBDeviceInterface(void (*out)(IDeviceObject* self, FBDevicePacket* outpacket), - void (*in)(IDeviceObject* self, FBDevicePacket* inpacket)) - : IDeviceObject(out, in) {} +FBDeviceInterface::FBDeviceInterface(void (*out)(DeviceInterface* self, FBDevicePacket* outpacket), + void (*in)(DeviceInterface* self, FBDevicePacket* inpacket)) + : DeviceInterface(out, in) {} /// @brief Class desctructor FBDeviceInterface::~FBDeviceInterface() = default; diff --git a/dev/kernel/src/Storage/AHCIDeviceInterface.cc b/dev/kernel/src/Storage/AHCIDeviceInterface.cc index 2d97eee7..382ce37b 100644 --- a/dev/kernel/src/Storage/AHCIDeviceInterface.cc +++ b/dev/kernel/src/Storage/AHCIDeviceInterface.cc @@ -12,11 +12,11 @@ using namespace Kernel; /// @param Out Drive output /// @param In Drive input /// @param Cleanup Drive cleanup. -AHCIDeviceInterface::AHCIDeviceInterface(void (*out)(IDeviceObject* self, +AHCIDeviceInterface::AHCIDeviceInterface(void (*out)(DeviceInterface* self, MountpointInterface* outpacket), - void (*in)(IDeviceObject* self, + void (*in)(DeviceInterface* self, MountpointInterface* inpacket)) - : IDeviceObject(out, in) {} + : DeviceInterface(out, in) {} /// @brief Class desctructor AHCIDeviceInterface::~AHCIDeviceInterface() = default; @@ -45,7 +45,7 @@ AHCIDeviceInterface& AHCIDeviceInterface::operator<<(MountpointInterface* mnt) { } } - return (AHCIDeviceInterface&) IDeviceObject::operator<<(mnt); + return (AHCIDeviceInterface&) DeviceInterface::operator<<(mnt); } /// @brief Input operator. @@ -67,7 +67,7 @@ AHCIDeviceInterface& AHCIDeviceInterface::operator>>(MountpointInterface* mnt) { } } - return (AHCIDeviceInterface&) IDeviceObject::operator>>(mnt); + return (AHCIDeviceInterface&) DeviceInterface::operator>>(mnt); } const UInt16& AHCIDeviceInterface::GetPortsImplemented() { diff --git a/dev/kernel/src/Storage/ATADeviceInterface.cc b/dev/kernel/src/Storage/ATADeviceInterface.cc index a66d812b..697571a3 100644 --- a/dev/kernel/src/Storage/ATADeviceInterface.cc +++ b/dev/kernel/src/Storage/ATADeviceInterface.cc @@ -12,9 +12,9 @@ using namespace Kernel; /// @param Out Drive output /// @param In Drive input /// @param Cleanup Drive cleanup. -ATADeviceInterface::ATADeviceInterface(void (*Out)(IDeviceObject*, MountpointInterface* outpacket), - void (*In)(IDeviceObject*, MountpointInterface* inpacket)) - : IDeviceObject(Out, In) {} +ATADeviceInterface::ATADeviceInterface(void (*Out)(DeviceInterface*, MountpointInterface* outpacket), + void (*In)(DeviceInterface*, MountpointInterface* inpacket)) + : DeviceInterface(Out, In) {} /// @brief Class desctructor ATADeviceInterface::~ATADeviceInterface() = default; @@ -43,7 +43,7 @@ ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) { } } - return (ATADeviceInterface&) IDeviceObject::operator<<(Data); + return (ATADeviceInterface&) DeviceInterface::operator<<(Data); } /// @brief Input operator. @@ -65,7 +65,7 @@ ATADeviceInterface& ATADeviceInterface::operator>>(MountpointInterface* Data) { } } - return (ATADeviceInterface&) IDeviceObject::operator>>(Data); + return (ATADeviceInterface&) DeviceInterface::operator>>(Data); } const UInt32& ATADeviceInterface::GetIndex() { diff --git a/dev/kernel/src/Storage/NVMEDeviceInterface.cc b/dev/kernel/src/Storage/NVMEDeviceInterface.cc index cff776c9..bc138710 100644 --- a/dev/kernel/src/Storage/NVMEDeviceInterface.cc +++ b/dev/kernel/src/Storage/NVMEDeviceInterface.cc @@ -7,11 +7,11 @@ #include namespace Kernel { -NVMEDeviceInterface::NVMEDeviceInterface(void (*out)(IDeviceObject*, +NVMEDeviceInterface::NVMEDeviceInterface(void (*out)(DeviceInterface*, MountpointInterface* outpacket), - void (*in)(IDeviceObject*, MountpointInterface* inpacket), + void (*in)(DeviceInterface*, MountpointInterface* inpacket), void (*cleanup)(void)) - : IDeviceObject(out, in), fCleanup(cleanup) {} + : DeviceInterface(out, in), fCleanup(cleanup) {} NVMEDeviceInterface::~NVMEDeviceInterface() { if (fCleanup) fCleanup(); diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 876cae03..1454585c 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -31,10 +31,6 @@ namespace Kernel { STATIC UInt32 kLastExitCode = 0U; -/***********************************************************************************/ -/// @brief Scheduler itself. -/***********************************************************************************/ - USER_PROCESS::USER_PROCESS() = default; USER_PROCESS::~USER_PROCESS() = default; -- cgit v1.2.3