diff options
| author | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-13 17:20:30 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-13 17:21:05 +0100 |
| commit | b75417b44d5f63ea0ead68cbe8f62bd76df62229 (patch) | |
| tree | 81527a21bdf4ae8f14fb8acd0ff04d9d127f24d3 /Private/KernelKit/DeviceManager.hpp | |
| parent | a9ac78b47dd040e04afc4990dace2472df2302e4 (diff) | |
HCR-15: Merge to master branch.
Important commit and end of ticket.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/KernelKit/DeviceManager.hpp')
| -rw-r--r-- | Private/KernelKit/DeviceManager.hpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/Private/KernelKit/DeviceManager.hpp b/Private/KernelKit/DeviceManager.hpp new file mode 100644 index 00000000..9a689b26 --- /dev/null +++ b/Private/KernelKit/DeviceManager.hpp @@ -0,0 +1,93 @@ +/* + * ======================================================== + * + * HCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +/* ------------------------------------------- + + Revision History: + + 31/01/24: Add kDeviceCnt (amlel) + + ------------------------------------------- */ + +#pragma once + +/* HCore */ +/* File: KernelKit/Device.hpp */ +/* Device abstraction and I/O buffer. */ + +#include <NewKit/ErrorOr.hpp> +#include <NewKit/Ref.hpp> + +namespace HCore { +template <typename T> +class DeviceInterface; + +template <typename T> +class DeviceInterface { + public: + explicit DeviceInterface(void (*Out)(T), void (*In)(T)) + : m_Out(Out), m_In(In) {} + + virtual ~DeviceInterface() = default; + + public: + DeviceInterface &operator=(const DeviceInterface<T> &) = default; + DeviceInterface(const DeviceInterface<T> &) = default; + + public: + DeviceInterface<T> &operator<<(T Data) { + m_Out(Data); + return *this; + } + + DeviceInterface<T> &operator>>(T Data) { + m_In(Data); + return *this; + } + + virtual const char *Name() const { return "DeviceInterface"; } + + operator bool() { return m_Out && m_In; } + bool operator!() { return !m_Out && !m_In; } + + private: + void (*m_Out)(T Data); + void (*m_In)(T Data); +}; + +template <typename T> +class IOBuf final { + public: + explicit IOBuf(T Dat) : m_Data(Dat) {} + + IOBuf &operator=(const IOBuf<T> &) = default; + IOBuf(const IOBuf<T> &) = default; + + ~IOBuf() = default; + + public: + T operator->() const { return m_Data; } + T &operator[](Size index) const { return m_Data[index]; } + + private: + T m_Data; +}; + +///! @brief Device types enum. +enum { + kDeviceTypeIDE, + kDeviceTypeEthernet, + kDeviceTypeWiFi, + kDeviceTypeRS232, + kDeviceTypeSCSI, + kDeviceTypeSHCI, + kDeviceTypeUSB, + kDeviceTypeCount, +}; +} // namespace HCore |
