0.4.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
31namespace nm = NAV::NodeManager;
32
33#include "util/Logger.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
43int 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 NAV::flow::SetProgramRootPath(std::filesystem::current_path());
47
48 // Program configuration
49 auto failedConfigFiles = NAV::ConfigManager::FetchConfigs(argc, argv);
50
51 // Sets the output path
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
61
62 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
69
70 // Register all Node Data Types which are available to the program
72
74
75 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
83 {
84 LOG_INFO("Starting in No-GUI Mode");
85
87 {
90
91 bool loadSuccessful = false;
92 try
93 {
95 }
96 catch (...)
97 {
99 LOG_ERROR("Loading flow file failed");
100 }
101 if (loadSuccessful)
102 {
103#ifdef TESTING
104 nm::ApplyWatcherCallbacks();
105#endif
106
108
111 {
112 auto interruptThread = std::thread([]() {
114 && NAV::ConfigManager::Get<bool>("sigterm"))
115 {
118 }
119 else if (size_t duration = NAV::ConfigManager::Get<size_t>("duration");
120 NAV::ConfigManager::Get<bool>("nogui") && duration)
121 {
124 }
125 });
126 interruptThread.join();
127 }
128 else
129 {
131 }
132
133#ifdef TESTING
134 TESTS::runGeneralFlowCleanupChecks();
135 nm::CallCleanupCallback();
136#endif
137
140 }
141 else
142 {
143 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", ""));
162 {
163 app.frameCountNavigate = ImGui::GetFrameCount();
164 }
165 else
166 {
170 }
171 }
172
173 return app.Run();
174 }
175
176 LOG_CRITICAL("Could not create the window");
177 }
178
179 return EXIT_SUCCESS;
180}
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
Manages all Nodes.
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.
void initialize()
Initialize from ANTEX file.
Application class providing all relevant GUI callbacks.
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:43
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.
bool showFlowWhenNotifyingValueChange
Flag if notifyOutputValueChanged & notifyInputValueChanged triggers a GUI Flow event.
void DisableAllCallbacks()
Disables all Node callbacks.
void DeleteAllNodes()
Delete all nodes.
bool showFlowWhenInvokingCallbacks
Flag if invokeCallbacks triggers a GUI Flow event.
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.
std::filesystem::path GetOutputPath()
Get the path where logs and outputs are stored.
void DiscardChanges()
Discards the unsaved changes flag. Does not really discard the changes.
void SetOutputPath()
Set the path where logs and outputs are stored.