INSTINCT Code Coverage Report


Directory: src/
File: internal/AppLogic.cpp
Date: 2025-11-25 23:34:18
Exec Total Coverage
Lines: 39 62 62.9%
Functions: 2 2 100.0%
Branches: 71 240 29.6%

Line Branch Exec Source
1 // This file is part of INSTINCT, the INS Toolkit for Integrated
2 // Navigation Concepts and Training by the Institute of Navigation of
3 // the University of Stuttgart, Germany.
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9 #include "AppLogic.hpp"
10
11 // <boost/asio.hpp> needs to be included before <winsock.h> (even though not used in this file)
12 // https://stackoverflow.com/questions/9750344/boostasio-winsock-and-winsock-2-compatibility-issue
13 #ifdef _WIN32
14 // Set the proper SDK version before including boost/Asio
15 #include <SDKDDKVer.h>
16 // Note boost/ASIO includes Windows.h.
17 #include <boost/asio.hpp>
18 #endif //_WIN32
19
20 #include <filesystem>
21 #include <chrono>
22
23 #include "NodeRegistry.hpp"
24 #include "Navigation/GNSS/Positioning/AntexReader.hpp"
25 #include "internal/gui/NodeEditorApplication.hpp"
26 #include "internal/ConfigManager.hpp"
27 #include "internal/FlowManager.hpp"
28 #include "internal/FlowExecutor.hpp"
29
30 #include "util/Logger.hpp"
31 #include "util/Time/TimeBase.hpp"
32 #include "Sleep.hpp"
33
34 #ifdef TESTING
35 #include "FlowTester.hpp"
36 #endif
37
38 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))
39
40 114 int NAV::AppLogic::processCommandLineArguments(int argc, const char* argv[]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
41 {
42 // Save the root path of the program
43
2/4
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 114 times.
✗ Branch 5 not taken.
114 flow::SetProgramRootPath(std::filesystem::current_path());
44
45 // Program configuration
46
1/2
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
114 auto failedConfigFiles = ConfigManager::FetchConfigs(argc, argv);
47
48 // Sets the output path
49
1/2
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
114 flow::SetOutputPath();
50
51 #ifndef TESTING
52 // Initialize the logger
53 Logger logger((flow::GetOutputPath() / "instinct.log").string());
54 #endif
55
56 // Log all the options
57
1/2
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
114 ConfigManager::CheckOptions(argc, argv);
58
59
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 114 times.
114 for ([[maybe_unused]] const auto& configFile : failedConfigFiles)
60 {
61 LOG_ERROR("Could not open the config file: {}", configFile);
62 }
63
64 // Register all Node Types which are available to the program
65
1/2
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
114 NodeRegistry::RegisterNodeTypes();
66
67 // Register all Node Data Types which are available to the program
68
1/2
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
114 NodeRegistry::RegisterNodeDataTypes();
69
70
1/2
✓ Branch 2 taken 114 times.
✗ Branch 3 not taken.
114 AntexReader::Get().initialize();
71
72
1/2
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
114 util::time::SetCurrentTimeToComputerTime();
73
74 if (sizeof(long double) != 16)
75 {
76 LOG_WARN("You are running INSTINCT on a platform without quadruple-precision floating-point support. Functionality concerning time measurements and ranging could be affected by the precision loss.");
77 }
78
79
3/6
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 114 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 114 times.
✗ Branch 8 not taken.
228 if (ConfigManager::Get<bool>("nogui"))
80 {
81
2/4
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 114 times.
✗ Branch 7 not taken.
228 LOG_INFO("Starting in No-GUI Mode");
82
83
3/6
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 114 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 114 times.
✗ Branch 8 not taken.
228 if (ConfigManager::HasKey("load"))
84 {
85 114 gui::NodeEditorApplication::showFlowWhenInvokingCallbacks = false;
86 114 gui::NodeEditorApplication::showFlowWhenNotifyingValueChange = false;
87
88 228 bool loadSuccessful = false;
89 try
90 {
91
4/8
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 114 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 114 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 114 times.
✗ Branch 11 not taken.
456 loadSuccessful = flow::LoadFlow(ConfigManager::Get<std::string>("load", ""));
92 }
93 catch (...)
94 {
95 flow::DeleteAllNodes();
96 LOG_ERROR("Loading flow file failed");
97 }
98
2/2
✓ Branch 0 taken 113 times.
✓ Branch 1 taken 1 times.
114 if (loadSuccessful)
99 {
100 #ifdef TESTING
101
1/2
✓ Branch 1 taken 113 times.
✗ Branch 2 not taken.
113 flow::ApplyWatcherCallbacks();
102 #endif
103
104
1/2
✓ Branch 1 taken 113 times.
✗ Branch 2 not taken.
113 FlowExecutor::start();
105
106
4/10
✓ Branch 1 taken 113 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 113 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 112 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
339 if (ConfigManager::Get<bool>("nogui")
107
14/34
✓ Branch 1 taken 113 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 113 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 113 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 113 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 113 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 113 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 113 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
✓ Branch 20 taken 112 times.
✓ Branch 21 taken 113 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 113 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 113 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 113 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 113 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
678 && (ConfigManager::Get<bool>("sigterm") || ConfigManager::Get<size_t>("duration")))
108 {
109 auto interruptThread = std::thread([]() {
110
3/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
3 if (ConfigManager::Get<bool>("nogui")
111
8/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
4 && ConfigManager::Get<bool>("sigterm"))
112 {
113 Sleep::waitForSignal(true);
114 FlowExecutor::stop();
115 }
116
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 else if (size_t duration = ConfigManager::Get<size_t>("duration");
117
7/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
3 ConfigManager::Get<bool>("nogui") && duration)
118 {
119 1 Sleep::countDownSeconds(duration);
120 1 FlowExecutor::stop();
121 }
122
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 });
123
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 interruptThread.join();
124 1 }
125 else
126 {
127
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 FlowExecutor::waitForFinish();
128 }
129
130 #ifdef TESTING
131
1/2
✓ Branch 1 taken 113 times.
✗ Branch 2 not taken.
113 TESTS::runGeneralFlowCleanupChecks();
132
1/2
✓ Branch 1 taken 113 times.
✗ Branch 2 not taken.
113 flow::CallCleanupCallback();
133 #endif
134
135
1/2
✓ Branch 1 taken 113 times.
✗ Branch 2 not taken.
113 flow::DisableAllCallbacks();
136
1/2
✓ Branch 1 taken 113 times.
✗ Branch 2 not taken.
113 flow::DeleteAllNodes();
137 }
138 else
139 {
140 1 return EXIT_FAILURE;
141 }
142 }
143 else
144 {
145 LOG_CRITICAL("When running in No-GUI Mode you have to specify a flow file to load (-l)");
146 }
147 }
148 else
149 {
150 LOG_INFO("Starting the GUI");
151 gui::NodeEditorApplication app("INSTINCT - INS Toolkit for Integrated Navigation Concepts and Training", "INSTINCT.ini", argc, argv);
152
153 if (app.Create())
154 {
155 if (ConfigManager::HasKey("load"))
156 {
157 LOG_INFO("Loading flow file: {}", ConfigManager::Get<std::string>("load", ""));
158 if (flow::LoadFlow(ConfigManager::Get<std::string>("load", "")))
159 {
160 app.frameCountNavigate = ImGui::GetFrameCount();
161 }
162 else
163 {
164 flow::DeleteAllNodes();
165 flow::DiscardChanges();
166 flow::SetCurrentFilename("");
167 }
168 }
169
170 return app.Run();
171 }
172
173 LOG_CRITICAL("Could not create the window");
174 }
175
176 113 return EXIT_SUCCESS;
177 114 }
178