diff --git a/file/include/simdata/simdataXP.h b/file/include/simdata/simdataXP.h index 2f9fd1c..9df3bf8 100644 --- a/file/include/simdata/simdataXP.h +++ b/file/include/simdata/simdataXP.h @@ -16,16 +16,22 @@ namespace file { namespace simdata { - int scan(const std::string defaultFile, - const std::string sceneryPack, - const std::string logFile, - SimDatabase &airports); + int scan( + const std::string defaultFile, + const std::string sceneryPack, + const std::string logFile, + std::map, std::vector>> + &airports); - void makeAirport(const std::string &kind, - std::ifstream &infile, - SimDatabase &airports, - std::ofstream &logfile); - void makeGate15(std::vector &gates, + void makeAirport( + const std::string &kind, + std::ifstream &infile, + std::map, std::vector>> + &airports, + std::ofstream &logfile); + void makeGate15(std::vector &gates, const std::vector &fields); void makeRunway(std::vector &runways, const std::vector &fields); diff --git a/file/simdataXP.cpp b/file/simdataXP.cpp index ea9f5e1..561eb7c 100644 --- a/file/simdataXP.cpp +++ b/file/simdataXP.cpp @@ -6,10 +6,13 @@ namespace file { namespace simdata { - int scan(const std::string defaultFile, - const std::string sceneryPack, - const std::string logFile, - SimDatabase &database) + int scan( + const std::string defaultFile, + const std::string sceneryPack, + const std::string logFile, + std::map, std::vector>> + &airports) { std::ifstream base(defaultFile); if (!base.good()) { @@ -29,7 +32,7 @@ namespace file // Default logfile << " " << defaultFile << std::endl; - makeAirport("DEFAULT", base, database, logfile); + makeAirport("DEFAULT", base, airports, logfile); base.close(); std::string line; @@ -49,7 +52,7 @@ namespace file std::ifstream pack(path); if (pack.good()) { logfile << " " << path << std::endl; - makeAirport("CUSTOM", pack, database, logfile); + makeAirport("CUSTOM", pack, airports, logfile); pack.close(); } else { pack.close(); @@ -59,18 +62,20 @@ namespace file } logfile << std::endl - << " Total airports: " << database.numAirports() - << std::endl; + << " Total airports: " << airports.size() << std::endl; custom.close(); logfile.close(); return 0; } - void makeAirport(const std::string &kind, - std::ifstream &infile, - SimDatabase &database, - std::ofstream &logfile) + void makeAirport( + const std::string &kind, + std::ifstream &infile, + std::map, std::vector>> + &airports, + std::ofstream &logfile) { std::string line; std::string *currentIcao = nullptr; @@ -93,7 +98,7 @@ namespace file // Write to file if ICAO is valid, and we have gates and runways if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) { - database.addAirport(*currentIcao, tmpGates, tmpRunways); + airports[*currentIcao] = {tmpGates, tmpRunways}; validCount += 1; logfile << "\t " << *currentIcao << " committed" << std::endl; @@ -113,7 +118,7 @@ namespace file // Write to file if ICAO is valid, and we have gates and runways if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) { - database.addAirport(*currentIcao, tmpGates, tmpRunways); + airports[*currentIcao] = {tmpGates, tmpRunways}; validCount += 1; logfile << "\t " << *currentIcao << " committed" << std::endl; @@ -135,7 +140,7 @@ namespace file } if (currentIcao != nullptr && !tmpRunways.empty() && !tmpGates.empty()) { - database.addAirport(*currentIcao, tmpGates, tmpRunways); + airports[*currentIcao] = {tmpGates, tmpRunways}; validCount += 1; logfile << "\t " << *currentIcao << " committed" << std::endl; } diff --git a/xplugin/main.cpp b/xplugin/main.cpp index 382b987..d3b8398 100644 --- a/xplugin/main.cpp +++ b/xplugin/main.cpp @@ -116,10 +116,11 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc) try { connector = std::make_unique( - "wss://ws.hofmannnet.myhome-server.de:8000", + "ss://ws.hofmannnet.myhome-server.de:8000", configuration->getUser(), toLog); } catch (const std::invalid_argument &e) { + toLog("SOCK"); toLog(e.what()); return 0; } @@ -146,9 +147,55 @@ PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc) ap2.first.size() == 0 ? toLog(" SUCCESS") : toLog(" ERROR"); } - delete connector.release(); - delete database.release(); - delete configuration.release(); + // Thread for sending data to websocket + serverThread = std::thread(&serverWorker); + recordingThread = std::thread(&recordingWorker); + toLog("Workers started"); + + toLog("Logbook Test"); + germanairlinesva::file::logbook::Logbook logbook; + logbook.addEntry("08.09.2022", + "1000", + "L049", + "D-ALFA", + "John F. Kennedy International Aiport / EDDF", + "A1", + "14L", + "Gander International Airport / CYQX", + "10", + "03", + "10:00", + "10:20", + "13:20", + "13:30", + 210.5, + 20.1, + 5012.4156, + 8.87, + 5041.3856, + 7.1, + 971.14, + 2.41, + 980.65, + -165.23, + 1, + 1.2012, + "2022-09-08_VGA1000", + 5.5, + 1); + logbook.toFile(); + + return 1; +} + +PLUGIN_API void XPluginStop(void) +{ + /* Flight Loop */ + XPLMUnregisterFlightLoopCallback(flightLoop, nullptr); + /* End threads */ + wantsExit = true; + serverThread.join(); + recordingThread.join(); delete connector.release(); delete database.release();