Skip to content
Snippets Groups Projects
Commit 03d917e9 authored by andrey.daragan's avatar andrey.daragan
Browse files

Merge branch 'features-2917' into 'develop'

Features 2917

See merge request !86
parents 7c9e2e09 837afce3
No related branches found
No related tags found
1 merge request!86Features 2917
Pipeline #1731 passed with stage
in 15 minutes and 7 seconds
...@@ -47,17 +47,17 @@ void DapServiceController::requestToService(const QString &asServicename, const ...@@ -47,17 +47,17 @@ void DapServiceController::requestToService(const QString &asServicename, const
const QVariant &arg8, const QVariant &arg9, const QVariant &arg10) const QVariant &arg8, const QVariant &arg9, const QVariant &arg10)
{ {
DapAbstractCommand * transceiver = m_transceivers.find(asServicename).value().first; DapAbstractCommand * transceiver = m_transceivers.find(asServicename).value().first;
Q_ASSERT(transceiver); Q_ASSERT(transceiver);
transceiver->requestToService(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
connect(transceiver, SIGNAL(serviceResponded(QVariant)), SLOT(findEmittedSignal(QVariant))); connect(transceiver, SIGNAL(serviceResponded(QVariant)), SLOT(findEmittedSignal(QVariant)));
transceiver->requestToService(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
} }
/// Register command. /// Register command.
void DapServiceController::registerCommand() void DapServiceController::registerCommand()
{ {
m_transceivers.insert("ADD", qMakePair(new DapAddWalletCommand("ADD", m_DAPRpcSocket, this), QString("addWalletResponded"))); m_transceivers.insert("ADD", qMakePair(new DapAddWalletCommand("ADD", m_DAPRpcSocket, this), QString("addWalletResponded")));
m_transceivers.insert("GET_LOG", qMakePair(new DapUpdateLogsCommand("GET_LOG", m_DAPRpcSocket, this),QString("historyLogResponded")));
} }
/// Find the emitted signal. /// Find the emitted signal.
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "DapServiceClient.h" #include "DapServiceClient.h"
#include "Handlers/DapAbstractCommand.h" #include "Handlers/DapAbstractCommand.h"
#include "Handlers/DapAddWalletCommand.h" #include "Handlers/DapAddWalletCommand.h"
#include "Handlers/DapUpdateLogsCommand.h"
class DapServiceController : public QObject class DapServiceController : public QObject
{ {
...@@ -75,6 +76,9 @@ signals: ...@@ -75,6 +76,9 @@ signals:
void versionChanged(const QString &version); void versionChanged(const QString &version);
void addWalletResponded(const QVariant& wallet); void addWalletResponded(const QVariant& wallet);
///A signal that is used to transmit data to the log model.
/// @param historyString QStringList
void historyLogResponded(const QVariant& historyString);
private slots: private slots:
/// Register command. /// Register command.
......
...@@ -2,6 +2,7 @@ import QtQuick.Window 2.2 ...@@ -2,6 +2,7 @@ import QtQuick.Window 2.2
import QtQuick.Controls 2.1 import QtQuick.Controls 2.1
import QtQuick 2.0 import QtQuick 2.0
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
import QtQml 2.0
DapLogsScreenForm DapLogsScreenForm
{ {
...@@ -35,9 +36,25 @@ DapLogsScreenForm ...@@ -35,9 +36,25 @@ DapLogsScreenForm
property var todayYear property var todayYear
property var stringTime property var stringTime
} }
//Slot for updating data in the model. The signal comes from C++.
Connections
{
target: dapServiceController
onHistoryLogResponded:fillModel(historyString);
}
//Timer for updating data in the model
Timer
{
id:loadContentLogTimer
interval: 60000
repeat: true
onTriggered: dapServiceController.requestToService("GET_LOG",200);
}
//Creates a list model for the example //Creates a list model for the example
Component.onCompleted: { Component.onCompleted:
{
dapLogsListViewIndex = -1; dapLogsListViewIndex = -1;
privateDate.today = new Date(); privateDate.today = new Date();
privateDate.todayDay = privateDate.today.getDate(); privateDate.todayDay = privateDate.today.getDate();
...@@ -45,14 +62,10 @@ DapLogsScreenForm ...@@ -45,14 +62,10 @@ DapLogsScreenForm
privateDate.todayYear = privateDate.today.getFullYear(); privateDate.todayYear = privateDate.today.getFullYear();
var timeString = new Date(); var timeString = new Date();
var day = new Date(86400); var day = new Date(86400);
var count = 1000
for (var i = 0; i < count; i++) dapServiceController.requestToService("GET_LOG",200);
{ loadContentLogTimer.start();
var momentTime = timeString/1000 - (day/6) * i;
var momentDay = getDay(momentTime);
dapLogsModel.append({"type":"DBG"+i, "info":"Add problems"+i, "file":"dup_chein"+i, "time":getTime(momentTime),
"date":getDay(momentTime)});
}
} }
ListModel ListModel
...@@ -126,6 +139,7 @@ DapLogsScreenForm ...@@ -126,6 +139,7 @@ DapLogsScreenForm
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
width: 43 * pt width: 43 * pt
color: parent.color color: parent.color
clip: true
Text Text
{ {
id: typeLog id: typeLog
...@@ -148,6 +162,7 @@ DapLogsScreenForm ...@@ -148,6 +162,7 @@ DapLogsScreenForm
anchors.right: frameFileLog.left anchors.right: frameFileLog.left
anchors.rightMargin: thirdMarginList anchors.rightMargin: thirdMarginList
color: parent.color color: parent.color
clip: true
Text Text
{ {
id: textLog id: textLog
...@@ -169,6 +184,7 @@ DapLogsScreenForm ...@@ -169,6 +184,7 @@ DapLogsScreenForm
anchors.rightMargin: thirdMarginList anchors.rightMargin: thirdMarginList
width: 326 * pt width: 326 * pt
color: parent.color color: parent.color
clip: true
Text Text
{ {
id: fileLog id: fileLog
...@@ -189,6 +205,7 @@ DapLogsScreenForm ...@@ -189,6 +205,7 @@ DapLogsScreenForm
anchors.right: parent.right anchors.right: parent.right
width: 62 * pt width: 62 * pt
color: parent.color color: parent.color
clip: true
Text Text
{ {
id: timeLog id: timeLog
...@@ -232,19 +249,41 @@ DapLogsScreenForm ...@@ -232,19 +249,41 @@ DapLogsScreenForm
} }
} }
//Splits a string from the log.
function parceStringFromLog(string)
{
var split = string.split(/ \[|\] \[|\]|\[/);
return split;
}
//Fills in the model.
function fillModel(stringList)
{
dapLogsModel.clear();
var count = Object.keys(stringList).length
for (var ind = count-1; ind >= 0; ind--)
{
var arrLogString = parceStringFromLog(stringList[ind]);
var stringTime = parceTime(arrLogString[1]);
dapLogsModel.append({"type":arrLogString[2], "info":arrLogString[4], "file":arrLogString[3], "time":getTime(stringTime),
"date":getDay(stringTime)});
}
}
//This function converts the string representation of time to the Date format //This function converts the string representation of time to the Date format
function parceTime(thisTime) function parceTime(thisTime)
{ {
var aDate = thisTime.split('-'); var aDate = thisTime.split('-');
var aDay = aDate[0].split('/'); var aDay = aDate[0].split('/');
var aTime = aDate[1].split(':'); var aTime = aDate[1].split(':');
privateDate.stringTime = new Date(20+aDay[2], aDay[0] - 1, aDay[1], aTime[0], aTime[1], aTime[2]); return new Date(20+aDay[2], aDay[0] - 1, aDay[1], aTime[0], aTime[1], aTime[2]);
} }
//Returns the time in the correct form for the delegate //Returns the time in the correct form for the delegate
function getTime(thisTime) function getTime(thisTime)
{ {
var tmpTime = new Date(thisTime * 1000) var tmpTime = new Date(thisTime)
var thisHour = tmpTime.getHours(); var thisHour = tmpTime.getHours();
var thisMinute = tmpTime.getMinutes(); var thisMinute = tmpTime.getMinutes();
var thisSecond = tmpTime.getSeconds(); var thisSecond = tmpTime.getSeconds();
...@@ -258,7 +297,7 @@ DapLogsScreenForm ...@@ -258,7 +297,7 @@ DapLogsScreenForm
{ {
var monthArray = ["January", "February", "March", "April", "May", "June", "July", "August", "September", var monthArray = ["January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December"]; "October", "November", "December"];
var tmpDate = new Date(thisTime*1000); var tmpDate = new Date(thisTime);
var thisMonth = tmpDate.getMonth(); var thisMonth = tmpDate.getMonth();
var thisDay = tmpDate.getDate(); var thisDay = tmpDate.getDate();
var thisYear = tmpDate.getFullYear(); var thisYear = tmpDate.getFullYear();
......
...@@ -36,4 +36,5 @@ bool DapServiceController::start() ...@@ -36,4 +36,5 @@ bool DapServiceController::start()
void DapServiceController::registerCommand() void DapServiceController::registerCommand()
{ {
m_pServer->addService(new DapAddWalletCommand("ADD", nullptr, this)); m_pServer->addService(new DapAddWalletCommand("ADD", nullptr, this));
m_pServer->addService(new DapUpdateLogsCommand("GET_LOG", nullptr, this));
} }
...@@ -23,6 +23,7 @@ typedef class DapRpcLocalServer DapUiService; ...@@ -23,6 +23,7 @@ typedef class DapRpcLocalServer DapUiService;
#include "Handlers/DapAbstractCommand.h" #include "Handlers/DapAbstractCommand.h"
#include "Handlers/DapAddWalletCommand.h" #include "Handlers/DapAddWalletCommand.h"
#include "Handlers/DapUpdateLogsCommand.h"
/** /**
* @brief The DapServiceController class * @brief The DapServiceController class
......
...@@ -28,7 +28,7 @@ QVariant DapAddWalletCommand::respondToService(const QVariant &arg1, const QVari ...@@ -28,7 +28,7 @@ QVariant DapAddWalletCommand::respondToService(const QVariant &arg1, const QVari
Q_UNUSED(arg8) Q_UNUSED(arg8)
Q_UNUSED(arg9) Q_UNUSED(arg9)
Q_UNUSED(arg10) Q_UNUSED(arg10)
return QVariant(); return QVariant();
} }
......
#include "DapUpdateLogsCommand.h"
/// Overloaded constructor.
/// @param asServiceName Service name.
/// @param apSocket Client connection socket with service.
/// @param parent Parent.
DapUpdateLogsCommand::DapUpdateLogsCommand(const QString &asServiceName, DapRpcSocket *apSocket, QObject *parent)
: DapAbstractCommand(asServiceName, apSocket, parent),m_seekFile(0),m_bufferSize(DEFAULT_BUFFER_SIZE),m_bufLog(),m_watcherDapLogFile(nullptr)
{
if(apSocket == nullptr)
{
m_watcherDapLogFile = new QFileSystemWatcher(parent);
if (! m_watcherDapLogFile->addPath(LOG_FILE))
{
qCritical("File not found");
}
connect(m_watcherDapLogFile, &QFileSystemWatcher::fileChanged, this,&DapUpdateLogsCommand::dapGetLog);
}
}
/// Send a response to the service.
/// @param arg1...arg10 Parameters.
/// @return Reply to service.
QVariant DapUpdateLogsCommand::respondToService(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3,
const QVariant &arg4, const QVariant &arg5, const QVariant &arg6,
const QVariant &arg7, const QVariant &arg8, const QVariant &arg9,
const QVariant &arg10)
{
Q_UNUSED(arg1)
Q_UNUSED(arg2)
Q_UNUSED(arg3)
Q_UNUSED(arg4)
Q_UNUSED(arg5)
Q_UNUSED(arg6)
Q_UNUSED(arg7)
Q_UNUSED(arg8)
Q_UNUSED(arg9)
Q_UNUSED(arg10)
return QVariant();
}
/// The log file is being read.
/// @param arg1...arg10 Parameters.
/// @return Reply to client.
QVariant DapUpdateLogsCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3,
const QVariant &arg4, const QVariant &arg5, const QVariant &arg6,
const QVariant &arg7, const QVariant &arg8, const QVariant &arg9,
const QVariant &arg10)
{
Q_UNUSED(arg2)
Q_UNUSED(arg3)
Q_UNUSED(arg4)
Q_UNUSED(arg5)
Q_UNUSED(arg6)
Q_UNUSED(arg7)
Q_UNUSED(arg8)
Q_UNUSED(arg9)
Q_UNUSED(arg10)
if(m_bufferSize != arg1.toInt()||m_bufLog.isEmpty())
{
m_bufferSize = arg1.toInt();
m_seekFile = 0;
dapGetLog();
}
return m_bufLog;
}
///The slot reads logs to the buffer.
void DapUpdateLogsCommand::dapGetLog()
{
QFile dapLogFile(LOG_FILE);
if (!dapLogFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
qCritical("The node log file does not open.");
return;
}
QTextStream readFile(&dapLogFile);
QString line;
readFile.seek(m_seekFile);
while(!readFile.atEnd())
{
m_bufLog.append(readFile.readLine());
if(m_bufLog.size() > m_bufferSize)
{
m_bufLog.removeFirst();
}
}
m_seekFile = readFile.pos();
dapLogFile.close();
}
/// Reply from service.
/// @return Service reply.
void DapUpdateLogsCommand::replyFromService()
{
DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender());
emit serviceResponded(reply->response().toJsonValue());
}
#ifndef DAPUPDATELOGSCOMMAND_H
#define DAPUPDATELOGSCOMMAND_H
#include <QFile>
#include <QFileSystemWatcher>
#include "DapAbstractCommand.h"
#define LOG_FILE "/opt/cellframe-node/var/log/cellframe-node.log"
#define DEFAULT_BUFFER_SIZE 200
class DapUpdateLogsCommand : public DapAbstractCommand
{
///The cursor position from which to start reading the file.
qint64 m_seekFile {0};
///The number of rows that are stored in memory.
int m_bufferSize {0};
///The container with the lines from the log.
QStringList m_bufLog;
///Monitors changes in the log file.
QFileSystemWatcher *m_watcherDapLogFile {nullptr};
public:
/// Overloaded constructor.
/// @param asServiceName Service name.
/// @param apSocket Client connection socket with service.
/// @param parent Parent.
explicit DapUpdateLogsCommand(const QString &asServicename, DapRpcSocket *apSocket = nullptr, QObject *parent = nullptr);
protected slots:
///The slot reads logs to the buffer.
void dapGetLog();
public slots:
/// Send a response to the service.
/// @param arg1...arg10 Parameters.
/// @return Reply to service.
QVariant respondToService(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(),
const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(),
const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(),
const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(),
const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant())override;
/// Send a response to the client.
/// @param arg1...arg10 Parameters.
/// @return Reply to client.
QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(),
const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(),
const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(),
const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(),
const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override;
/// Reply from service.
/// @return Service reply.
virtual void replyFromService()override;
};
#endif // DAPUPDATELOGSCOMMAND_H
...@@ -20,7 +20,8 @@ SOURCES +=\ ...@@ -20,7 +20,8 @@ SOURCES +=\
$$PWD/DapLogMessage.cpp \ $$PWD/DapLogMessage.cpp \
$$PWD/DapChainWallet.cpp \ $$PWD/DapChainWallet.cpp \
$$PWD/Handlers/DapAbstractCommand.cpp \ $$PWD/Handlers/DapAbstractCommand.cpp \
$$PWD/Handlers/DapAddWalletCommand.cpp $$PWD/Handlers/DapAddWalletCommand.cpp \
$$PWD/Handlers/DapUpdateLogsCommand.cpp
HEADERS +=\ HEADERS +=\
$$PWD/DapChainConvertor.h \ $$PWD/DapChainConvertor.h \
...@@ -31,4 +32,5 @@ HEADERS +=\ ...@@ -31,4 +32,5 @@ HEADERS +=\
$$PWD/DapChainWallet.h \ $$PWD/DapChainWallet.h \
$$PWD/DapNodeType.h \ $$PWD/DapNodeType.h \
$$PWD/Handlers/DapAbstractCommand.h \ $$PWD/Handlers/DapAbstractCommand.h \
$$PWD/Handlers/DapAddWalletCommand.h $$PWD/Handlers/DapAddWalletCommand.h \
$$PWD/Handlers/DapUpdateLogsCommand.h
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment