summaryrefslogtreecommitdiffhomepage
path: root/KernelKit/Device.hpp
blob: 859a198b4a8bc402ba87db5d7685ff855e4e3780 (plain)
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
96
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