Log Viewer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.0 KiB

#include <QObject>
#include <QTcpServer>
#include <QTcpSocket>
#include "parser/IParser.h"
class TcpServerWorker : public QObject
{
Q_OBJECT
public:
TcpServerWorker(Parser_ptr parser, QObject* parent = nullptr) : QObject(parent)
{
_parser = std::move(parser);
//Initialize the server
server = new QTcpServer(this);
connect(server, &QTcpServer::newConnection, this, &TcpServerWorker::handleNewConnection);
}
bool startServer(quint16 port) {
return server->listen(QHostAddress::Any, port);
}
signals:
void log(Log_ptr log);
//uncrustify off
private slots:
//uncrustify on
void handleNewConnection() {
QTcpSocket* clientSocket = server->nextPendingConnection();
connect(clientSocket, &QTcpSocket::readyRead, this, [this, clientSocket]() {
while(clientSocket->canReadLine())
{
emit log(_parser->parse(clientSocket->readLine()));
}
});
}
private:
QTcpServer* server;
Parser_ptr _parser;
};