/* * ======================================================== * * 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 { kDeviceIde, kDeviceNetwork, kDevicePrinter, kDeviceGSDB, kDeviceScsi, kDeviceSata, kDeviceUsb, kDeviceCD, kDeviceSwap, kDeviceCnt, }; } // namespace HCore