INSTINCT Code Coverage Report


Directory: src/
File: internal/AppLogic.cpp
Date: 2025-02-07 16:54:41
Exec Total Coverage
Lines: 30 62 48.4%
Functions: 1 2 50.0%
Branches: 47 240 19.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 #include <filesystem>
12 #include <chrono>
13
14 #include "NodeRegistry.hpp"
15 #include "Navigation/GNSS/Positioning/AntexReader.hpp"
16 #include "internal/gui/NodeEditorApplication.hpp"
17 #include "internal/ConfigManager.hpp"
18 #include "internal/FlowManager.hpp"
19 #include "internal/FlowExecutor.hpp"
20
21 #include "internal/NodeManager.hpp"
22 namespace nm = NAV::NodeManager;
23
24 #include "util/Logger.hpp"
25 #include "util/Time/TimeBase.hpp"
26 #include "Sleep.hpp"
27
28 #ifdef TESTING
29 #include "FlowTester.hpp"
30 #endif
31
32 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))
33
34 112 int NAV::AppLogic::processCommandLineArguments(int argc, const char* argv[]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
35 {
36 // Save the root path of the program
37
2/4
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 112 times.
✗ Branch 5 not taken.
112 NAV::flow::SetProgramRootPath(std::filesystem::current_path());
38
39 // Program configuration
40
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 auto failedConfigFiles = NAV::ConfigManager::FetchConfigs(argc, argv);
41
42 // Sets the output path
43
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 NAV::flow::SetOutputPath();
44
45 #ifndef TESTING
46 // Initialize the logger
47 Logger logger((NAV::flow::GetOutputPath() / "instinct.log").string());
48 #endif
49
50 // Log all the options
51
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 NAV::ConfigManager::CheckOptions(argc, argv);
52
53
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 112 times.
112 for ([[maybe_unused]] const auto& configFile : failedConfigFiles)
54 {
55 LOG_ERROR("Could not open the config file: {}", configFile);
56 }
57
58 // Register all Node Types which are available to the program
59
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 NAV::NodeRegistry::RegisterNodeTypes();
60
61 // Register all Node Data Types which are available to the program
62
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 NAV::NodeRegistry::RegisterNodeDataTypes();
63
64
1/2
✓ Branch 2 taken 112 times.
✗ Branch 3 not taken.
112 NAV::AntexReader::Get().initialize();
65
66
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 util::time::SetCurrentTimeToComputerTime();
67
68 if (sizeof(long double) != 16)
69 {
70 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.");
71 }
72
73
3/6
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 112 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 112 times.
✗ Branch 8 not taken.
224 if (NAV::ConfigManager::Get<bool>("nogui"))
74 {
75
2/4
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 112 times.
✗ Branch 7 not taken.
224 LOG_INFO("Starting in No-GUI Mode");
76
77
3/6
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 112 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 112 times.
✗ Branch 8 not taken.
224 if (NAV::ConfigManager::HasKey("load"))
78 {
79 112 nm::showFlowWhenInvokingCallbacks = false;
80 112 nm::showFlowWhenNotifyingValueChange = false;
81
82 112 bool loadSuccessful = false;
83 try
84 {
85
4/8
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 112 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 112 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 112 times.
✗ Branch 11 not taken.
448 loadSuccessful = NAV::flow::LoadFlow(NAV::ConfigManager::Get<std::string>("load", ""));
86 }
87 catch (...)
88 {
89 nm::DeleteAllNodes();
90 LOG_ERROR("Loading flow file failed");
91 }
92
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 1 times.
112 if (loadSuccessful)
93 {
94 #ifdef TESTING
95
1/2
✓ Branch 1 taken 111 times.
✗ Branch 2 not taken.
111 nm::ApplyWatcherCallbacks();
96 #endif
97
98
1/2
✓ Branch 1 taken 111 times.
✗ Branch 2 not taken.
111 NAV::FlowExecutor::start();
99
100
3/10
✓ Branch 1 taken 111 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 111 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 111 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
333 if (NAV::ConfigManager::Get<bool>("nogui")
101
13/34
✓ Branch 1 taken 111 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 111 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 111 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 111 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 111 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 111 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 111 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 111 times.
✓ Branch 21 taken 111 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 111 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 111 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 111 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 111 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.
666 && (NAV::ConfigManager::Get<bool>("sigterm") || NAV::ConfigManager::Get<size_t>("duration")))
102 {
103 auto interruptThread = std::thread([]() {
104 if (NAV::ConfigManager::Get<bool>("nogui")
105 && NAV::ConfigManager::Get<bool>("sigterm"))
106 {
107 NAV::Sleep::waitForSignal(true);
108 NAV::FlowExecutor::stop();
109 }
110 else if (size_t duration = NAV::ConfigManager::Get<size_t>("duration");
111 NAV::ConfigManager::Get<bool>("nogui") && duration)
112 {
113 NAV::Sleep::countDownSeconds(duration);
114 NAV::FlowExecutor::stop();
115 }
116 });
117 interruptThread.join();
118 }
119 else
120 {
121
1/2
✓ Branch 1 taken 111 times.
✗ Branch 2 not taken.
111 NAV::FlowExecutor::waitForFinish();
122 }
123
124 #ifdef TESTING
125
1/2
✓ Branch 1 taken 111 times.
✗ Branch 2 not taken.
111 TESTS::runGeneralFlowCleanupChecks();
126
1/2
✓ Branch 1 taken 111 times.
✗ Branch 2 not taken.
111 nm::CallCleanupCallback();
127 #endif
128
129
1/2
✓ Branch 1 taken 111 times.
✗ Branch 2 not taken.
111 nm::DisableAllCallbacks();
130
1/2
✓ Branch 1 taken 111 times.
✗ Branch 2 not taken.
111 nm::DeleteAllNodes();
131 }
132 else
133 {
134 1 return EXIT_FAILURE;
135 }
136 }
137 else
138 {
139 LOG_CRITICAL("When running in No-GUI Mode you have to specify a flow file to load (-l)");
140 }
141 }
142 else
143 {
144 LOG_INFO("Starting the GUI");
145 NAV::gui::NodeEditorApplication app("INSTINCT - INS Toolkit for Integrated Navigation Concepts and Training", "INSTINCT.ini", argc, argv);
146
147 if (app.Create())
148 {
149 if (NAV::ConfigManager::HasKey("load"))
150 {
151 LOG_INFO("Loading flow file: {}", NAV::ConfigManager::Get<std::string>("load", ""));
152 if (NAV::flow::LoadFlow(NAV::ConfigManager::Get<std::string>("load", "")))
153 {
154 app.frameCountNavigate = ImGui::GetFrameCount();
155 }
156 else
157 {
158 nm::DeleteAllNodes();
159 NAV::flow::DiscardChanges();
160 NAV::flow::SetCurrentFilename("");
161 }
162 }
163
164 return app.Run();
165 }
166
167 LOG_CRITICAL("Could not create the window");
168 }
169
170 111 return EXIT_SUCCESS;
171 112 }
172