diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-26 22:26:48 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-26 22:27:09 +0100 |
| commit | eba8b7ddd0a455d9e49f32dcae712c5612c0093c (patch) | |
| tree | 749a3d34546d055507a920bce4ab10e8a9945719 /Private/KernelKit/Device.hpp | |
| parent | dd192787a70a973f2474720aea49af3f6ddabb7a (diff) | |
Kernel: Major repository refactor.
Rework the repo into Private and Public modules.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/KernelKit/Device.hpp')
| -rw-r--r-- | Private/KernelKit/Device.hpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/Private/KernelKit/Device.hpp b/Private/KernelKit/Device.hpp new file mode 100644 index 00000000..b117cf7f --- /dev/null +++ b/Private/KernelKit/Device.hpp @@ -0,0 +1,97 @@ +/* + * ======================================================== + * + * hCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +/* hCore */ +/* File: KernelKit/Device.hpp */ +/* Device abstraction utilities. */ + +#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; + + }; + + ///! device types. + enum + { + kDeviceIde, + kDeviceNetwork, + kDevicePrinter, + kDeviceGSDB, + kDeviceScsi, + kDeviceSata, + kDeviceUsb, + kDeviceCD, + kDeviceSwap, + }; +} // namespace hCore |
