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:
brindosch 2016-07-11 17:08:22 +02:00 committed by GitHub
parent 070a534262
commit c802505553
11 changed files with 44 additions and 29 deletions

View File

@ -9,6 +9,7 @@
// Hyperion includes
#include <hyperion/Hyperion.h>
#include <utils/Logger.h>
class JsonClientConnection;
@ -56,4 +57,6 @@ private:
/// List with open connections
QSet<JsonClientConnection *> _openConnections;
Logger * _log;
};

View File

@ -15,6 +15,7 @@
#include <utils/ColorRgb.h>
#include <utils/GrabbingMode.h>
#include <utils/VideoMode.h>
#include <utils/Logger.h>
// jsoncpp includes
#include <message.pb.h>
@ -126,4 +127,6 @@ private:
/// The buffer used for reading data from the socket
QByteArray _receiveBuffer;
Logger * _log;
};

View File

@ -17,6 +17,7 @@
#include <utils/ColorRgb.h>
#include <utils/GrabbingMode.h>
#include <utils/VideoMode.h>
#include <utils/Logger.h>
// forward decl
class ProtoClientConnection;
@ -86,5 +87,6 @@ private:
/// Hyperion proto connection object for forwarding
QList<ProtoConnection*> _proxy_connections;
Logger * _log;
};

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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;
};

View File

@ -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

View File

@ -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<const char *>(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;
}
}

View File

@ -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<ColorRgb> & 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

View File

@ -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()