| 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 | * Handle for input/output files/streams. |
| 23 | * |
| 24 | * @ingroup File-IO |
| 25 | */ |
| 26 | typedef void *IOHANDLE; |
| 27 | |
| 28 | /** |
| 29 | * Wrapper for asynchronously writing to an @link IOHANDLE @endlink. |
| 30 | * |
| 31 | * @ingroup File-IO |
| 32 | */ |
| 33 | typedef struct ASYNCIO ASYNCIO; |
| 34 | |
| 35 | typedef int (*FS_LISTDIR_CALLBACK)(const char *name, int is_dir, int dir_type, void *user); |
| 36 | |
| 37 | typedef struct |
| 38 | { |
| 39 | const char *m_pName; |
| 40 | time_t m_TimeCreated; // seconds since UNIX Epoch |
| 41 | time_t m_TimeModified; // seconds since UNIX Epoch |
| 42 | } CFsFileInfo; |
| 43 | |
| 44 | typedef int (*FS_LISTDIR_CALLBACK_FILEINFO)(const CFsFileInfo *info, int is_dir, int dir_type, void *user); |
| 45 | |
| 46 | /** |
| 47 | * The maximum bytes necessary to encode one Unicode codepoint with UTF-8. |
| 48 | */ |
| 49 | inline constexpr auto UTF8_BYTE_LENGTH = 4; |
| 50 | |
| 51 | inline constexpr auto IO_MAX_PATH_LENGTH = 512; |
| 52 | |
| 53 | /** |
| 54 | * @ingroup Network-General |
| 55 | */ |
| 56 | typedef struct NETSOCKET_INTERNAL *NETSOCKET; |
| 57 | |
| 58 | /** |
| 59 | * @ingroup Network-General |
| 60 | */ |
| 61 | inline constexpr auto NETTYPE_INVALID = 0; |
| 62 | |
| 63 | /** |
| 64 | * @ingroup Network-General |
| 65 | */ |
| 66 | inline constexpr auto NETTYPE_IPV4 = 1 << 0; |
| 67 | |
| 68 | /** |
| 69 | * @ingroup Network-General |
| 70 | */ |
| 71 | inline constexpr auto NETTYPE_IPV6 = 1 << 1; |
| 72 | |
| 73 | /** |
| 74 | * @ingroup Network-General |
| 75 | */ |
| 76 | inline constexpr auto NETTYPE_WEBSOCKET_IPV4 = 1 << 2; |
| 77 | |
| 78 | /** |
| 79 | * @ingroup Network-General |
| 80 | */ |
| 81 | inline constexpr auto NETTYPE_WEBSOCKET_IPV6 = 1 << 3; |
| 82 | |
| 83 | /** |
| 84 | * @ingroup Network-General |
| 85 | */ |
| 86 | inline constexpr auto NETTYPE_LINK_BROADCAST = 1 << 4; |
| 87 | /** |
| 88 | * 0.7 address. This is a flag in NETADDR to avoid introducing a parameter to every networking function |
| 89 | * to differentiate between 0.6 and 0.7 connections. |
| 90 | * |
| 91 | * @ingroup Network-General |
| 92 | */ |
| 93 | inline constexpr auto NETTYPE_TW7 = 1 << 5; |
| 94 | |
| 95 | /** |
| 96 | * @ingroup Network-General |
| 97 | */ |
| 98 | inline constexpr auto NETTYPE_ALL = NETTYPE_IPV4 | NETTYPE_IPV6 | NETTYPE_WEBSOCKET_IPV4 | NETTYPE_WEBSOCKET_IPV6; |
| 99 | |
| 100 | /** |
| 101 | * @ingroup Network-General |
| 102 | */ |
| 103 | inline constexpr auto NETTYPE_MASK = NETTYPE_ALL | NETTYPE_LINK_BROADCAST | NETTYPE_TW7; |
| 104 | |
| 105 | /** |
| 106 | * @ingroup Network-Address |
| 107 | */ |
| 108 | inline constexpr auto NETADDR_MAXSTRSIZE = 1 + (8 * 4 + 7) + 1 + 1 + 5 + 1; // [XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX]:XXXXX |
| 109 | |
| 110 | /** |
| 111 | * @ingroup Network-Address |
| 112 | */ |
| 113 | typedef struct NETADDR |
| 114 | { |
| 115 | unsigned int type; |
| 116 | unsigned char ip[16]; |
| 117 | unsigned short port; |
| 118 | |
| 119 | bool operator==(const NETADDR &other) const; |
| 120 | bool operator!=(const NETADDR &other) const; |
| 121 | bool operator<(const NETADDR &other) const; |
| 122 | } NETADDR; |
| 123 | |
| 124 | template<> |
| 125 | struct std::hash<NETADDR> |
| 126 | { |
| 127 | size_t operator()(const NETADDR &Addr) const noexcept; |
| 128 | }; |
| 129 | |
| 130 | /** |
| 131 | * @ingroup Network-General |
| 132 | */ |
| 133 | typedef struct NETSTATS |
| 134 | { |
| 135 | uint64_t sent_packets; |
| 136 | uint64_t sent_bytes; |
| 137 | uint64_t recv_packets; |
| 138 | uint64_t recv_bytes; |
| 139 | } NETSTATS; |
| 140 | |
| 141 | #if defined(CONF_FAMILY_WINDOWS) |
| 142 | /** |
| 143 | * A handle for a process. |
| 144 | * |
| 145 | * @ingroup Process |
| 146 | */ |
| 147 | typedef void *PROCESS; |
| 148 | /** |
| 149 | * A handle that denotes an invalid process. |
| 150 | * |
| 151 | * @ingroup Process |
| 152 | */ |
| 153 | constexpr PROCESS INVALID_PROCESS = nullptr; // NOLINT(misc-misplaced-const) |
| 154 | #else |
| 155 | /** |
| 156 | * A handle for a process. |
| 157 | * |
| 158 | * @ingroup Process |
| 159 | */ |
| 160 | typedef pid_t PROCESS; |
| 161 | /** |
| 162 | * A handle that denotes an invalid process. |
| 163 | * |
| 164 | * @ingroup Process |
| 165 | */ |
| 166 | constexpr PROCESS INVALID_PROCESS = 0; |
| 167 | #endif |
| 168 | |
| 169 | #endif // BASE_TYPES_H |
| 170 | |