From b75417b44d5f63ea0ead68cbe8f62bd76df62229 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 13 Feb 2024 17:20:30 +0100 Subject: HCR-15: Merge to master branch. Important commit and end of ticket. Signed-off-by: Amlal El Mahrouss --- Private/KernelKit/DeviceManager.hpp | 93 +++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Private/KernelKit/DeviceManager.hpp (limited to 'Private/KernelKit/DeviceManager.hpp') 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 +#include + +namespace HCore { +template +class DeviceInterface; + +template +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 &) = default; + DeviceInterface(const DeviceInterface &) = default; + + public: + DeviceInterface &operator<<(T Data) { + m_Out(Data); + return *this; + } + + DeviceInterface &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 +class IOBuf final { + public: + explicit IOBuf(T Dat) : m_Data(Dat) {} + + IOBuf &operator=(const IOBuf &) = default; + IOBuf(const IOBuf &) = 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 -- cgit v1.2.3