diff options
| author | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-02 20:11:24 +0200 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-02 20:11:24 +0200 |
| commit | 59578978610f6af245f571a011694a51d94dc530 (patch) | |
| tree | 3553807ef1c8095248520ee823c1426aef8738d8 /Kernel/KernelKit/DeviceManager.hxx | |
| parent | 9afcd1c001703c32964fed5906f36a2d913e91e9 (diff) | |
[unstable] [META] refactor whole project.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Kernel/KernelKit/DeviceManager.hxx')
| -rw-r--r-- | Kernel/KernelKit/DeviceManager.hxx | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/Kernel/KernelKit/DeviceManager.hxx b/Kernel/KernelKit/DeviceManager.hxx new file mode 100644 index 00000000..819fb498 --- /dev/null +++ b/Kernel/KernelKit/DeviceManager.hxx @@ -0,0 +1,129 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +/* ------------------------------------------- + + Revision History: + + 31/01/24: Add kDeviceCnt (amlel) + + ------------------------------------------- */ + +#pragma once + +/* Kernel device interface manager. */ +/* @file KernelKit/DeviceManager.hpp */ +/* @brief Device abstraction and I/O buffer. */ + +#include <NewKit/ErrorOr.hxx> +#include <NewKit/Ref.hxx> + +// Last Rev +// Wed, Apr 3, 2024 9:09:41 AM + +namespace Kernel +{ + template <typename T> + class DeviceInterface; + + template <typename T> + class DeviceInterface + { + public: + explicit DeviceInterface(void (*Out)(T), void (*In)(T)) + : fOut(Out), fIn(In) + { + } + + virtual ~DeviceInterface() = default; + + public: + DeviceInterface& operator=(const DeviceInterface<T>&) = default; + DeviceInterface(const DeviceInterface<T>&) = default; + + public: + virtual DeviceInterface<T>& operator<<(T Data) + { + fOut(Data); + return *this; + } + + virtual DeviceInterface<T>& operator>>(T Data) + { + fIn(Data); + return *this; + } + + virtual const char* Name() const + { + return "DeviceInterface"; + } + + operator bool() + { + return fOut && fIn; + } + bool operator!() + { + return !fOut || !fIn; + } + + private: + void (*fOut)(T Data) = {nullptr}; + void (*fIn)(T Data) = {nullptr}; + }; + + /// + /// @brief Input Output Buffer + /// Used mainly to communicate between hardware. + /// + template <typename T> + class IOBuf final + { + public: + explicit IOBuf(T Dat) + : fData(Dat) + { + // at least pass something valid when instancating this struct. + MUST_PASS(Dat); + } + + IOBuf& operator=(const IOBuf<T>&) = default; + IOBuf(const IOBuf<T>&) = default; + + ~IOBuf() = default; + + public: + template <typename R> + R operator->() const + { + return fData; + } + + template <typename R> + R& operator[](Size index) const + { + return fData[index]; + } + + private: + T fData; + }; + + ///! @brief Device enum types. + enum + { + kDeviceTypeIDE, + kDeviceTypeEthernet, + kDeviceTypeWiFi, + kDeviceTypeRS232, + kDeviceTypeSCSI, + kDeviceTypeSHCI, + kDeviceTypeUSB, + kDeviceTypeMedia, + kDeviceTypeCount, + }; +} // namespace Kernel |
