unilink  0.4.3
A simple C++ library for unified async communication
platform.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2025 Jinwoo Sung
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <string>
20 
21 #include "visibility.hpp"
22 
23 #if !defined(UNILINK_PLATFORM_WINDOWS) && defined(_WIN32)
24 #define UNILINK_PLATFORM_WINDOWS 1
25 #endif
26 
27 #if !defined(UNILINK_ARCH_X64) && !defined(UNILINK_ARCH_X86) && !defined(UNILINK_ARCH_ARM64)
28 #if defined(_M_ARM64) || defined(__aarch64__)
29 #define UNILINK_ARCH_ARM64 1
30 #elif defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__amd64__)
31 #define UNILINK_ARCH_X64 1
32 #elif defined(_M_IX86) || defined(__i386__)
33 #define UNILINK_ARCH_X86 1
34 #endif
35 #endif
36 
37 #if defined(UNILINK_PLATFORM_WINDOWS)
38 #if !defined(_AMD64_) && (defined(_M_AMD64) || defined(_M_X64))
39 #define _AMD64_ 1
40 #endif
41 #if !defined(_X86_) && defined(_M_IX86)
42 #define _X86_ 1
43 #endif
44 #if !defined(_ARM64_) && defined(_M_ARM64)
45 #define _ARM64_ 1
46 #endif
47 #ifndef BOOST_ASIO_DISABLE_WINDOWS_OBJECT_HANDLE
48 #define BOOST_ASIO_DISABLE_WINDOWS_OBJECT_HANDLE
49 #endif
50 #ifndef NOMINMAX
51 #define NOMINMAX
52 #endif
53 #ifndef WIN32_LEAN_AND_MEAN
54 #define WIN32_LEAN_AND_MEAN
55 #endif
56 #include <threadpoolapiset.h>
57 #include <windows.h>
58 #include <winsock2.h>
59 #include <ws2tcpip.h>
60 
61 // Ensure fundamental Windows callback aliases exist even when lean headers are
62 // used. Some SDK combinations omit these when WIN32_LEAN_AND_MEAN is defined.
63 #ifndef CALLBACK
64 #define CALLBACK __stdcall
65 #endif
66 #ifdef BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE
67 #undef BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE
68 #endif
69 #ifndef VOID
70 typedef void VOID;
71 #endif
72 #ifndef PVOID
73 typedef void* PVOID;
74 #endif
75 #ifndef BOOLEAN
76 typedef unsigned char BOOLEAN;
77 #endif
78 #endif // defined(UNILINK_PLATFORM_WINDOWS)
79 
80 namespace unilink {
81 namespace base {
82 
87 // Platform detection macros (set by CMake or inferred from compiler)
88 #if defined(UNILINK_PLATFORM_WINDOWS)
89 #define UNILINK_FEATURE_LEVEL 3 // Windows matches standard feature set
90 #elif defined(UNILINK_PLATFORM_MACOS) || defined(__APPLE__)
91 #define UNILINK_PLATFORM_MACOS 1
92 #define UNILINK_FEATURE_LEVEL 3 // macOS matches standard feature set
93 #elif defined(UNILINK_PLATFORM_POSIX)
94 #define UNILINK_FEATURE_LEVEL 3
95 #else
96 #define UNILINK_FEATURE_LEVEL 3 // Default to standard
97 #endif
98 
99 // Feature availability macros
100 #define UNILINK_ENABLE_ADVANCED_LOGGING (UNILINK_FEATURE_LEVEL >= 2)
101 #define UNILINK_ENABLE_PERFORMANCE_MONITORING (UNILINK_FEATURE_LEVEL >= 2)
102 #define UNILINK_ENABLE_LATEST_OPTIMIZATIONS (UNILINK_FEATURE_LEVEL >= 3)
103 #define UNILINK_ENABLE_EXPERIMENTAL_FEATURES (UNILINK_FEATURE_LEVEL >= 3)
104 
109  public:
114  static int get_feature_level() { return UNILINK_FEATURE_LEVEL; }
115 
120  static std::string get_platform_description() {
121 #if defined(UNILINK_PLATFORM_WINDOWS)
122  return "Windows (Full Features)";
123 #elif defined(UNILINK_PLATFORM_MACOS)
124  return "macOS (Full Features)";
125 #elif defined(UNILINK_PLATFORM_POSIX)
126  return "POSIX Platform (Full Features)";
127 #else
128  return "Unknown Platform";
129 #endif
130  }
131 
137 
143 
149 
155 
160  static std::string get_support_warning() { return ""; }
161 };
162 
163 } // namespace base
164 
165 // Compatibility alias while transitioning from legacy `common` namespace.
166 namespace common {
168 } // namespace common
169 } // namespace unilink
#define UNILINK_ENABLE_EXPERIMENTAL_FEATURES
Definition: platform.hpp:103
#define UNILINK_ENABLE_PERFORMANCE_MONITORING
Definition: platform.hpp:101
#define UNILINK_FEATURE_LEVEL
Platform detection and feature availability.
Definition: platform.hpp:96
#define UNILINK_ENABLE_LATEST_OPTIMIZATIONS
Definition: platform.hpp:102
#define UNILINK_ENABLE_ADVANCED_LOGGING
Definition: platform.hpp:100
#define UNILINK_API
Definition: visibility.hpp:37