Consts and references

This commit is contained in:
Kilian committed 2022-09-09 20:10:38 +02:00
1 parent b050c23577
commit 699e2a4784
16 files changed
+156 -179

No files matched your search

+27 -24
View File
@@ -12,19 +12,20 @@ namespace germanairlinesva_websocket
ix::initNetSystem();
#endif
webSocket = new ix::WebSocket();
webSocket->enableAutomaticReconnection();
webSocket->setUrl(host);
webSocket->setOnMessageCallback([this](const ix::WebSocketMessagePtr &msg) {
this->onClientMessageCallback(msg);
});
webSocket->start();
this->webSocket = new ix::WebSocket();
this->webSocket->enableAutomaticReconnection();
this->webSocket->setUrl(host);
this->webSocket->setOnMessageCallback(
[this](const ix::WebSocketMessagePtr &msg) {
this->onClientMessageCallback(msg);
});
this->webSocket->start();
}
Websocket::~Websocket()
{
webSocket->stop();
toLog("WebSocket stopped");
this->webSocket->stop();
this->toLog("WebSocket stopped");
#ifdef IBM
// Required on Windows
ix::uninitNetSystem();
@@ -43,15 +44,15 @@ namespace germanairlinesva_websocket
debug_msg << it.first << ": " << it.second << std::endl;
}
toLog(debug_msg.str());
this->toLog(debug_msg.str());
webSocket->send("MASTER:" + user);
toLog("Connecting as " + user);
this->webSocket->send("MASTER:" + user);
this->toLog("Connecting as " + user);
} else if (msg->type == ix::WebSocketMessageType::Close) {
if (msg->closeInfo.reason.compare("DUPLICATE")) {
webSocket->disableAutomaticReconnection();
this->webSocket->disableAutomaticReconnection();
toLog("Disconnected due to beeing a duplicate simualtor");
this->toLog("Disconnected due to beeing a duplicate simualtor");
} else {
std::stringstream debug_msg;
@@ -60,7 +61,7 @@ namespace germanairlinesva_websocket
debug_msg << "Reason: " << msg->closeInfo.reason << std::endl;
debug_msg << "Remote: " << msg->closeInfo.remote << std::endl;
toLog(debug_msg.str());
this->toLog(debug_msg.str());
}
} else if (msg->type == ix::WebSocketMessageType::Error) {
std::stringstream debug_msg;
@@ -73,20 +74,22 @@ namespace germanairlinesva_websocket
debug_msg << "Retries: " << msg->errorInfo.retries << std::endl;
debug_msg << "Wait time: " << msg->errorInfo.wait_time << std::endl;
toLog(debug_msg.str());
this->toLog(debug_msg.str());
} else if (msg->type == ix::WebSocketMessageType::Message) {
if (!msg->str.empty()) {
toLog(msg->str);
this->toLog(msg->str);
}
}
}
void Websocket::sendData(data &d)
{
if (strcmp(d.path, lastPath) != 0) {
strcpy(lastPath, d.path);
if (germanairlinesva_util::generateMD5(d.path, lastHash, toLog)) {
strcpy(lastHash, "NOT SET");
if (strcmp(d.path, this->lastPath) != 0) {
strcpy(this->lastPath, d.path);
if (germanairlinesva_util::generateMD5(d.path,
this->lastHash,
this->toLog)) {
strcpy(this->lastHash, "NOT SET");
}
}
@@ -98,13 +101,13 @@ namespace germanairlinesva_websocket
{"truHdg", d.truHdg},
{"totFuel", d.totFuelKg},
{"fuelFlow", d.ff},
{"hash", lastHash},
{"hash", this->lastHash},
};
if (webSocket != nullptr) {
if (this->webSocket != nullptr) {
std::ostringstream msg;
msg << "SEND:" << user << ":" << json.dump();
webSocket->send(msg.str(), false);
this->webSocket->send(msg.str(), false);
}
}
} // namespace germanairlinesva_websocket