MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
device_constants.hpp
1#ifndef MSTL_CORE_SYSTEM_DEVICE_DEVICE_CONSTANTS_HPP__
2#define MSTL_CORE_SYSTEM_DEVICE_DEVICE_CONSTANTS_HPP__
3#include "MSTL/core/file/path.hpp"
6
7enum class DEVICE_TYPE {
8 SERIAL_PORT,
9 STORAGE,
10 HID,
11 NETWORK,
12 AUDIO,
13 VIDEO,
14 GENERIC,
15 UNKNOWN
16};
17
18string MSTL_API to_string(DEVICE_TYPE type);
19
20DEVICE_TYPE MSTL_API to_device_t(const string& str);
21
22
23enum class DEVICE_OPEN_MODE {
24 READ,
25 WRITE,
26 READ_WRITE,
27 NON_BLOCKING
28};
29
30enum class DEVICE_OPEN_FLAG : uint32_t {
31 NONE = 0,
32 EXCLUSIVE = 1 << 0,
33 NO_INHERIT = 1 << 1,
34 ASYNC = 1 << 2,
35 DIRECT_IO = 1 << 3,
36 SYNC = 1 << 4,
37 CREATE = 1 << 5
38};
39
40constexpr DEVICE_OPEN_FLAG operator|(DEVICE_OPEN_FLAG a, DEVICE_OPEN_FLAG b) {
41 return static_cast<DEVICE_OPEN_FLAG>(
42 static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
43}
44
45constexpr DEVICE_OPEN_FLAG operator&(DEVICE_OPEN_FLAG a, DEVICE_OPEN_FLAG b) {
46 return static_cast<DEVICE_OPEN_FLAG>(
47 static_cast<uint32_t>(a) & static_cast<uint32_t>(b));
48}
49
50enum class DEVICE_IO_DIRECT {
51 READ, // IN
52 WRITE, // OUT
53 BOTH
54};
55
56enum class DEVICE_EVENT {
57 DATA_AVAILABLE,
58 WRITE_READY,
59 ERROR_OCCURRED,
60 DISCONNECTED
61};
62
63
64struct device_info {
65 _MSTL path path;
66 string friendly_name;
67 string hardware_id;
68 string manufacturer;
69 string description;
70 DEVICE_TYPE type{DEVICE_TYPE::UNKNOWN};
71 uint16_t vendor_id{0};
72 uint16_t product_id{0};
73 uint32_t device_id{0};
74 uint64_t size_bytes{0};
75 uint32_t block_size{512};
76 bool removable{false};
77 bool present{false};
78 bool exclusive{false};
79};
80
81
82class ioctl_command {
83public:
84#ifdef MSTL_PLATFORM_WINDOWS__
85 using native_type = ::DWORD;
86#else
87 using native_type = unsigned long;
88#endif
89
90 explicit ioctl_command(native_type code, const void* in_data = nullptr,
91 size_t in_size = 0, void* out_data = nullptr, size_t out_size = 0)
92 : code_(code), in_data_(in_data), in_size_(in_size),
93 out_data_(out_data), out_size_(out_size) {}
94
95 MSTL_NODISCARD native_type code() const noexcept { return code_; }
96 MSTL_NODISCARD const void* in_data() const noexcept { return in_data_; }
97 MSTL_NODISCARD size_t in_size() const noexcept { return in_size_; }
98 MSTL_NODISCARD void* out_data() const noexcept { return out_data_; }
99 MSTL_NODISCARD size_t out_size() const noexcept { return out_size_; }
100
101 template <typename T>
102 static ioctl_command make(native_type code, const T& data) {
103 return ioctl_command(code, &data, sizeof(T));
104 }
105
106 template <typename T>
107 static ioctl_command make_with_output(native_type code, T& output) {
108 return ioctl_command(code, nullptr, 0, &output, sizeof(T));
109 }
110
111private:
112 native_type code_;
113 const void* in_data_;
114 size_t in_size_;
115 void* out_data_;
116 size_t out_size_;
117};
118
119
120using device_event_callback = function<void(DEVICE_EVENT)>;
121using data_received_callback = function<void(const void*, size_t)>;
122using io_completion_callback = function<void(size_t, int)>;
123
125#endif // MSTL_CORE_SYSTEM_DEVICE_DEVICE_CONSTANTS_HPP__
函数包装器主模板声明
MSTL通用函数包装器
unsigned int uint32_t
32位无符号整数类型
unsigned short uint16_t
16位无符号整数类型
unsigned long long uint64_t
64位无符号整数类型
constexpr memory_order operator|(memory_order mo, memory_order_modifier mod) noexcept
内存顺序与修饰符的或操作符
constexpr memory_order operator&(memory_order mo, memory_order_modifier mod) noexcept
内存顺序与修饰符的与操作符
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) data(Container &cont) noexcept(noexcept(cont.data()))
获取容器的底层数据指针