Fix Database
Add WS Header
This commit is contained in:
parent
c214d473e2
commit
176c43d5a6
@ -91,10 +91,8 @@ namespace file
|
|||||||
in.close();
|
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::ifstream in(path, std::ifstream::binary);
|
||||||
|
|
||||||
std::string ident = readString(in, 4);
|
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
|
inline const char *resolveFilename(int simVersion) const
|
||||||
{
|
{
|
||||||
switch (simVersion) {
|
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 std::size_t getCount() const { return this->airports.size(); }
|
||||||
|
|
||||||
inline const std::pair<const std::vector<Gate>,
|
inline const std::pair<const std::vector<Gate>,
|
||||||
|
|||||||
@ -25,6 +25,7 @@ namespace gaconnector
|
|||||||
this->connector =
|
this->connector =
|
||||||
std::make_unique<websocket::Websocket>(WEBSOCKET_ADDRESS,
|
std::make_unique<websocket::Websocket>(WEBSOCKET_ADDRESS,
|
||||||
this->configuration->getUser(),
|
this->configuration->getUser(),
|
||||||
|
this->configuration->getToken(),
|
||||||
this->toLog);
|
this->toLog);
|
||||||
this->toLog("WebSocket started");
|
this->toLog("WebSocket started");
|
||||||
|
|
||||||
|
|||||||
@ -33,11 +33,13 @@ namespace gaconnector
|
|||||||
ix::WebSocket *webSocket = nullptr;
|
ix::WebSocket *webSocket = nullptr;
|
||||||
std::string host;
|
std::string host;
|
||||||
std::string user;
|
std::string user;
|
||||||
|
std::string token;
|
||||||
std::function<void(const std::string)> toLog;
|
std::function<void(const std::string)> toLog;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Websocket(std::string host,
|
Websocket(std::string host,
|
||||||
std::string user,
|
std::string user,
|
||||||
|
std::string token,
|
||||||
std::function<void(const std::string)> toLog);
|
std::function<void(const std::string)> toLog);
|
||||||
~Websocket();
|
~Websocket();
|
||||||
void onClientMessageCallback(const ix::WebSocketMessagePtr &msg);
|
void onClientMessageCallback(const ix::WebSocketMessagePtr &msg);
|
||||||
|
|||||||
@ -8,8 +8,9 @@ namespace gaconnector
|
|||||||
{
|
{
|
||||||
Websocket::Websocket(std::string host,
|
Websocket::Websocket(std::string host,
|
||||||
std::string user,
|
std::string user,
|
||||||
|
std::string token,
|
||||||
std::function<void(const std::string)> toLog)
|
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
|
#ifdef IBM
|
||||||
// Required on Windows
|
// Required on Windows
|
||||||
@ -17,6 +18,9 @@ namespace gaconnector
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
this->webSocket = new ix::WebSocket();
|
this->webSocket = new ix::WebSocket();
|
||||||
|
this->webSocket->setExtraHeaders({
|
||||||
|
{ "Authentication", "Bearer " + this->token }
|
||||||
|
});
|
||||||
this->webSocket->enableAutomaticReconnection();
|
this->webSocket->enableAutomaticReconnection();
|
||||||
this->webSocket->setUrl(host);
|
this->webSocket->setUrl(host);
|
||||||
this->webSocket->setOnMessageCallback(
|
this->webSocket->setOnMessageCallback(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user