9#include <QCoreApplication>
11#include <QLibraryInfo>
13#include <QStandardPaths>
17#include "serviceprivate.h"
25 QuasarAppUtils::Params::parseParams(argc, argv);
26 d_ptr =
new ServicePrivate(
this);
35 qint64 pid = PCommon::instance()->getPidFromPidfile();
36 if (pid == QCoreApplication::applicationPid()) {
37 QFile pidFile(PCommon::instance()->getPidfile());
55 for (
const auto& i: data) {
56 if (list.contains(i)) {
58 sendResuylt(QString(
"The process of a command %0 with argumets: %1 is failed")
59 .arg(i.cmd(), i.arg()));
62 commandList += i.toString() +
" ";
66 if (commandList.size()) {
69 for (
const auto&i : list) {
70 stringList += i.toString() +
" ";
75 result[
"Error"] =
"Wrong command! The commands : " + commandList +
" is not supported";
76 result[
"Available commands"] = stringList;
87 return d_ptr->sendCmdResult(result);
91 return d_ptr->sendCmdResult({{
"Result", result}});
97 QTimer::singleShot(1000,
nullptr, [](){
98 QCoreApplication::quit();
119void ServiceBase::printDefaultHelp() {
121 serviceHelp.unite(QuasarAppUtils::Params::getHelp());
123 serviceHelp.unite({{QObject::tr(
"Options that available befor install"),{
124 {
"start / s", QObject::tr(
"Start a service in console")},
125 {
"daemon / d", QObject::tr(
"Start a service as a daemon")},
126 {
"install / i / -install username", QObject::tr(
"Install a service. Add user name if you want to run service from custom user. Example: -install username")},
127 {
"unistall / u", QObject::tr(
"unistall a service")},
131 QuasarAppUtils::Help::Options optionsList;
132 for (
const auto& cmd : features) {
133 optionsList.insert(cmd.cmd(), cmd.description());
136 serviceHelp.unite({{
"Available commands of the service:", optionsList}});
138 QuasarAppUtils::Help::print(serviceHelp);
159 bool printHelp = !QuasarAppUtils::Params::size() ||
160 QuasarAppUtils::Params::isEndable(
"h") ||
161 QuasarAppUtils::Params::isEndable(
"help");
168 bool fStart = QuasarAppUtils::Params::isEndable(
"start") || QuasarAppUtils::Params::isEndable(
"s");
169 bool fDaemon = QuasarAppUtils::Params::isEndable(
"daemon") || QuasarAppUtils::Params::isEndable(
"d");
171 if (QuasarAppUtils::Params::isEndable(
"install") || QuasarAppUtils::Params::isEndable(
"i")) {
172 if (!d_ptr->install(QuasarAppUtils::Params::getArg(
"install")))
177 if (QuasarAppUtils::Params::isEndable(
"uninstall") || QuasarAppUtils::Params::isEndable(
"u")) {
178 if (!d_ptr->uninstall())
183 if (fStart || fDaemon) {
186 if (!d_ptr->startDeamon())
191 QTimer::singleShot(0,
nullptr, [
this]() {
193 std::this_thread::sleep_for (std::chrono::milliseconds(1000));
196 if (!d_ptr->start()) {
202 QTimer::singleShot(0,
nullptr, [
this]() {
209 return core()->exec();
The Controller class provide control functionality for your service.
QuasarAppUtils::Help::Section help() const
help This method return help of the Controller.
virtual bool handleReceive(const Feature &data)=0
handleReceive This method invoked when service receive a request from terminal. Override this method ...
void setCore(QCoreApplication *core)
setCore This method sets new object of the core application.
virtual int exec()
exec This is main method of the service. Use this like a QCoreApplication::exec.
void onPause() override
onPause Called when get pause command from terminal. The Default implementation do nothing.
void onResume() override
onResume Called when get resume command from terminal. The Default implementation do nothing.
virtual void createApplication()=0
createApplication Default implementation create a Application object and parse arguments.
bool sendResuylt(const QVariantMap &result)
sendResuylt - Call this method for send responce from service to tour controller.
QSet< Feature > supportedFeatures() override
supportedFeatures
void onStop() override
onStop Called when get stop command from terminal. The default implementation of this method invoke a...
Controller * controller()
controller This method return the local controller object. If the controller object is not inited the...
void handleReceiveData(const QSet< Feature > &data) override final
handleReceiveData - This method invoice when service receive new command from terminal of controller ...
QCoreApplication * core()
core This method return a pointer to instance of the core application.
ServiceBase(int argc, char *argv[])
ServiceBase This is main constructor of the service.
The Patronum namespace - It is main name space of Patronum Library. The Patronum library support the ...
@ FailedToStart
This error ocured when user srvice failed to start.
@ ServiceUnavailable
Service is unavailable. Try send start command or restart the service manually.
@ UnsupportedPlatform
This error ocured when service not supportded using platform.