diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 09:14:11 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 09:14:11 +0100 |
| commit | 5339d016c07bf717ee388f4feb73544087324af0 (patch) | |
| tree | 94be6f67ed626091f24aee24ec3b3be03d01e4e7 /KernelKit/Device.hpp | |
git: port from mercurial repo.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'KernelKit/Device.hpp')
| -rw-r--r-- | KernelKit/Device.hpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/KernelKit/Device.hpp b/KernelKit/Device.hpp new file mode 100644 index 00000000..859a198b --- /dev/null +++ b/KernelKit/Device.hpp @@ -0,0 +1,97 @@ +/* + * ======================================================== + * + * hCore + * Copyright 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 IDevice; + + template<typename T> + class IDevice + { + public: + IDevice(void (*Out)(T), void (*In)(T)) + : m_Out(Out), m_In(In) {} + + virtual ~IDevice() = default; + + public: + IDevice &operator=(const IDevice<T> &) = default; + IDevice(const IDevice<T> &) = default; + + public: + IDevice<T> &operator<<(T Data) + { + m_Out(Data); + return *this; + } + + IDevice<T> &operator>>(T Data) + { + m_In(Data); + return *this; + } + + virtual const char *Name() const + { + return ("IDevice"); + } + + 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 |
