GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 7 / 0 / 7
Functions: 100.0% 1 / 0 / 1
Branches: -% 0 / 0 / 0

include/DetourModKit.hpp
Line Branch Exec Source
1 #ifndef DETOURMODKIT_HPP
2 #define DETOURMODKIT_HPP
3
4 /**
5 * @file DetourModKit.hpp
6 * @brief Central header file for DetourModKit library.
7 * @details This header provides a single include point for all DetourModKit functionality,
8 * along with convenient namespace aliases for common usage patterns.
9 * Include this header to access all DetourModKit features.
10 */
11
12 // Version information (generated by CMake)
13 #include "DetourModKit/version.hpp"
14
15 // Core functionality headers
16 #include "DetourModKit/config.hpp"
17 #include "DetourModKit/hook_manager.hpp"
18 #include "DetourModKit/input_codes.hpp"
19 #include "DetourModKit/logger.hpp"
20 #include "DetourModKit/async_logger.hpp"
21 #include "DetourModKit/input.hpp"
22
23 // Module headers
24 #include "DetourModKit/bootstrap.hpp"
25 #include "DetourModKit/event_dispatcher.hpp"
26 #include "DetourModKit/filesystem.hpp"
27 #include "DetourModKit/format.hpp"
28 #include "DetourModKit/math.hpp"
29 #include "DetourModKit/memory.hpp"
30 #include "DetourModKit/profiler.hpp"
31 #include "DetourModKit/scanner.hpp"
32 #include "DetourModKit/worker.hpp"
33
34 /**
35 * @brief Convenient namespace aliases for common DetourModKit usage patterns.
36 * @details These aliases allow for shorter, more readable code when using DetourModKit
37 * functionality extensively. Example: DMK::Logger instead of DetourModKit::Logger.
38 */
39 namespace DMK = DetourModKit;
40 namespace DMKConfig = DetourModKit::Config;
41 namespace DMKScanner = DetourModKit::Scanner;
42 namespace DMKString = DetourModKit::String;
43 namespace DMKFormat = DetourModKit::Format;
44 namespace DMKFilesystem = DetourModKit::Filesystem;
45 namespace DMKMemory = DetourModKit::Memory;
46 namespace DMKMath = DetourModKit::Math;
47 namespace DMKBootstrap = DetourModKit::Bootstrap;
48
49 #ifndef DMK_NO_SHORT_NAMES
50 /**
51 * @brief Convenient type aliases for commonly used DetourModKit types.
52 * @details These aliases provide shorter names for frequently used types.
53 * Define DMK_NO_SHORT_NAMES before including this header to disable them.
54 */
55 using DMKLogger = DetourModKit::Logger;
56 using DMKStoppableWorker = DetourModKit::StoppableWorker;
57 using DMKInputBindingGuard = DetourModKit::Config::InputBindingGuard;
58 using DMKHookManager = DetourModKit::HookManager;
59 using DMKLogLevel = DetourModKit::LogLevel;
60 using DMKHookStatus = DetourModKit::HookStatus;
61 using DMKHookType = DetourModKit::HookType;
62 using DMKHookConfig = DetourModKit::HookConfig;
63 using DMKAsyncLogger = DetourModKit::AsyncLogger;
64 using DMKAsyncLoggerConfig = DetourModKit::AsyncLoggerConfig;
65 using DMKOverflowPolicy = DetourModKit::OverflowPolicy;
66 using DMKInputManager = DetourModKit::InputManager;
67 using DMKInputPoller = DetourModKit::InputPoller;
68 using DMKInputMode = DetourModKit::InputMode;
69 using DMKInputSource = DetourModKit::InputSource;
70 using DMKInputCode = DetourModKit::InputCode;
71 using DMKKeyCombo = DetourModKit::Config::KeyCombo;
72 using DMKKeyComboList = DetourModKit::Config::KeyComboList;
73 using DMKInputBinding = DetourModKit::InputBinding;
74 using DMKProfiler = DetourModKit::Profiler;
75 using DMKScopedProfile = DetourModKit::ScopedProfile;
76 using DMKProfileSample = DetourModKit::ProfileSample;
77 #endif // DMK_NO_SHORT_NAMES
78
79 /**
80 * @brief Explicitly shuts down all DetourModKit singletons in the correct order.
81 * @details This function should be called before process exit or DLL unload to ensure
82 * proper cleanup without use-after-free errors. It shuts down singletons in
83 * reverse dependency order: InputManager, HookManager, Memory cache, Config,
84 * then Logger last. After calling this function, the singletons are in a safe
85 * state for destruction.
86 *
87 * @note This function is idempotent - calling it multiple times is safe.
88 * @note Each subsystem detects if it is running under the Windows loader lock
89 * (e.g. from DllMain/DLL_PROCESS_DETACH or FreeLibrary) and will detach
90 * background threads instead of joining them to avoid deadlock. However,
91 * calling DMK_Shutdown() before DLL_PROCESS_DETACH is still the recommended
92 * practice for a clean orderly shutdown.
93 * @note The async-logger StringPool singleton is intentionally leaked and is
94 * NOT reclaimed by this function; the OS releases the memory at process
95 * exit. See DetourModKit::StringPool for the rationale.
96 */
97 24 inline void DMK_Shutdown()
98 {
99 // Shutdown in reverse dependency order:
100 // 1. InputManager first (polling thread may invoke callbacks that log)
101 24 DetourModKit::InputManager::get_instance().shutdown();
102
103 // 2. HookManager (may have been logging via Logger)
104 24 DetourModKit::HookManager::get_instance().shutdown();
105
106 // 3. Memory cache (background cleanup thread must stop before Logger shuts down)
107 24 DetourModKit::Memory::shutdown_cache();
108
109 // 4. Clear registered config items (static vector cleanup)
110 24 DetourModKit::Config::clear_registered_items();
111
112 // 5. Logger last (no more logging after this)
113 24 DetourModKit::Logger::get_instance().shutdown();
114 24 }
115
116 #endif // DETOURMODKIT_HPP
117