global logbuffer (#297)

* - implement a global logbuffer
- providerrs232 reduce log spam

* logger add signal and start json push

* implement logger notifier ... need some cleanup
This commit is contained in:
redPanther
2016-11-26 22:34:46 +01:00
committed by GitHub
parent 9360183f2e
commit 73406c982b
7 changed files with 247 additions and 70 deletions

View File

@@ -47,9 +47,11 @@ JsonClientConnection::JsonClientConnection(QTcpSocket *socket)
, _hyperion(Hyperion::getInstance())
, _receiveBuffer()
, _webSocketHandshakeDone(false)
, _log(Logger::getInstance("JSONCLIENTCONNECTION"))
//, _log(Logger::getInstance("JSONCLIENTCONNECTION"))
, _forwarder_enabled(true)
, _streaming_logging_activated(false)
{
_log = Logger::getInstance("JSONCLIENTCONNECTION");
// connect internal signals and slots
connect(_socket, SIGNAL(disconnected()), this, SLOT(socketClosed()));
connect(_socket, SIGNAL(readyRead()), this, SLOT(readData()));
@@ -57,6 +59,9 @@ JsonClientConnection::JsonClientConnection(QTcpSocket *socket)
_timer_ledcolors.setSingleShot(false);
connect(&_timer_ledcolors, SIGNAL(timeout()), this, SLOT(streamLedcolorsUpdate()));
//qRegisterMetaType<Logger::T_LOG_MESSAGE>("Logger::T_LOG_MESSAGE");
connect(LoggerNotifier::getInstance(),SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, SLOT(incommingLogMessage(Logger::T_LOG_MESSAGE)));
}
@@ -306,6 +311,8 @@ void JsonClientConnection::handleMessage(const QString& messageString)
handleComponentStateCommand(message, command, tan);
else if (command == "ledcolors")
handleLedColorsCommand(message, command, tan);
else if (command == "logging")
handleLoggingCommand(message, command, tan);
else
handleNotImplemented();
}
@@ -1204,6 +1211,55 @@ void JsonClientConnection::handleLedColorsCommand(const QJsonObject& message, co
sendSuccessReply(command+"-"+subcommand,tan);
}
void JsonClientConnection::handleLoggingCommand(const QJsonObject& message, const QString &command, const int tan)
{
// create result
QString subcommand = message["subcommand"].toString("");
_streaming_logging_reply["success"] = true;
_streaming_logging_reply["command"] = command;
_streaming_logging_reply["tan"] = tan;
if (subcommand == "start")
{
if (!_streaming_logging_activated)
{
_streaming_logging_reply["command"] = command+"-update";
connect(_log,SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, SLOT(incommingLogMessage(Logger::T_LOG_MESSAGE)));
}
}
else if (subcommand == "stop")
{
if (_streaming_logging_activated)
{
disconnect(_log, SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, 0);
_streaming_logging_activated = false;
}
}
else
{
sendErrorReply("unknown subcommand",command,tan);
return;
}
sendSuccessReply(command+"-"+subcommand,tan);
}
void JsonClientConnection::incommingLogMessage(Logger::T_LOG_MESSAGE msg)
{
if (!_streaming_logging_activated)
{
_streaming_logging_activated = true;
QVector<Logger::T_LOG_MESSAGE>* logBuffer = Logger::getGlobalLogMessageBuffer();
for(int i=0; i<logBuffer->length(); i++)
{
std::cout << "------- " << logBuffer->at(i).message.toStdString() << std::endl;
}
}
std::cout << "------- " << msg.message.toStdString() << std::endl;
}
void JsonClientConnection::handleNotImplemented()
{
sendErrorReply("Command not implemented");