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