9#include "controllerprivate.h"
14#include <QCoreApplication>
20 d_ptr =
new ControllerPrivate(
this);
28 if (!QuasarAppUtils::Params::size() && !QuasarAppUtils::Params::parseParams(argc, argv)) {
37 bool printHelp = !QuasarAppUtils::Params::size() ||
38 QuasarAppUtils::Params::isEndable(
"h") ||
39 QuasarAppUtils::Params::isEndable(
"help");
45 if (!d_ptr->connectToHost()) {
50 if (!d_ptr->sendFeaturesRequest()) {
56 if (QuasarAppUtils::Params::isEndable(
"stop")) {
60 if (QuasarAppUtils::Params::isEndable(
"resume")) {
61 return d_ptr->resume();
64 if (QuasarAppUtils::Params::isEndable(
"pause")) {
65 return d_ptr->pause();
68 QSet<Feature> sendData = {};
69 auto userParams = QuasarAppUtils::Params::getUserParamsMap();
70 for (
auto val = userParams.begin(); val != userParams.end(); ++val) {
72 bool fIgnore = val.key() ==
"verbose" || val.key() ==
"fileLog";
78 sendData.insert(
Feature{val.key(), val.value()});
81 if (!d_ptr->sendCmd(sendData)) {
85 QTimer::singleShot(1000,
nullptr, []() {
97 d_ptr->setEcho(
false);
99 if (!d_ptr->connectToHost(
false)) {
103 _disableFinished =
true;
105 return d_ptr->stop();
109 QuasarAppUtils::Help::Section
help {
110 {QObject::tr(
"Options that available after start"), {
111 {
"stop", QObject::tr(
"Stop a service")},
112 {
"pause", QObject::tr(
"Pause a service")},
113 {
"resume", QObject::tr(
"Resume a service")}
128 QuasarAppUtils::Help::Options options;
130 for (
const auto& feature:
features ) {
131 QString cmd, description;
132 if (feature.arg().isNull()) {
135 cmd = QString(
"-%0 value").arg(feature.cmd());
138 description = feature.description();
140 if (!feature.example().isEmpty()) {
141 description +=
". Example : " + feature.example();
144 options.insert(cmd, description);
147 QuasarAppUtils::Help::print(options);
151 QuasarAppUtils::Help::Options options;
153 for(
auto iter = responce.begin(); iter != responce.end(); ++iter) {
154 options.insert(iter.key(), iter.value().toString());
157 QuasarAppUtils::Help::print(options);
161 if (!_disableFinished)
162 QCoreApplication::exit(0);
166 return d_ptr->features();
169void Controller::printDefaultHelp()
const {
171 auto quasarappHelp = QuasarAppUtils::Params::getHelp();
172 QuasarAppUtils::Help::print(quasarappHelp.unite(
help()));
void finished() override
finished This method invoked when controler receive from service the Command::CloseConnection command...
void handleError(PatronumError error) override
handleError - override this method if you want track errors the default implementation print error me...
void handleFeatures(const QList< Feature > &features) override
handleFeatures - Override this method if you want create a custom reaction of get service features....
QuasarAppUtils::Help::Section help() const
help This method return help of the Controller.
bool send()
send - This method send request to service.
bool sendStop()
sendStop This method send stop command to service;
Controller()
Controller This is base constructor of the controller.
QList< Feature > features()
features - This method return current features of connected service.
void handleResponce(const QVariantMap &responce) override
handleResponce - Override this method if you want create a custom reaction of get responce from servi...
The Feature class it is atomic type for describe service command.
The Patronum namespace - It is main name space of Patronum Library. The Patronum library support the ...
QString errorToString(PatronumError error)
errorToString This method convert the PatronumError to QString.
PatronumError
The PatronumError enum - controller work error codes.
@ TimeOutError
Timeout error. service unavailable or not started.