0.5.1
Loading...
Searching...
No Matches
AppLogic.cpp
Go to the documentation of this file.
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"
29
30#include "util/Logger.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
40int 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 flow::SetProgramRootPath(std::filesystem::current_path());
44
45 // Program configuration
46 auto failedConfigFiles = ConfigManager::FetchConfigs(argc, argv);
47
48 // Sets the output path
50
51#ifndef TESTING
52 // Initialize the logger
53 Logger logger((flow::GetOutputPath() / "instinct.log").string());
54#endif
55
56 // Log all the options
58
59 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
66
67 // Register all Node Data Types which are available to the program
69
70 AntexReader::Get().initialize();
71
72 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 if (ConfigManager::Get<bool>("nogui"))
80 {
81 LOG_INFO("Starting in No-GUI Mode");
82
83 if (ConfigManager::HasKey("load"))
84 {
87
88 bool loadSuccessful = false;
89 try
90 {
91 loadSuccessful = flow::LoadFlow(ConfigManager::Get<std::string>("load", ""));
92 }
93 catch (...)
94 {
96 LOG_ERROR("Loading flow file failed");
97 }
98 if (loadSuccessful)
99 {
100#ifdef TESTING
101 flow::ApplyWatcherCallbacks();
102#endif
103
105
106 if (ConfigManager::Get<bool>("nogui")
107 && (ConfigManager::Get<bool>("sigterm") || ConfigManager::Get<size_t>("duration")))
108 {
109 auto interruptThread = std::thread([]() {
110 if (ConfigManager::Get<bool>("nogui")
111 && ConfigManager::Get<bool>("sigterm"))
112 {
115 }
116 else if (size_t duration = ConfigManager::Get<size_t>("duration");
117 ConfigManager::Get<bool>("nogui") && duration)
118 {
119 Sleep::countDownSeconds(duration);
121 }
122 });
123 interruptThread.join();
124 }
125 else
126 {
128 }
129
130#ifdef TESTING
131 TESTS::runGeneralFlowCleanupChecks();
132 flow::CallCleanupCallback();
133#endif
134
137 }
138 else
139 {
140 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", ""));
159 {
160 app.frameCountNavigate = ImGui::GetFrameCount();
161 }
162 else
163 {
167 }
168 }
169
170 return app.Run();
171 }
172
173 LOG_CRITICAL("Could not create the window");
174 }
175
176 return EXIT_SUCCESS;
177}
ANTEX file reader.
Application logic.
Config management for the Project.
Flow Executor Thread.
Save/Load the Nodes.
Utility class for logging to console and file.
#define LOG_CRITICAL(...)
Critical Event, which causes the program to work entirely and throws an exception.
Definition Logger.hpp:75
#define LOG_ERROR
Error occurred, which stops part of the program to work, but not everything.
Definition Logger.hpp:73
#define LOG_WARN
Error occurred, but a fallback option exists and program continues to work normally.
Definition Logger.hpp:71
#define LOG_INFO
Info to the user on the state of the program.
Definition Logger.hpp:69
Utility class which specifies available nodes.
Class to catch system signals and sleep.
Keeps track of the current real/simulation time.
Utility class for logging.
Definition Logger.hpp:88
static AntexReader & Get()
Get the static Instance of the reader.
Application class providing all relevant GUI callbacks.
static bool showFlowWhenInvokingCallbacks
Flag if invokeCallbacks triggers a GUI Flow event.
static bool showFlowWhenNotifyingValueChange
Flag if notifyOutputValueChanged & notifyInputValueChanged triggers a GUI Flow event.
int frameCountNavigate
Frame counter to block the navigate to content function till nodes are correctly loaded.
int processCommandLineArguments(int argc, const char *argv[])
Processes the command line arguments.
Definition AppLogic.cpp:40
void CheckOptions(const int argc, const char *argv[])
Writes all command line options into the log.
const T & Get(const std::string &key, const T &&defaultValue)
Retrieves the value of a corresponding key from the configuration, if one exists.
bool HasKey(const std::string &key)
Checks if a corresponding key exists in the configuration.
std::vector< std::string > FetchConfigs(const int argc, const char *argv[])
Fetches the configs from the command line parameters.
void start()
Starts the Thread.
void waitForFinish()
Waits for a thread to finish its execution.
void stop()
Stops the Thread.
void RegisterNodeDataTypes()
Register all available NodeData types for the program.
void RegisterNodeTypes()
Register all available Node types for the program.
void countDownSeconds(size_t seconds)
Wait the thread till time passes.
Definition Sleep.cpp:86
void waitForSignal(bool showText=false)
Wait the thread till sigusr signal is send.
Definition Sleep.cpp:59
void SetProgramRootPath(const std::filesystem::path &newRootPath)
Set the program root path.
void SetCurrentFilename(const std::string &newFilename)
Set the current filename of the open flow.
bool LoadFlow(const std::string &filepath)
Loads the flow from the specified file.
void DisableAllCallbacks()
Disables all Node callbacks.
std::filesystem::path GetOutputPath()
Get the path where logs and outputs are stored.
void DeleteAllNodes()
Delete all nodes.
void DiscardChanges()
Discards the unsaved changes flag. Does not really discard the changes.
void SetOutputPath()
Set the path where logs and outputs are stored.