GCC Code Coverage Report


Directory: src/gate/
File: src/gate/gatemain.h
Date: 2026-05-04 21:11:01
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 /** @file
30 * @brief Abstraction utilities for system specific component entrypoints
31 * @ingroup gatecore
32 */
33
34
35
36 /** @mainpage Introduction
37 *
38 * \section section_preamble Preamble
39 *
40 * The GATE project is a C based library framework that shall provide
41 * platform-independent implementations of lower-level auxiliary functions.
42 * While most C libraries are only targeting Windows and Linux platforms,
43 * GATE code is designed to run within other operating systems with no or
44 * limited C standard library implementation.
45 *
46 * The GATE C++ libraries are a thin layer of C++ classes around the C based
47 * implementation to simplify usage of lower-level C functions. Using a C
48 * API within C++ code allows code sharing of C++ logic between incompatible
49 * compilers (e.g. MSVC++ and g++).
50 *
51 * GATE is also an interface study where I add all kinds of features I was
52 * missing in Win32 or POSIX like:
53 *
54 * - C-based object interfaces
55 * - unified streaming
56 * - coroutines
57 * - delegates
58 * - data containers, fields and dictionaries
59 *
60 * \section section_platforms Supported platforms
61 *
62 * - Windows API beginning with NT4
63 * - Windows CE (CE 5+)
64 * - Windows RT (experimental)
65 * - POSIX
66 * - Linux (GLIBC, MUSL-LIBC)
67 * - BSD (NetBSD, FreeBSD, OpenBSD)
68 * - Android (experimental)
69 * - FreeRTOS (experimental)
70 * - UEFI Bootservices (experimental)
71 * - DOS (experimental)
72 * - WebAssembly-Emscripten (experimental)
73 *
74 * GATE libraries are designed with the concept of mandatory and optional
75 * features. Mandatory features are available on all platforms and are only
76 * depending on memory allocation support. Everything else that needs
77 * operating system support (or a native platform implementation) is only
78 * provided, if the platform supports it.
79 * GATE ensures that the entry points are available on all platforms, but
80 * they will return a NOT_IMPLEMENTED error at runtime when they are used.
81 * This allows application to compile function calls also on platform where
82 * they are not completely implemented.
83 *
84 * This feature was a main goal to overcome problems I found with other
85 * libraries that still could not be compiled on a target platform due to
86 * a single function that I never wanted to invoke.
87 *
88 * \section section_compilers Supported compilers
89 *
90 * - MSVC
91 * - GCC
92 * - CLANG
93 * - WATCOM
94 */
95
96 #ifndef GATE_MAIN_H_INCLUDED
97 #define GATE_MAIN_H_INCLUDED
98
99 #include "gate/gate_core_api.h"
100 #include "gate/gatemaindefs.h"
101
102
103 #if defined(__cplusplus)
104 # define GATE_MAIN_EXTERNC extern "C"
105 #else
106 # define GATE_MAIN_EXTERNC
107 #endif
108
109 GATE_MAIN_EXTERNC GATE_CORE_API int GATE_CALL gate_main_stdc_entry(gate_main_func main_func, int argc, char* argv[]);
110
111 #if defined(GATE_MAIN_WINAPI_IMPL)
112
113 #if defined(GATE_SYS_WINCE) || defined(GATE_SYS_WIN16)
114 # include <windows.h>
115 # define GATE_MAIN_NATIVE_HEADER_INCLUDED 1
116 #endif
117
118 GATE_MAIN_EXTERNC GATE_CORE_API int GATE_CALL gate_main_wchar_entry(gate_main_func main_func, int argc, wchar_t* argv[], wchar_t* envp[]);
119 GATE_MAIN_EXTERNC GATE_CORE_API int GATE_CALL gate_main_winapi_entry(gate_main_func main_func, void* hInstance, void* hPrevInstance, void* lpCmdLine, int nShowCmd);
120
121 #if defined(GATE_MAIN_NATIVE_HEADER_INCLUDED)
122 # define GATE_WINMAIN_API WINAPI
123 #else
124 # if defined(GATE_SYS_WIN16)
125 # define GATE_WINMAIN_API __pascal
126 # else
127 # define GATE_WINMAIN_API __stdcall
128 # endif
129 #endif
130
131 #if defined(GATE_SYS_WINCE)
132 # if defined(GATE_MAIN_NATIVE_HEADER_INCLUDED)
133 # define WINMAIN_STR LPWSTR
134 # else
135 # define WINMAIN_STR wchar_t*
136 # endif
137 #else
138 # if defined(GATE_MAIN_NATIVE_HEADER_INCLUDED)
139 # define WINMAIN_STR LPSTR
140 # else
141 # define WINMAIN_STR char*
142 # endif
143 #endif
144
145 #if defined(GATE_APP_TYPE_UI) || defined(GATE_SYS_WIN16)
146 #if defined(GATE_MAIN_NATIVE_HEADER_INCLUDED)
147 int GATE_WINMAIN_API WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, WINMAIN_STR lpCmdLine, int nShowCmd)
148 #else
149 int GATE_WINMAIN_API WinMain(void* hInstance, void* hPrevInstance, void* lpCmdLine, int nShowCmd)
150 #endif
151 {
152 return gate_main_winapi_entry(&gate_main, (void*)hInstance, (void*)hPrevInstance, lpCmdLine, nShowCmd);
153 }
154 #endif
155
156 #if !defined(GATE_COMPILER_WATCOM) && !defined(GATE_COMPILER_TCC) && (!defined(GATE_APP_TYPE_UI) || defined(GATE_SYS_WINCE))
157 int wmain(int argc, wchar_t* argv[], wchar_t* envp[])
158 {
159 return gate_main_wchar_entry(&gate_main, argc, argv, envp);
160 }
161 #endif /* !GATE_COMPILER_WATCOM && !GATE_COMPILER_TCC && !GATE_APP_TYPE_UI */
162
163 #if defined(GATE_APP_TYPE_UI) && !defined(GATE_MAIN_NO_STDC_IMPL) && !defined(GATE_COMPILER_GCC)
164 # define GATE_MAIN_NO_STDC_IMPL 1
165 #endif
166
167
168 #endif /* GATE_MAIN_WINAPI_IMPL */
169
170
171 #if defined(GATE_MAIN_ANDROID_IMPL)
172 # include <android/native_activity.h>
173
174 GATE_MAIN_EXTERNC GATE_CORE_API void gate_main_android_entry(gate_main_func main_func, void* activity, void* savedState, size_t savedStateSize);
175
176 void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_t savedStateSize)
177 {
178 gate_main_android_entry(&gate_main, activity, savedState, savedStateSize);
179 }
180 #endif /* GATE_MAIN_ANDROID_IMPL */
181
182
183 #if defined(GATE_MAIN_ARDUINO_IMPL)
184
185 GATE_MAIN_EXTERNC GATE_CORE_API void gate_main_arduino_setup(void);
186 GATE_MAIN_EXTERNC GATE_CORE_API void gate_main_arduino_loop(void);
187
188 GATE_MAIN_EXTERNC void setup(void)
189 {
190 gate_main_arduino_setup();
191 }
192 GATE_MAIN_EXTERNC void loop(void)
193 {
194 gate_main_arduino_loop();
195 }
196
197 #endif /* GATE_MAIN_ARDUINO_IMPL */
198
199
200 #if !defined(GATE_MAIN_NO_STDC_IMPL)
201 34 int main(int argc, char* argv[], char* envp[])
202 {
203 (void)envp;
204 34 return gate_main_stdc_entry(&gate_main, argc, argv);
205 }
206
207 #endif /* GATE_MAIN_NO_STDC */
208
209 #endif /* GATE_MAIN_H_INCLUDED */
210