/* ------------------------------------------- Copyright Mahrouss Logic ------------------------------------------- */ /* ------------------------------------------- Revision History: 31/01/24: Add kDeviceCnt (amlel) ------------------------------------------- */ #pragma once /* NewOS device interface manager. */ /* @file KernelKit/DeviceManager.hpp */ /* @brief Device abstraction and I/O buffer. */ #include #include // Last Rev // Sat Feb 24 CET 2024 namespace NewOS { 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); }; /// /// @brief Input Output Buffer /// Used mainly to communicate between hardware. /// template class IOBuf final { public: explicit IOBuf(T Dat) : m_Data(Dat) { // at least pass something valid when instancating this struct. MUST_PASS(Dat); } IOBuf &operator=(const IOBuf &) = default; IOBuf(const IOBuf &) = default; ~IOBuf() = default; public: template R operator->() const { return m_Data; } template R &operator[](Size index) const { return m_Data[index]; } private: T m_Data; }; ///! @brief Device enum types. enum { kDeviceTypeIDE, kDeviceTypeEthernet, kDeviceTypeWiFi, kDeviceTypeRS232, kDeviceTypeSCSI, kDeviceTypeSHCI, kDeviceTypeUSB, kDeviceTypeMedia, kDeviceTypeCount, }; } // namespace NewOS