1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/*
* ========================================================
*
* 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 <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;
};
///! @brief Device types enum.
enum {
kDeviceIde,
kDeviceNetwork,
kDevicePrinter,
kDeviceGSDB,
kDeviceScsi,
kDeviceSata,
kDeviceUsb,
kDeviceCD,
kDeviceSwap,
kDeviceCnt,
};
} // namespace HCore
|