9#include "controllerprivate.h"
15#include <QCoreApplication>
21 d_ptr =
new ControllerPrivate(
this);
29 if (!QuasarAppUtils::Params::size() && !QuasarAppUtils::Params::parseParams(argc, argv)) {
38 bool printHelp = !QuasarAppUtils::Params::size() ||
39 QuasarAppUtils::Params::isEndable(
"h") ||
40 QuasarAppUtils::Params::isEndable(
"help");
46 if (!d_ptr->connectToHost()) {
51 if (!d_ptr->sendFeaturesRequest()) {
57 if (QuasarAppUtils::Params::isEndable(
"stop")) {
61 if (QuasarAppUtils::Params::isEndable(
"resume")) {
62 return d_ptr->resume();
65 if (QuasarAppUtils::Params::isEndable(
"pause")) {
66 return d_ptr->pause();
69 QHash<QString, Feature> sendData = {};
70 auto userParams = QuasarAppUtils::Params::getUserParamsMap();
71 for (
auto val = userParams.begin(); val != userParams.end(); ++val) {
73 bool fIgnore = val.key() ==
"verbose" || val.key() ==
"fileLog";
79 sendData.insert(val.key(),
Feature{val.key(), val.value()});
82 if (!d_ptr->sendCmd(sendData)) {
86 QTimer::singleShot(1000,
nullptr, []() {
98 d_ptr->setEcho(
false);
100 if (!d_ptr->connectToHost(
false)) {
104 _disableFinished =
true;
106 return d_ptr->stop();
110 QuasarAppUtils::Help::Section
help {
111 {QObject::tr(
"Options that available after start"), {
112 {
"stop", QObject::tr(
"Stop a service")},
113 {
"pause", QObject::tr(
"Pause a service")},
114 {
"resume", QObject::tr(
"Resume a service")}
129 QuasarAppUtils::Help::Options options;
131 for (
const auto& feature:
features ) {
132 QString cmd, description;
133 if (feature.arg().isNull()) {
136 cmd = QString(
"-%0 value").arg(feature.cmd());
139 description = feature.description();
141 if (!feature.example().isEmpty()) {
142 description +=
". Example : " + feature.example();
145 options.insert(cmd, description);
148 QuasarAppUtils::Help::print(options);
153 if (responce.size() == 1 && responce.firstKey().isEmpty()) {
154 std::cout << responce.first().toByteArray().toStdString();
158 QuasarAppUtils::Help::Options options;
160 for(
auto iter = responce.begin(); iter != responce.end(); ++iter) {
161 options.insert(iter.key(), iter.value().toString());
164 QuasarAppUtils::Help::print(options);
168 if (!_disableFinished)
169 QCoreApplication::exit(0);
173 return d_ptr->features();
176void Controller::printDefaultHelp()
const {
178 auto quasarappHelp = QuasarAppUtils::Params::getHelp();
179 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.