mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
logging rework json/proto (#102)
* cleanup: remove ambiled device as written at the forum this is no longer supported. All people should move to adalight. They just need to flash a new sketch. * fix typo * travis.ci * travis: move to ubuntu 14.04 * script try * add serialport * update .json files * . * . * . * update travis * fix * typo * fix * . * disable v4l2 on mac * disable email notification * update osx * maybe fix * . * disable osx and rm v4l2 * try osx * try fix * travis update * add oe systemd file * Proto * Json * fix * fix2 * fix3 * . * typo * update * revert runtime error
This commit is contained in:
@@ -33,7 +33,8 @@ JsonClientConnection::JsonClientConnection(QTcpSocket *socket, Hyperion * hyperi
|
||||
_imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
||||
_hyperion(hyperion),
|
||||
_receiveBuffer(),
|
||||
_webSocketHandshakeDone(false)
|
||||
_webSocketHandshakeDone(false),
|
||||
_log(Logger::getInstance("JSONCLIENTCONNECTION"))
|
||||
{
|
||||
// connect internal signals and slots
|
||||
connect(_socket, SIGNAL(disconnected()), this, SLOT(socketClosed()));
|
||||
@@ -167,7 +168,7 @@ void JsonClientConnection::handleWebSocketFrame()
|
||||
}
|
||||
} else
|
||||
{
|
||||
std::cout << "JSONCLIENT INFO: Someone is sending very big messages over several frames... it's not supported yet" << std::endl;
|
||||
Error(_log, "Someone is sending very big messages over several frames... it's not supported yet");
|
||||
quint8 close[] = {0x88, 0};
|
||||
_socket->write((const char*)close, 2);
|
||||
_socket->flush();
|
||||
@@ -178,7 +179,7 @@ void JsonClientConnection::handleWebSocketFrame()
|
||||
void JsonClientConnection::doWebSocketHandshake()
|
||||
{
|
||||
// http header, might not be a very reliable check...
|
||||
std::cout << "Websocket handshake" << std::endl;
|
||||
Debug(_log, "Websocket handshake");
|
||||
|
||||
// get the key to prepare an answer
|
||||
int start = _receiveBuffer.indexOf("Sec-WebSocket-Key") + 19;
|
||||
@@ -403,7 +404,7 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &)
|
||||
const ColorCorrection * colorTemp = _hyperion->getTemperature(tempId);
|
||||
if (colorTemp == nullptr)
|
||||
{
|
||||
std::cerr << "JSONCLIENT ERROR: Incorrect color temperature correction id: " << tempId << std::endl;
|
||||
Error(_log, "Incorrect color temperature correction id: %s", tempId.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -424,7 +425,7 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &)
|
||||
const ColorTransform * colorTransform = _hyperion->getTransform(transformId);
|
||||
if (colorTransform == nullptr)
|
||||
{
|
||||
std::cerr << "JSONCLIENT ERROR: Incorrect color transform id: " << transformId << std::endl;
|
||||
Error(_log, "Incorrect color transform id: %s", transformId.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -462,7 +463,7 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &)
|
||||
const ColorAdjustment * colorAdjustment = _hyperion->getAdjustment(adjustmentId);
|
||||
if (colorAdjustment == nullptr)
|
||||
{
|
||||
std::cerr << "JSONCLIENT ERROR: Incorrect color adjustment id: " << adjustmentId << std::endl;
|
||||
Error(_log, "Incorrect color adjustment id: %s", adjustmentId.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -799,7 +800,7 @@ void JsonClientConnection::sendMessage(const Json::Value & message, QTcpSocket *
|
||||
socket->write(serializedMessage.c_str());
|
||||
if (!socket->waitForBytesWritten())
|
||||
{
|
||||
//std::cout << "Error while writing data to host" << std::endl;
|
||||
Debug(_log, "Error while writing data to host");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -810,7 +811,7 @@ void JsonClientConnection::sendMessage(const Json::Value & message, QTcpSocket *
|
||||
// receive reply
|
||||
if (!socket->waitForReadyRead())
|
||||
{
|
||||
//std::cout << "Error while reading data from host" << std::endl;
|
||||
Debug(_log, "Error while writing data from host");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -823,7 +824,7 @@ void JsonClientConnection::sendMessage(const Json::Value & message, QTcpSocket *
|
||||
Json::Value reply;
|
||||
if (!jsonReader.parse(serializedReply.constData(), serializedReply.constData() + bytes, reply))
|
||||
{
|
||||
//std::cout << "Error while parsing reply: invalid json" << std::endl;
|
||||
Error(_log, "Error while parsing reply: invalid json");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -859,7 +860,7 @@ bool JsonClientConnection::checkJson(const Json::Value & message, const QString
|
||||
Json::Value schemaJson;
|
||||
if (!jsonReader.parse(reinterpret_cast<const char *>(schemaData.data()), reinterpret_cast<const char *>(schemaData.data()) + schemaData.size(), schemaJson, false))
|
||||
{
|
||||
throw std::runtime_error("JSONCLIENT ERROR: Schema error: " + jsonReader.getFormattedErrorMessages()) ;
|
||||
throw std::runtime_error("JSONCLIENT ERROR: Schema error: " + jsonReader.getFormattedErrorMessages());
|
||||
}
|
||||
|
||||
// create schema checker
|
||||
|
@@ -15,6 +15,7 @@
|
||||
|
||||
// util includes
|
||||
#include <utils/jsonschema/JsonSchemaChecker.h>
|
||||
#include <utils/Logger.h>
|
||||
|
||||
class ImageProcessor;
|
||||
|
||||
@@ -194,4 +195,6 @@ private:
|
||||
|
||||
/// used for WebSocket detection and connection handling
|
||||
bool _webSocketHandshakeDone;
|
||||
|
||||
Logger * _log;
|
||||
};
|
||||
|
@@ -9,7 +9,8 @@ JsonServer::JsonServer(uint16_t port) :
|
||||
QObject(),
|
||||
_hyperion(Hyperion::getInstance()),
|
||||
_server(),
|
||||
_openConnections()
|
||||
_openConnections(),
|
||||
_log(Logger::getInstance("JSONSERVER"))
|
||||
{
|
||||
if (!_server.listen(QHostAddress::Any, port))
|
||||
{
|
||||
@@ -50,7 +51,7 @@ void JsonServer::newConnection()
|
||||
|
||||
if (socket != nullptr)
|
||||
{
|
||||
std::cout << "JSONSERVER INFO: New connection" << std::endl;
|
||||
Debug(_log, "New connection");
|
||||
JsonClientConnection * connection = new JsonClientConnection(socket, _hyperion);
|
||||
_openConnections.insert(connection);
|
||||
|
||||
@@ -61,7 +62,7 @@ void JsonServer::newConnection()
|
||||
|
||||
void JsonServer::closedConnection(JsonClientConnection *connection)
|
||||
{
|
||||
std::cout << "JSONSERVER INFO: Connection closed" << std::endl;
|
||||
Debug(_log, "Connection closed");
|
||||
_openConnections.remove(connection);
|
||||
|
||||
// schedule to delete the connection object
|
||||
|
Reference in New Issue
Block a user