added timer for responce

This commit is contained in:
Andrei Yankovich 2021-04-28 17:53:18 +03:00
parent 5fc1abab33
commit d1520b6215
4 changed files with 32 additions and 9 deletions

View File

@ -9,17 +9,24 @@
QString Patronum::IController::errorToString(Patronum::ControllerError error) const {
switch (error) {
case Patronum::ControllerError::ServiceUnavailable: return "Service is unavailable. Try send start comand or restart the service manually.";
case Patronum::ControllerError::ServiceUnavailable:
return QObject::tr("Service is unavailable. Try send start comand or restart the service manually.");
case Patronum::ControllerError::InvalidPackage: return "Invalid package received";
case Patronum::ControllerError::InvalidPackage:
return QObject::tr("Invalid package received");
case Patronum::ControllerError::WrongCommand: return "Library unsupported command received";
case Patronum::ControllerError::WrongCommand:
return QObject::tr("Library unsupported command received");
case Patronum::ControllerError::SystemError: return "Internal error of the work of the Patronum library."
" Contact the developers and provide them with an error report."
" https://github.com/QuasarApp/Patronum/issues";
case Patronum::ControllerError::SystemError:
return QObject::tr("Internal error of the work of the Patronum library."
" Contact the developers and provide them with an error report."
" https://github.com/QuasarApp/Patronum/issues");
case Patronum::ControllerError::TimeOutError:
return QObject::tr("Timeout error. service unavailable or not started.");
default:
return "Unknown error";
return QObject::tr("Unknown error");
}
}

View File

@ -28,8 +28,11 @@ enum class ControllerError {
InvalidPackage,
/// Library unsupported command received.
WrongCommand,
/// Timeout error. service unavailable or not started.
TimeOutError,
/// Internal error of the work of the Patronum library. Contact the developers and provide them with an error report. https://github.com/QuasarApp/Patronum/issues
SystemError
};
/**

View File

@ -12,6 +12,7 @@
#include <QVariantMap>
#include <quasarapp.h>
#include <QCoreApplication>
#include <QTimer>
namespace Patronum {
@ -82,7 +83,17 @@ bool Controller::send() {
sendData.insert(Feature{val.key(), val.value()});
}
return d_ptr->sendCmd(sendData);
if (!d_ptr->sendCmd(sendData)) {
return false;
}
QTimer::singleShot(1000, nullptr, [this]() {
QuasarAppUtils::Params::log(errorToString(ControllerError::TimeOutError), QuasarAppUtils::Error);
QCoreApplication::exit(static_cast<int>(ControllerError::TimeOutError));
});
return true;
}
int Controller::startDetached() const {

View File

@ -61,7 +61,7 @@ public:
QList<Feature> supportedFeatures() {
QList<Feature> res;
Feature Ping = {"Ping", ""}
Feature Ping = {"Ping", "This is description of the ping command"}
return res << Ping;
}
};
@ -87,6 +87,8 @@ public:
};
int main(int argc, char **argv) {
QCoreApplication::setApplicationName("MyServiceName"); // <--
QCoreApplication::setOrganizationName("MyCompany"); // <--
QCoreApplcication app
MyControllerApp controller;
controller.send(argc, argv);