Refactor SimDatabase
This commit is contained in:
1 parent
4445f1f12a
commit
2cf03d2933
15 files changed
+255
-255
No files matched your search
+19
-32
@@ -10,12 +10,9 @@ std::thread serverThread;
|
||||
std::thread recordingThread;
|
||||
std::atomic<bool> wantsExit;
|
||||
|
||||
germanairlinesva::file::config::Config configuration;
|
||||
std::map<std::string,
|
||||
std::pair<std::vector<germanairlinesva::file::simdata::Gate>,
|
||||
std::vector<germanairlinesva::file::simdata::Runway>>>
|
||||
airports;
|
||||
germanairlinesva_websocket::Websocket *connector;
|
||||
std::unique_ptr<germanairlinesva::file::config::Config> configuration;
|
||||
std::unique_ptr<germanairlinesva::file::simdata::SimDatabase> database;
|
||||
std::unique_ptr<germanairlinesva_websocket::Websocket> connector;
|
||||
int xplaneVersion;
|
||||
|
||||
/* Datarefs */
|
||||
@@ -114,52 +111,39 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
|
||||
roll = XPLMFindDataRef("sim/flightmodel/position/phi"); // FLOAT
|
||||
quaternion = XPLMFindDataRef("sim/flightmodel/position/q"); // FLOAT[4]
|
||||
|
||||
configuration = germanairlinesva::file::config::Config();
|
||||
configuration = std::make_unique<germanairlinesva::file::config::Config>();
|
||||
toLog("Config loaded");
|
||||
|
||||
try {
|
||||
connector = new germanairlinesva_websocket::Websocket(
|
||||
connector = std::make_unique<germanairlinesva_websocket::Websocket>(
|
||||
"wss://ws.hofmannnet.myhome-server.de:8000",
|
||||
configuration.getUser(),
|
||||
configuration->getUser(),
|
||||
toLog);
|
||||
} catch (const std::invalid_argument &e) {
|
||||
toLog(e.what());
|
||||
return 0;
|
||||
}
|
||||
toLog("WebSocket started");
|
||||
|
||||
char hash[2 * MD5LEN + 1] = "";
|
||||
if (germanairlinesva::util::generateMD5(XPLANE_CUSTOM_SCENERY, hash, toLog) ==
|
||||
0) {
|
||||
|
||||
if (strcmp(configuration.getScenery().c_str(), hash) != 0 ||
|
||||
!germanairlinesva::util::fileExists(
|
||||
XPLANE_PLUGIN_DIRECTORY SIMDATABASE)) {
|
||||
scan(xplaneVersion < 12000 ? XPLANE11_BASE_SCENERY
|
||||
: XPLANE12_BASE_SCENERY,
|
||||
XPLANE_CUSTOM_SCENERY,
|
||||
XPLANE_PLUGIN_DIRECTORY "log.txt",
|
||||
airports);
|
||||
germanairlinesva::file::simdata::toFile(
|
||||
airports,
|
||||
XPLANE_PLUGIN_DIRECTORY SIMDATABASE);
|
||||
|
||||
configuration.updateScenery(hash);
|
||||
toLog("Sim Database updated");
|
||||
} else {
|
||||
airports = germanairlinesva::file::simdata::fromFile(
|
||||
XPLANE_PLUGIN_DIRECTORY SIMDATABASE);
|
||||
toLog("Sim Database loaded");
|
||||
}
|
||||
database = std::make_unique<germanairlinesva::file::simdata::SimDatabase>(
|
||||
xplaneVersion,
|
||||
hash,
|
||||
configuration,
|
||||
toLog);
|
||||
|
||||
toLog("Readback test of sim database using EDDF");
|
||||
auto ap = airports["EDDF"];
|
||||
auto ap = (*database)["EDDF"];
|
||||
for (const auto &it : ap.first) {
|
||||
toLog(" " + it.to_string());
|
||||
}
|
||||
for (const auto &it : ap.second) {
|
||||
toLog(" " + it.to_string());
|
||||
}
|
||||
toLog("Readback test of sim database using XXXX");
|
||||
auto ap2 = (*database)["XXXX"];
|
||||
ap2.first.size() == 0 ? toLog(" SUCCESS") : toLog(" ERROR");
|
||||
}
|
||||
|
||||
// Thread for sending data to websocket
|
||||
@@ -209,10 +193,13 @@ PLUGIN_API void XPluginStop(void)
|
||||
XPLMUnregisterFlightLoopCallback(flightLoop, nullptr);
|
||||
/* End threads */
|
||||
wantsExit = true;
|
||||
delete connector;
|
||||
serverThread.join();
|
||||
recordingThread.join();
|
||||
|
||||
delete connector.release();
|
||||
delete database.release();
|
||||
delete configuration.release();
|
||||
|
||||
p.toFile("flight.rec");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user