summaryrefslogtreecommitdiffhomepage
path: root/NewKernel/KernelKit/DeviceManager.hpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-08 12:32:41 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-08 12:32:41 +0200
commit09dd11ddf800898c00ecb04a65fb5cd10fb481fa (patch)
treeeda0b4e23d6a71da7de3a78f0bb76ec3201dd2f9 /NewKernel/KernelKit/DeviceManager.hpp
parentca83108fd138cc0398f900e6a6c0a53ad51aee31 (diff)
MHR-23: :boom: changes, reworked project tree.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'NewKernel/KernelKit/DeviceManager.hpp')
-rw-r--r--NewKernel/KernelKit/DeviceManager.hpp131
1 files changed, 131 insertions, 0 deletions
diff --git a/NewKernel/KernelKit/DeviceManager.hpp b/NewKernel/KernelKit/DeviceManager.hpp
new file mode 100644
index 00000000..e9baa194
--- /dev/null
+++ b/NewKernel/KernelKit/DeviceManager.hpp
@@ -0,0 +1,131 @@
+/* -------------------------------------------
+
+ 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 <NewKit/ErrorOr.hpp>
+#include <NewKit/Ref.hpp>
+
+#define kDriveManagerCount 4U
+
+// Last Rev
+// Wed, Apr 3, 2024 9:09:41 AM
+
+namespace NewOS
+{
+ template <typename T>
+ class DeviceInterface;
+
+ template <typename T>
+ class DeviceInterface
+ {
+ public:
+ explicit DeviceInterface(void (*Out)(T), void (*In)(T))
+ : fOut(Out), fIn(In)
+ {
+ }
+
+ virtual ~DeviceInterface() = default;
+
+ public:
+ DeviceInterface& operator=(const DeviceInterface<T>&) = default;
+ DeviceInterface(const DeviceInterface<T>&) = default;
+
+ public:
+ virtual DeviceInterface<T>& operator<<(T Data)
+ {
+ fOut(Data);
+ return *this;
+ }
+
+ virtual DeviceInterface<T>& operator>>(T Data)
+ {
+ fIn(Data);
+ return *this;
+ }
+
+ virtual const char* Name() const
+ {
+ return "DeviceInterface";
+ }
+
+ operator bool()
+ {
+ return fOut && fIn;
+ }
+ bool operator!()
+ {
+ return !fOut && !fIn;
+ }
+
+ private:
+ void (*fOut)(T Data);
+ void (*fIn)(T Data);
+ };
+
+ ///
+ /// @brief Input Output Buffer
+ /// Used mainly to communicate between hardware.
+ ///
+ template <typename T>
+ class IOBuf final
+ {
+ public:
+ explicit IOBuf(T Dat)
+ : fData(Dat)
+ {
+ // at least pass something valid when instancating this struct.
+ MUST_PASS(Dat);
+ }
+
+ IOBuf& operator=(const IOBuf<T>&) = default;
+ IOBuf(const IOBuf<T>&) = default;
+
+ ~IOBuf() = default;
+
+ public:
+ template <typename R>
+ R operator->() const
+ {
+ return fData;
+ }
+
+ template <typename R>
+ R& operator[](Size index) const
+ {
+ return fData[index];
+ }
+
+ private:
+ T fData;
+ };
+
+ ///! @brief Device enum types.
+ enum
+ {
+ kDeviceTypeIDE,
+ kDeviceTypeEthernet,
+ kDeviceTypeWiFi,
+ kDeviceTypeRS232,
+ kDeviceTypeSCSI,
+ kDeviceTypeSHCI,
+ kDeviceTypeUSB,
+ kDeviceTypeMedia,
+ kDeviceTypeCount,
+ };
+} // namespace NewOS