1#ifndef BASE_TYPES_H
2#define BASE_TYPES_H
3
4#include <base/detect.h>
5
6#include <cstdint>
7#include <ctime>
8#include <functional>
9
10#if defined(CONF_FAMILY_UNIX)
11#include <sys/types.h> // pid_t
12#endif
13
14enum class TRISTATE
15{
16 NONE,
17 SOME,
18 ALL,
19};
20
21/**
22 * The maximum supported length of a file/folder path including null-termination.
23 *
24 * @ingroup File-IO
25 */
26inline constexpr auto IO_MAX_PATH_LENGTH = 512;
27
28/**
29 * Handle for input/output files/streams.
30 *
31 * @ingroup File-IO
32 */
33typedef void *IOHANDLE;
34
35/**
36 * Wrapper for asynchronously writing to an @link IOHANDLE @endlink.
37 *
38 * @ingroup File-IO
39 */
40typedef struct ASYNCIO ASYNCIO;
41
42/**
43 * Callback function type for @link fs_listdir @endlink.
44 *
45 * @ingroup Filesystem
46 *
47 * @param name The name of the file/folder entry.
48 * @param is_dir Whether the entry is a file (`0`) or folder (`1`).
49 * @param dir_type The value of the `type` parameter passed to `fs_listdir`.
50 * @param user The value of the `user` parameter passed to `fs_listdir`.
51 *
52 * @return `0` to continue enumerating file/folder entries, or `1` to stop enumerating.
53 *
54 * @see fs_listdir
55 */
56typedef int (*FS_LISTDIR_CALLBACK)(const char *name, int is_dir, int dir_type, void *user);
57
58/**
59 * Represents a file/folder entry for the @link FS_LISTDIR_CALLBACK_FILEINFO @endlink
60 * when using @link fs_listdir_fileinfo @endlink.
61 *
62 * @ingroup Filesystem
63 */
64class CFsFileInfo
65{
66public:
67 /**
68 * The name of the file/folder entry.
69 */
70 const char *m_pName;
71
72 /**
73 * The creation time of the file/folder.
74 */
75 time_t m_TimeCreated;
76
77 /**
78 * The modification time of the file/folder.
79 */
80 time_t m_TimeModified;
81};
82
83/**
84 * Callback function type for @link fs_listdir_fileinfo @endlink.
85 *
86 * @ingroup Filesystem
87 *
88 * @param info Information of the file/folder entry.
89 * @param is_dir Whether the entry is a file (`0`) or folder (`1`).
90 * @param dir_type The value of the `type` parameter passed to `fs_listdir_fileinfo`.
91 * @param user The value of the `user` parameter passed to `fs_listdir_fileinfo`.
92 *
93 * @return `0` to continue enumerating file/folder entries, or `1` to stop enumerating.
94 *
95 * @see fs_listdir_fileinfo
96 */
97typedef int (*FS_LISTDIR_CALLBACK_FILEINFO)(const CFsFileInfo *info, int is_dir, int dir_type, void *user);
98
99/**
100 * The maximum bytes necessary to encode one Unicode codepoint with UTF-8.
101 *
102 * @ingroup Strings
103 */
104inline constexpr auto UTF8_BYTE_LENGTH = 4;
105
106/**
107 * @ingroup Network-General
108 */
109typedef struct NETSOCKET_INTERNAL *NETSOCKET;
110
111/**
112 * @ingroup Network-General
113 */
114inline constexpr auto NETTYPE_INVALID = 0;
115
116/**
117 * @ingroup Network-General
118 */
119inline constexpr auto NETTYPE_IPV4 = 1 << 0;
120
121/**
122 * @ingroup Network-General
123 */
124inline constexpr auto NETTYPE_IPV6 = 1 << 1;
125
126/**
127 * @ingroup Network-General
128 */
129inline constexpr auto NETTYPE_WEBSOCKET_IPV4 = 1 << 2;
130
131/**
132 * @ingroup Network-General
133 */
134inline constexpr auto NETTYPE_WEBSOCKET_IPV6 = 1 << 3;
135
136/**
137 * @ingroup Network-General
138 */
139inline constexpr auto NETTYPE_LINK_BROADCAST = 1 << 4;
140
141/**
142 * 0.7 address. This is a flag in NETADDR to avoid introducing a parameter to every networking function
143 * to differentiate between 0.6 and 0.7 connections.
144 *
145 * @ingroup Network-General
146 */
147inline constexpr auto NETTYPE_TW7 = 1 << 5;
148
149/**
150 * @ingroup Network-General
151 */
152inline constexpr auto NETTYPE_ALL = NETTYPE_IPV4 | NETTYPE_IPV6 | NETTYPE_WEBSOCKET_IPV4 | NETTYPE_WEBSOCKET_IPV6;
153
154/**
155 * @ingroup Network-General
156 */
157inline constexpr auto NETTYPE_MASK = NETTYPE_ALL | NETTYPE_LINK_BROADCAST | NETTYPE_TW7;
158
159/**
160 * @ingroup Network-Address
161 */
162inline constexpr auto NETADDR_MAXSTRSIZE = 1 + (8 * 4 + 7) + 1 + 1 + 5 + 1; // [XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX]:XXXXX
163
164/**
165 * @ingroup Network-Address
166 */
167typedef struct NETADDR
168{
169 unsigned int type;
170 unsigned char ip[16];
171 unsigned short port;
172
173 bool operator==(const NETADDR &other) const;
174 bool operator!=(const NETADDR &other) const;
175 bool operator<(const NETADDR &other) const;
176} NETADDR;
177
178/**
179 * @ingroup Network-Address
180 */
181template<>
182struct std::hash<NETADDR>
183{
184 size_t operator()(const NETADDR &Addr) const noexcept;
185};
186
187/**
188 * @ingroup Network-General
189 */
190typedef struct NETSTATS
191{
192 uint64_t sent_packets;
193 uint64_t sent_bytes;
194 uint64_t recv_packets;
195 uint64_t recv_bytes;
196} NETSTATS;
197
198#if defined(CONF_FAMILY_WINDOWS)
199/**
200 * A handle for a process.
201 *
202 * @ingroup Process
203 */
204typedef void *PROCESS;
205/**
206 * A handle that denotes an invalid process.
207 *
208 * @ingroup Process
209 */
210constexpr PROCESS INVALID_PROCESS = nullptr; // NOLINT(misc-misplaced-const)
211#else
212/**
213 * A handle for a process.
214 *
215 * @ingroup Process
216 */
217typedef pid_t PROCESS;
218/**
219 * A handle that denotes an invalid process.
220 *
221 * @ingroup Process
222 */
223constexpr PROCESS INVALID_PROCESS = 0;
224#endif
225
226#endif // BASE_TYPES_H
227