GCC Code Coverage Report


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