Fix Database

Add WS Header
This commit is contained in:
Kilian Hofmann 2022-10-22 01:42:23 +02:00
parent c214d473e2
commit 176c43d5a6
4 changed files with 42 additions and 39 deletions

View File

@ -91,10 +91,8 @@ namespace file
in.close();
}
inline void fromFile(const char *file)
inline void fromFile(const char *path)
{
std::string path(BASE_DIRECTORY);
path.append(file);
std::ifstream in(path, std::ifstream::binary);
std::string ident = readString(in, 4);
@ -108,6 +106,39 @@ namespace file
}
}
inline void toFile(const char *path) const
{
std::ofstream out(path, std::fstream::binary);
// File Header
out.write(SIMDATABASE_HEADER, 4);
out.write("\1", 1);
// Num Airports
write<std::uint16_t>(out, airports.size());
// Airport
for (const std::pair<
const std::string,
std::pair<std::vector<Gate>, std::vector<Runway>>> &airport :
airports) {
std::string icao = airport.first;
const std::vector<Gate> gates = airport.second.first;
const std::vector<Runway> runways = airport.second.second;
// ICAO
writeString(out, icao);
// Gates
write<std::uint16_t>(out, gates.size());
for (const Gate &gate : gates) {
gate.toFile(out);
}
// Runways
write<std::uint8_t>(out, runways.size());
for (const Runway &runway : runways) {
runway.toFile(out);
}
}
out.close();
}
inline const char *resolveFilename(int simVersion) const
{
switch (simVersion) {
@ -165,41 +196,6 @@ namespace file
}
}
inline void toFile(const char *file) const
{
std::string path(BASE_DIRECTORY);
path.append(file);
std::ofstream out(path, std::fstream::binary);
// File Header
out.write(SIMDATABASE_HEADER, 4);
out.write("\1", 1);
// Num Airports
write<std::uint16_t>(out, airports.size());
// Airport
for (const std::pair<
const std::string,
std::pair<std::vector<Gate>, std::vector<Runway>>> &airport :
airports) {
std::string icao = airport.first;
const std::vector<Gate> gates = airport.second.first;
const std::vector<Runway> runways = airport.second.second;
// ICAO
writeString(out, icao);
// Gates
write<std::uint16_t>(out, gates.size());
for (const Gate &gate : gates) {
gate.toFile(out);
}
// Runways
write<std::uint8_t>(out, runways.size());
for (const Runway &runway : runways) {
runway.toFile(out);
}
}
out.close();
}
inline std::size_t getCount() const { return this->airports.size(); }
inline const std::pair<const std::vector<Gate>,

View File

@ -25,6 +25,7 @@ namespace gaconnector
this->connector =
std::make_unique<websocket::Websocket>(WEBSOCKET_ADDRESS,
this->configuration->getUser(),
this->configuration->getToken(),
this->toLog);
this->toLog("WebSocket started");

View File

@ -33,11 +33,13 @@ namespace gaconnector
ix::WebSocket *webSocket = nullptr;
std::string host;
std::string user;
std::string token;
std::function<void(const std::string)> toLog;
public:
Websocket(std::string host,
std::string user,
std::string token,
std::function<void(const std::string)> toLog);
~Websocket();
void onClientMessageCallback(const ix::WebSocketMessagePtr &msg);

View File

@ -8,8 +8,9 @@ namespace gaconnector
{
Websocket::Websocket(std::string host,
std::string user,
std::string token,
std::function<void(const std::string)> toLog)
: host(host), user(user), toLog(std::move(toLog))
: host(host), user(user), token(token), toLog(std::move(toLog))
{
#ifdef IBM
// Required on Windows
@ -17,6 +18,9 @@ namespace gaconnector
#endif
this->webSocket = new ix::WebSocket();
this->webSocket->setExtraHeaders({
{ "Authentication", "Bearer " + this->token }
});
this->webSocket->enableAutomaticReconnection();
this->webSocket->setUrl(host);
this->webSocket->setOnMessageCallback(