| 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 | typedef int (*FS_LISTDIR_CALLBACK)(const char *name, int is_dir, int dir_type, void *user); |
| 29 | |
| 30 | typedef struct |
| 31 | { |
| 32 | const char *m_pName; |
| 33 | time_t m_TimeCreated; // seconds since UNIX Epoch |
| 34 | time_t m_TimeModified; // seconds since UNIX Epoch |
| 35 | } CFsFileInfo; |
| 36 | |
| 37 | typedef int (*FS_LISTDIR_CALLBACK_FILEINFO)(const CFsFileInfo *info, int is_dir, int dir_type, void *user); |
| 38 | |
| 39 | /** |
| 40 | * @ingroup Network-General |
| 41 | */ |
| 42 | typedef struct NETSOCKET_INTERNAL *NETSOCKET; |
| 43 | |
| 44 | /** |
| 45 | * The maximum bytes necessary to encode one Unicode codepoint with UTF-8. |
| 46 | */ |
| 47 | inline constexpr auto UTF8_BYTE_LENGTH = 4; |
| 48 | |
| 49 | inline constexpr auto IO_MAX_PATH_LENGTH = 512; |
| 50 | |
| 51 | inline constexpr auto NETADDR_MAXSTRSIZE = 1 + (8 * 4 + 7) + 1 + 1 + 5 + 1; // [XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX]:XXXXX |
| 52 | |
| 53 | inline constexpr auto NETTYPE_INVALID = 0; |
| 54 | inline constexpr auto NETTYPE_IPV4 = 1 << 0; |
| 55 | inline constexpr auto NETTYPE_IPV6 = 1 << 1; |
| 56 | inline constexpr auto NETTYPE_WEBSOCKET_IPV4 = 1 << 2; |
| 57 | inline constexpr auto NETTYPE_WEBSOCKET_IPV6 = 1 << 3; |
| 58 | inline constexpr auto NETTYPE_LINK_BROADCAST = 1 << 4; |
| 59 | /** |
| 60 | * 0.7 address. This is a flag in NETADDR to avoid introducing a parameter to every networking function |
| 61 | * to differentiate between 0.6 and 0.7 connections. |
| 62 | */ |
| 63 | inline constexpr auto NETTYPE_TW7 = 1 << 5; |
| 64 | |
| 65 | inline constexpr auto NETTYPE_ALL = NETTYPE_IPV4 | NETTYPE_IPV6 | NETTYPE_WEBSOCKET_IPV4 | NETTYPE_WEBSOCKET_IPV6; |
| 66 | inline constexpr auto NETTYPE_MASK = NETTYPE_ALL | NETTYPE_LINK_BROADCAST | NETTYPE_TW7; |
| 67 | |
| 68 | /** |
| 69 | * @ingroup Network-General |
| 70 | */ |
| 71 | typedef struct NETADDR |
| 72 | { |
| 73 | unsigned int type; |
| 74 | unsigned char ip[16]; |
| 75 | unsigned short port; |
| 76 | |
| 77 | bool operator==(const NETADDR &other) const; |
| 78 | bool operator!=(const NETADDR &other) const; |
| 79 | bool operator<(const NETADDR &other) const; |
| 80 | } NETADDR; |
| 81 | |
| 82 | template<> |
| 83 | struct std::hash<NETADDR> |
| 84 | { |
| 85 | size_t operator()(const NETADDR &Addr) const noexcept; |
| 86 | }; |
| 87 | |
| 88 | /** |
| 89 | * @ingroup Network-General |
| 90 | */ |
| 91 | typedef struct NETSTATS |
| 92 | { |
| 93 | uint64_t sent_packets; |
| 94 | uint64_t sent_bytes; |
| 95 | uint64_t recv_packets; |
| 96 | uint64_t recv_bytes; |
| 97 | } NETSTATS; |
| 98 | |
| 99 | #if defined(CONF_FAMILY_WINDOWS) |
| 100 | /** |
| 101 | * A handle for a process. |
| 102 | * |
| 103 | * @ingroup Shell |
| 104 | */ |
| 105 | typedef void *PROCESS; |
| 106 | /** |
| 107 | * A handle that denotes an invalid process. |
| 108 | * |
| 109 | * @ingroup Shell |
| 110 | */ |
| 111 | constexpr PROCESS INVALID_PROCESS = nullptr; // NOLINT(misc-misplaced-const) |
| 112 | #else |
| 113 | /** |
| 114 | * A handle for a process. |
| 115 | * |
| 116 | * @ingroup Shell |
| 117 | */ |
| 118 | typedef pid_t PROCESS; |
| 119 | /** |
| 120 | * A handle that denotes an invalid process. |
| 121 | * |
| 122 | * @ingroup Shell |
| 123 | */ |
| 124 | constexpr PROCESS INVALID_PROCESS = 0; |
| 125 | #endif |
| 126 | |
| 127 | #endif // BASE_TYPES_H |
| 128 | |