From c8025055539b1b61b2e154b8b2d41238f115e708 Mon Sep 17 00:00:00 2001 From: brindosch Date: Mon, 11 Jul 2016 17:08:22 +0200 Subject: [PATCH] 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 --- include/jsonserver/JsonServer.h | 3 +++ include/protoserver/ProtoConnection.h | 3 +++ include/protoserver/ProtoServer.h | 4 +++- libsrc/blackborder/BlackBorderDetector.cpp | 2 +- libsrc/blackborder/BlackBorderProcessor.cpp | 2 +- libsrc/jsonserver/JsonClientConnection.cpp | 21 +++++++++++---------- libsrc/jsonserver/JsonClientConnection.h | 3 +++ libsrc/jsonserver/JsonServer.cpp | 7 ++++--- libsrc/protoserver/ProtoConnection.cpp | 15 ++++++++------- libsrc/protoserver/ProtoServer.cpp | 7 ++++--- src/hyperiond/hyperiond.cpp | 6 +++--- 11 files changed, 44 insertions(+), 29 deletions(-) diff --git a/include/jsonserver/JsonServer.h b/include/jsonserver/JsonServer.h index 7773ab88..57a47ec8 100644 --- a/include/jsonserver/JsonServer.h +++ b/include/jsonserver/JsonServer.h @@ -9,6 +9,7 @@ // Hyperion includes #include +#include class JsonClientConnection; @@ -56,4 +57,6 @@ private: /// List with open connections QSet _openConnections; + + Logger * _log; }; diff --git a/include/protoserver/ProtoConnection.h b/include/protoserver/ProtoConnection.h index 44327b10..8a6e3b3e 100644 --- a/include/protoserver/ProtoConnection.h +++ b/include/protoserver/ProtoConnection.h @@ -15,6 +15,7 @@ #include #include #include +#include // jsoncpp includes #include @@ -126,4 +127,6 @@ private: /// The buffer used for reading data from the socket QByteArray _receiveBuffer; + + Logger * _log; }; diff --git a/include/protoserver/ProtoServer.h b/include/protoserver/ProtoServer.h index 1241b81f..c6b35968 100644 --- a/include/protoserver/ProtoServer.h +++ b/include/protoserver/ProtoServer.h @@ -17,6 +17,7 @@ #include #include #include +#include // forward decl class ProtoClientConnection; @@ -86,5 +87,6 @@ private: /// Hyperion proto connection object for forwarding QList _proxy_connections; - + + Logger * _log; }; diff --git a/libsrc/blackborder/BlackBorderDetector.cpp b/libsrc/blackborder/BlackBorderDetector.cpp index 7f9b1129..8d789e31 100644 --- a/libsrc/blackborder/BlackBorderDetector.cpp +++ b/libsrc/blackborder/BlackBorderDetector.cpp @@ -23,7 +23,7 @@ uint8_t BlackBorderDetector::calculateThreshold(double threshold) uint8_t blackborderThreshold = uint8_t(rgbThreshold); - Info(Logger::getInstance("BLACKBORDER"), "threshold set to %f (%d)", threshold , int(blackborderThreshold)); + Debug(Logger::getInstance("BLACKBORDER"), "threshold set to %f (%d)", threshold , int(blackborderThreshold)); return blackborderThreshold; } diff --git a/libsrc/blackborder/BlackBorderProcessor.cpp b/libsrc/blackborder/BlackBorderProcessor.cpp index c84d3054..f76e390d 100644 --- a/libsrc/blackborder/BlackBorderProcessor.cpp +++ b/libsrc/blackborder/BlackBorderProcessor.cpp @@ -20,7 +20,7 @@ BlackBorderProcessor::BlackBorderProcessor(const Json::Value &blackborderConfig) , _consistentCnt(0) , _inconsistentCnt(10) { - Info(Logger::getInstance("BLACKBORDER"), "mode: %s", _detectionMode.c_str()); + Debug(Logger::getInstance("BLACKBORDER"), "mode: %s", _detectionMode.c_str()); } BlackBorder BlackBorderProcessor::getCurrentBorder() const diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 605cb34a..241b97bc 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -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(schemaData.data()), reinterpret_cast(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 diff --git a/libsrc/jsonserver/JsonClientConnection.h b/libsrc/jsonserver/JsonClientConnection.h index dd3386b4..bc809725 100644 --- a/libsrc/jsonserver/JsonClientConnection.h +++ b/libsrc/jsonserver/JsonClientConnection.h @@ -15,6 +15,7 @@ // util includes #include +#include class ImageProcessor; @@ -194,4 +195,6 @@ private: /// used for WebSocket detection and connection handling bool _webSocketHandshakeDone; + + Logger * _log; }; diff --git a/libsrc/jsonserver/JsonServer.cpp b/libsrc/jsonserver/JsonServer.cpp index 0d1d7132..41ff0c67 100644 --- a/libsrc/jsonserver/JsonServer.cpp +++ b/libsrc/jsonserver/JsonServer.cpp @@ -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 diff --git a/libsrc/protoserver/ProtoConnection.cpp b/libsrc/protoserver/ProtoConnection.cpp index 3492a7ec..3ac7ce77 100644 --- a/libsrc/protoserver/ProtoConnection.cpp +++ b/libsrc/protoserver/ProtoConnection.cpp @@ -10,8 +10,9 @@ ProtoConnection::ProtoConnection(const std::string & a) : _socket(), _skipReply(false), - _prevSocketState(QAbstractSocket::UnconnectedState) -{ + _prevSocketState(QAbstractSocket::UnconnectedState), + _log(Logger::getInstance("PROTOCONNECTION")) + { QString address(a.c_str()); QStringList parts = address.split(":"); if (parts.size() != 2) @@ -28,7 +29,7 @@ ProtoConnection::ProtoConnection(const std::string & a) : } // try to connect to host - std::cout << "PROTOCONNECTION INFO: Connecting to Hyperion: " << _host.toStdString() << ":" << _port << std::endl; + Info(_log, "Connecting to Hyperion: %s:%d", _host.toStdString().c_str(), _port); connectToHost(); // start the connection timer @@ -74,7 +75,7 @@ void ProtoConnection::readData() if (!reply.ParseFromArray(_receiveBuffer.data() + 4, messageSize)) { - std::cerr << "PROTOCONNECTION ERROR: Unable to parse message" << std::endl; + Error(_log, "Unable to parse message"); return; } @@ -155,11 +156,11 @@ void ProtoConnection::sendMessage(const proto::HyperionRequest &message) switch (_socket.state() ) { case QAbstractSocket::UnconnectedState: - std::cout << "PROTOCONNECTION INFO: No connection to Hyperion: " << _host.toStdString() << ":" << _port << std::endl; + Info(_log, "No connection to Hyperion: %s:%d", _host.toStdString().c_str(), _port); break; case QAbstractSocket::ConnectedState: - std::cout << "PROTOCONNECTION INFO: Connected to Hyperion: " << _host.toStdString() << ":" << _port << std::endl; + Info(_log, "Connected to Hyperion: %s:%d", _host.toStdString().c_str(), _port); break; default: @@ -193,7 +194,7 @@ void ProtoConnection::sendMessage(const proto::HyperionRequest &message) count += _socket.write(reinterpret_cast(serializedMessage.data()), length); if (!_socket.waitForBytesWritten()) { - std::cerr << "PROTOCONNECTION ERROR: Error while writing data to host" << std::endl; + Error(_log, "Error while writing data to host"); return; } } diff --git a/libsrc/protoserver/ProtoServer.cpp b/libsrc/protoserver/ProtoServer.cpp index c4461e62..46d38029 100644 --- a/libsrc/protoserver/ProtoServer.cpp +++ b/libsrc/protoserver/ProtoServer.cpp @@ -11,7 +11,8 @@ ProtoServer::ProtoServer(uint16_t port) : QObject(), _hyperion(Hyperion::getInstance()), _server(), - _openConnections() + _openConnections(), + _log(Logger::getInstance("PROTOSERVER")) { MessageForwarder * forwarder = _hyperion->getForwarder(); @@ -57,7 +58,7 @@ void ProtoServer::newConnection() if (socket != nullptr) { - std::cout << "PROTOSERVER INFO: New connection" << std::endl; + Debug(_log, "New connection"); ProtoClientConnection * connection = new ProtoClientConnection(socket, _hyperion); _openConnections.insert(connection); @@ -86,7 +87,7 @@ void ProtoServer::sendImageToProtoSlaves(int priority, const Image & i void ProtoServer::closedConnection(ProtoClientConnection *connection) { - std::cout << "PROTOSERVER INFO: Connection closed" << std::endl; + Debug(_log, "Connection closed"); _openConnections.remove(connection); // schedule to delete the connection object diff --git a/src/hyperiond/hyperiond.cpp b/src/hyperiond/hyperiond.cpp index e56db837..c4875e1e 100644 --- a/src/hyperiond/hyperiond.cpp +++ b/src/hyperiond/hyperiond.cpp @@ -299,7 +299,7 @@ void HyperionDaemon::startNetworkServices() BonjourRecord(mDNSDescr.c_str(), "_hyperiond-rgbled._udp", QString()), _udpListener->getPort() ); - Info(_log, "UDP LIstener mDNS responder started"); + Debug(_log, "UDP LIstener mDNS responder started"); } // zeroconf json @@ -308,7 +308,7 @@ void HyperionDaemon::startNetworkServices() BonjourRecord(mDNSDescr.c_str(), "_hyperiond-json._tcp", QString()), _jsonServer->getPort() ); - Info(_log, "Json mDNS responder started"); + Debug(_log, "Json mDNS responder started"); // zeroconf proto BonjourServiceRegister *bonjourRegister_proto = new BonjourServiceRegister(); @@ -316,7 +316,7 @@ void HyperionDaemon::startNetworkServices() BonjourRecord(mDNSDescr.c_str(), "_hyperiond-proto._tcp", QString()), _protoServer->getPort() ); - Info(_log, "Proto mDNS responder started"); + Debug(_log, "Proto mDNS responder started"); } void HyperionDaemon::createGrabberDispmanx()