From 7d9eb0b09f944a842b865b8d790a9d519ddc9bb7 Mon Sep 17 00:00:00 2001 From: EndrII Date: Fri, 7 Feb 2025 11:09:25 +0100 Subject: [PATCH] update quasarapp --- Patronum/src/PController.cpp | 5 +- Patronum/src/Private/baseinstaller.cpp | 25 +++++----- Patronum/src/Private/controllerprivate.cpp | 25 +++++----- Patronum/src/Private/installersystemd.cpp | 16 +++---- Patronum/src/Private/localsocket.cpp | 12 ++--- Patronum/src/Private/parser.cpp | 4 +- Patronum/src/Private/serviceprivate.cpp | 54 ++++++++++------------ submodules/QuasarAppLib | 2 +- 8 files changed, 64 insertions(+), 79 deletions(-) diff --git a/Patronum/src/PController.cpp b/Patronum/src/PController.cpp index 8e119cb..e55aeba 100644 --- a/Patronum/src/PController.cpp +++ b/Patronum/src/PController.cpp @@ -83,7 +83,7 @@ bool Controller::send() { } QTimer::singleShot(1000, nullptr, []() { - QuasarAppUtils::Params::log(errorToString(PatronumError::TimeOutError), QuasarAppUtils::Error); + qCritical() << errorToString(PatronumError::TimeOutError); QCoreApplication::exit(static_cast(PatronumError::TimeOutError)); }); @@ -120,8 +120,7 @@ QuasarAppUtils::Help::Section Controller::help() const { } void Controller::handleError(PatronumError error) { - QuasarAppUtils::Params::log(errorToString(error), - QuasarAppUtils::Error); + qCritical() << errorToString(error); } void Controller::handleFeatures(const QList &features) { diff --git a/Patronum/src/Private/baseinstaller.cpp b/Patronum/src/Private/baseinstaller.cpp index 39fdd9c..56834b0 100644 --- a/Patronum/src/Private/baseinstaller.cpp +++ b/Patronum/src/Private/baseinstaller.cpp @@ -23,15 +23,12 @@ bool BaseInstaller::install(const QString &executable, const QString &user) { Q_UNUSED(user) if (!QFile::exists(executable)) { - QuasarAppUtils::Params::log(QObject::tr("The service executable file is not exists %0\n").arg(executable), - QuasarAppUtils::Error); + qCritical() << "The service executable file is not exists " << executable; return false; } if (isInstalled()) { - QuasarAppUtils::Params::log(QObject::tr("the service %0 alredy installed \n"). - arg(PCommon::instance()->getServiceName()), - QuasarAppUtils::Info); + qInfo() << "The service " << PCommon::instance()->getServiceName() << " alredy installed"; return false; } @@ -40,9 +37,8 @@ bool BaseInstaller::install(const QString &executable, const QString &user) { bool BaseInstaller::uninstall() { if (!isInstalled()) { - QuasarAppUtils::Params::log(QObject::tr("the service %0 alredy uninstalled \n"). - arg(PCommon::instance()->getServiceName()), - QuasarAppUtils::Info); + + qInfo() << "The service " << PCommon::instance()->getServiceName() << " alredy uninstalled"; return false; } @@ -51,9 +47,10 @@ bool BaseInstaller::uninstall() { bool BaseInstaller::enable() { if (!isInstalled()) { - QuasarAppUtils::Params::log(QObject::tr("Cannot enabled the service %0 not installed, run install command befor enable. \n"). - arg(PCommon::instance()->getServiceName()), - QuasarAppUtils::Info); + + qInfo() << QObject::tr("Cannot enabled the service %0 not installed, run install command befor enable. \n"). + arg(PCommon::instance()->getServiceName()); + return false; } @@ -62,9 +59,9 @@ bool BaseInstaller::enable() { bool BaseInstaller::disable() { if (!isInstalled()) { - QuasarAppUtils::Params::log(QObject::tr("Cannot disabled the service %0 not installed, run install command befor enable. \n"). - arg(PCommon::instance()->getServiceName()), - QuasarAppUtils::Info); + + qInfo() << QObject::tr("Cannot disabled the service %0 not installed, run install command befor enable. \n"). + arg(PCommon::instance()->getServiceName()); return false; } return true; diff --git a/Patronum/src/Private/controllerprivate.cpp b/Patronum/src/Private/controllerprivate.cpp index 966450e..8a49227 100644 --- a/Patronum/src/Private/controllerprivate.cpp +++ b/Patronum/src/Private/controllerprivate.cpp @@ -39,8 +39,9 @@ ControllerPrivate::~ControllerPrivate() { bool ControllerPrivate::sendFeaturesRequest() { if (!_socket->isValid()) { - QuasarAppUtils::Params::log("scoket is closed!", - QuasarAppUtils::Debug); + + qDebug() << "scoket is closed!"; + _controller->handleError(PatronumError::ServiceUnavailable); return false; } @@ -50,8 +51,9 @@ bool ControllerPrivate::sendFeaturesRequest() { bool ControllerPrivate::sendCmd(const QSet &result) { if (!_socket->isValid()) { - QuasarAppUtils::Params::log("scoket is closed!", - QuasarAppUtils::Debug); + + qDebug() << "scoket is closed!"; + _controller->handleError(PatronumError::ServiceUnavailable); return false; @@ -92,8 +94,9 @@ bool ControllerPrivate::connectToHost(bool echo) const { if (!_socket->connectToTarget()) { if (echo) { - QuasarAppUtils::Params::log("Connect to service fail !", - QuasarAppUtils::Debug); + + qDebug() << "Fail to connect to service!"; + _controller->handleError(PatronumError::ServiceUnavailable); } @@ -112,8 +115,7 @@ void ControllerPrivate::setEcho(bool echo) { void ControllerPrivate::handleReceve(QByteArray data) { if (!_controller) { - QuasarAppUtils::Params::log("System error, controller is not inited!", - QuasarAppUtils::Error); + qCritical() << "System error, controller is not inited!"; return; } @@ -125,8 +127,7 @@ void ControllerPrivate::handleReceve(QByteArray data) { for (const auto& pkg: std::as_const(packages)) { if (!pkg.isValid()) { - QuasarAppUtils::Params::log("Received invalid package!", - QuasarAppUtils::Debug); + qDebug() << "Invalid Package received. "; _controller->handleError(PatronumError::InvalidPackage); @@ -167,8 +168,8 @@ void ControllerPrivate::handleReceve(QByteArray data) { } default: { - QuasarAppUtils::Params::log("Wrong command!", - QuasarAppUtils::Debug); + qDebug() << "Wrong command!"; + _controller->handleError(PatronumError::WrongCommand); break; diff --git a/Patronum/src/Private/installersystemd.cpp b/Patronum/src/Private/installersystemd.cpp index 71417a7..4f181dc 100644 --- a/Patronum/src/Private/installersystemd.cpp +++ b/Patronum/src/Private/installersystemd.cpp @@ -36,9 +36,8 @@ bool InstallerSystemD::install(const QString &executable, const QString& user) { QFile templ(":/systemd/SystemD/service.service"); QString name = PCommon::instance()->getServiceName(); if (!templ.open(QIODevice::ReadOnly)) { - QuasarAppUtils::Params::log(QString{"Cannot install %0. The service template not available.\n"}. - arg(name), - QuasarAppUtils::Error); + + qCritical() << "Cannot install " << name << ". The service template not available."; return false; } @@ -59,9 +58,8 @@ bool InstallerSystemD::install(const QString &executable, const QString& user) { templ.setFileName(absaluteServicePath()); if (!templ.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - QuasarAppUtils::Params::log(QString{"Cannot install %0. %1\n"}. - arg(name, templ.errorString()), - QuasarAppUtils::Error); + + qCritical() << "Cannot install " << name << ". " << templ.errorString(); return false; } @@ -87,10 +85,8 @@ bool InstallerSystemD::uninstall() { QString name = PCommon::instance()->getServiceName(); if (!(disable() && QFile::remove(absaluteServicePath()))) { - QuasarAppUtils::Params::log(QString("Cannot uninstall %0. Cannot remove %1. Check permissions.\n"). - arg(name, - absaluteServicePath()), - QuasarAppUtils::Error); + + qCritical() << "Cannot uninstall " << name << ". Cannot remove " << absaluteServicePath() << ". Check permissions."; return false; } return true; diff --git a/Patronum/src/Private/localsocket.cpp b/Patronum/src/Private/localsocket.cpp index d5acbd5..78c859b 100644 --- a/Patronum/src/Private/localsocket.cpp +++ b/Patronum/src/Private/localsocket.cpp @@ -76,8 +76,7 @@ bool LocalSocket::listen() { } if (!m_server->listen(m_target)) { - QuasarAppUtils::Params::log("listen is failed! " + m_server->errorString(), - QuasarAppUtils::Error); + qCritical() << "Can't start local server! " << m_server->errorString(); return false; } @@ -89,8 +88,8 @@ bool LocalSocket::connectToTarget() { if (!m_socket) { m_socket = new QLocalSocket(this); if (!registerSokcet(m_socket)) { - QuasarAppUtils::Params::log("registerSokcet is failed!", - QuasarAppUtils::Error); + + qCritical() << "registerSokcet is failed!"; return false; } } @@ -138,12 +137,11 @@ void LocalSocket::handleSocketError(QLocalSocket::LocalSocketError) { auto _sender = dynamic_cast(sender()); if (!_sender) { - QuasarAppUtils::Params::log("Unknown error occurred!", QuasarAppUtils::Error); + qCritical() << "Unknown error occurred!"; return; } - QuasarAppUtils::Params::log("Socket connection fail: " + _sender->errorString(), - QuasarAppUtils::Warning); + qWarning() << "Socket connection fail: " << _sender->errorString(); } diff --git a/Patronum/src/Private/parser.cpp b/Patronum/src/Private/parser.cpp index f242448..d7e7ab4 100644 --- a/Patronum/src/Private/parser.cpp +++ b/Patronum/src/Private/parser.cpp @@ -59,8 +59,8 @@ bool Parser::parse(const QByteArray &array, } if (_data.m_data.size() > _data.m_hdr.size) { - QuasarAppUtils::Params::log("Invalid Package received. ", - QuasarAppUtils::Warning); + + qWarning() << "Invalid Package received. "; _data.reset(); _hdrArray.clear(); diff --git a/Patronum/src/Private/serviceprivate.cpp b/Patronum/src/Private/serviceprivate.cpp index 33e872c..3d2e824 100644 --- a/Patronum/src/Private/serviceprivate.cpp +++ b/Patronum/src/Private/serviceprivate.cpp @@ -21,8 +21,8 @@ #include void handleTermSignals(int sig) { - QuasarAppUtils::Params::log(QString("Shutdown application with %0 signal.").arg(sig), - QuasarAppUtils::Info); + + qInfo() << "Shutdown application with " << sig << " signal."; QCoreApplication::exit(0); } @@ -61,8 +61,8 @@ ServicePrivate::~ServicePrivate() { bool ServicePrivate::sendCmdResult(const QVariantMap &result) { if (!_socket->isValid()) { - QuasarAppUtils::Params::log("scoket is closed!", - QuasarAppUtils::Error); + qCritical() << "socket is closed!"; + return false; } @@ -71,8 +71,8 @@ bool ServicePrivate::sendCmdResult(const QVariantMap &result) { bool ServicePrivate::sendCloseConnection() { if (!_socket->isValid()) { - QuasarAppUtils::Params::log("scoket is closed!", - QuasarAppUtils::Error); + qCritical() << "socket is closed!"; + return false; } @@ -82,8 +82,7 @@ bool ServicePrivate::sendCloseConnection() { bool ServicePrivate::install(const QString &user) { if (!_installer) { - QuasarAppUtils::Params::log(errorToString(UnsupportedPlatform), - QuasarAppUtils::Error); + qCritical() << errorToString(UnsupportedPlatform); return false; } @@ -91,14 +90,14 @@ bool ServicePrivate::install(const QString &user) { return false; } - QuasarAppUtils::Params::log("The service installed successful", QuasarAppUtils::Info); + qInfo() << "The service installed successful"; return true; } bool ServicePrivate::uninstall() { if (!_installer) { - QuasarAppUtils::Params::log(errorToString(UnsupportedPlatform), - QuasarAppUtils::Error); + qCritical() << errorToString(UnsupportedPlatform); + return false; } @@ -106,15 +105,15 @@ bool ServicePrivate::uninstall() { return false; } - QuasarAppUtils::Params::log("The service uninstalled successful", QuasarAppUtils::Info); + qInfo() << "The service uninstalled successful"; return true; } bool ServicePrivate::start() { if (!_socket->listen()) { - QuasarAppUtils::Params::log("Fail to create a terminal socket!", - QuasarAppUtils::Error); + + qCritical() << "Fail to create a terminal socket!"; return false; }; @@ -124,8 +123,7 @@ bool ServicePrivate::start() { bool ServicePrivate::startDeamon() { if (_socket->isRunning()) { - QuasarAppUtils::Params::log("Failed to start a service because an another service alredy started", - QuasarAppUtils::Error); + qCritical() << "Failed to start a service because an another service alredy started"; return false; } @@ -138,8 +136,7 @@ bool ServicePrivate::startDeamon() { qint64 pid; if (!proc.startDetached(&pid)) { - QuasarAppUtils::Params::log("fail to start detached process: " + proc.errorString(), - QuasarAppUtils::Error); + qCritical() << "fail to start detached process: " + proc.errorString(); return false; } @@ -151,8 +148,7 @@ bool ServicePrivate::startDeamon() { pidFile.write(QByteArray::number(pid)); pidFile.close(); - QuasarAppUtils::Params::log("The service started successful", QuasarAppUtils::Info); - + qInfo() << "The service started successful"; return true; } @@ -204,20 +200,20 @@ void ServicePrivate::handleReceve(QByteArray data) { for (const auto &pkg: std::as_const(packages)) { if (!pkg.isValid()) { - QuasarAppUtils::Params::log("receive package is not valid!", - QuasarAppUtils::Warning); + + qWarning() << "Invalid Package received. "; return; } if (!_service) { - QuasarAppUtils::Params::log("System error, service is not inited!", - QuasarAppUtils::Error); + + qCritical() << "System error, service is not inited!"; return;; } if (!_socket->isValid()) { - QuasarAppUtils::Params::log("scoket is closed!", - QuasarAppUtils::Error); + + qCritical() << "scoket is closed!"; return; } @@ -227,8 +223,7 @@ void ServicePrivate::handleReceve(QByteArray data) { if (!_socket->send(_parser->createPackage(Command::Features, _service->supportedFeatures()))) { - QuasarAppUtils::Params::log("Fail to send ", - QuasarAppUtils::Error); + qCritical() << "Fail to send supported features!"; } break; @@ -251,8 +246,7 @@ void ServicePrivate::handleReceve(QByteArray data) { } default: { - QuasarAppUtils::Params::log("Wrong command!", - QuasarAppUtils::Error); + qCritical() << "Wrong command!"; break; } } diff --git a/submodules/QuasarAppLib b/submodules/QuasarAppLib index 8b5fce8..8b710ea 160000 --- a/submodules/QuasarAppLib +++ b/submodules/QuasarAppLib @@ -1 +1 @@ -Subproject commit 8b5fce889fb0819d1614962f315eb2f113511114 +Subproject commit 8b710eaa67ebc1ae11b071a33936e376198984b0