| 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 | |
| 14 | enum 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 | */ |
| 26 | inline constexpr auto IO_MAX_PATH_LENGTH = 512; |
| 27 | |
| 28 | /** |
| 29 | * Handle for input/output files/streams. |
| 30 | * |
| 31 | * @ingroup File-IO |
| 32 | */ |
| 33 | typedef void *IOHANDLE; |
| 34 | |
| 35 | /** |
| 36 | * Wrapper for asynchronously writing to an @link IOHANDLE @endlink. |
| 37 | * |
| 38 | * @ingroup File-IO |
| 39 | */ |
| 40 | typedef 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 | */ |
| 56 | typedef 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 | */ |
| 64 | class CFsFileInfo |
| 65 | { |
| 66 | public: |
| 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 | */ |
| 97 | typedef 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 | */ |
| 104 | inline constexpr auto UTF8_BYTE_LENGTH = 4; |
| 105 | |
| 106 | /** |
| 107 | * @ingroup Network-General |
| 108 | */ |
| 109 | typedef struct NETSOCKET_INTERNAL *NETSOCKET; |
| 110 | |
| 111 | /** |
| 112 | * @ingroup Network-General |
| 113 | */ |
| 114 | inline constexpr auto NETTYPE_INVALID = 0; |
| 115 | |
| 116 | /** |
| 117 | * @ingroup Network-General |
| 118 | */ |
| 119 | inline constexpr auto NETTYPE_IPV4 = 1 << 0; |
| 120 | |
| 121 | /** |
| 122 | * @ingroup Network-General |
| 123 | */ |
| 124 | inline constexpr auto NETTYPE_IPV6 = 1 << 1; |
| 125 | |
| 126 | /** |
| 127 | * @ingroup Network-General |
| 128 | */ |
| 129 | inline constexpr auto NETTYPE_WEBSOCKET_IPV4 = 1 << 2; |
| 130 | |
| 131 | /** |
| 132 | * @ingroup Network-General |
| 133 | */ |
| 134 | inline constexpr auto NETTYPE_WEBSOCKET_IPV6 = 1 << 3; |
| 135 | |
| 136 | /** |
| 137 | * @ingroup Network-General |
| 138 | */ |
| 139 | inline 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 | */ |
| 147 | inline constexpr auto NETTYPE_TW7 = 1 << 5; |
| 148 | |
| 149 | /** |
| 150 | * @ingroup Network-General |
| 151 | */ |
| 152 | inline constexpr auto NETTYPE_ALL = NETTYPE_IPV4 | NETTYPE_IPV6 | NETTYPE_WEBSOCKET_IPV4 | NETTYPE_WEBSOCKET_IPV6; |
| 153 | |
| 154 | /** |
| 155 | * @ingroup Network-General |
| 156 | */ |
| 157 | inline constexpr auto NETTYPE_MASK = NETTYPE_ALL | NETTYPE_LINK_BROADCAST | NETTYPE_TW7; |
| 158 | |
| 159 | /** |
| 160 | * @ingroup Network-Address |
| 161 | */ |
| 162 | inline 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 | */ |
| 167 | typedef 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 | */ |
| 181 | template<> |
| 182 | struct std::hash<NETADDR> |
| 183 | { |
| 184 | size_t operator()(const NETADDR &Addr) const noexcept; |
| 185 | }; |
| 186 | |
| 187 | /** |
| 188 | * @ingroup Network-General |
| 189 | */ |
| 190 | typedef 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 | */ |
| 204 | typedef void *PROCESS; |
| 205 | /** |
| 206 | * A handle that denotes an invalid process. |
| 207 | * |
| 208 | * @ingroup Process |
| 209 | */ |
| 210 | constexpr PROCESS INVALID_PROCESS = nullptr; // NOLINT(misc-misplaced-const) |
| 211 | #else |
| 212 | /** |
| 213 | * A handle for a process. |
| 214 | * |
| 215 | * @ingroup Process |
| 216 | */ |
| 217 | typedef pid_t PROCESS; |
| 218 | /** |
| 219 | * A handle that denotes an invalid process. |
| 220 | * |
| 221 | * @ingroup Process |
| 222 | */ |
| 223 | constexpr PROCESS INVALID_PROCESS = 0; |
| 224 | #endif |
| 225 | |
| 226 | #endif // BASE_TYPES_H |
| 227 | |