代码拉取完成,页面将自动刷新
同步操作将从 tredy6t/QtService 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <QApplication>
#include <iostream>
#include <string>
#include <map>
#include "CustomService.h"
#include "ServiceHandle.h"
enum ServiceCmdType
{
kServiceCmdTypeUnknown = -1,
kServiceCmdTypeHelp,
kServiceCmdTypeCommon,
kServiceCmdTypeInstall,
kServiceCmdTypeUninstall,
kServiceCmdTypeStart,
kServiceCmdTypeStop
};
std::map<std::string, ServiceCmdType> mapCmd
{
{ "help", kServiceCmdTypeHelp },
{ "common", kServiceCmdTypeCommon },
{ "install", kServiceCmdTypeInstall },
{ "uninstall", kServiceCmdTypeUninstall },
{ "start", kServiceCmdTypeStart },
{ "stop", kServiceCmdTypeStop }
};
void Usage()
{
std::cout << "Usage: QtService [command] [option1] [option2]\n";
std::cout << "command and options:\n";
std::cout << "\tinstall [service name]: install service, <service name> is optional, default is \"Custom Qt Server\" \n";
std::cout << "\tstop [service name]: stop service\n";
std::cout << "\tstart [service name]: start service\n";
std::cout << "\tuninstall [service name]: uninstall service\n";
std::cout << "\tcommon: start process in common mode\n";
std::cout << "\thelp: show usage\n";
}
bool CheckValidCmd(const std::string& strCmd, ServiceCmdType& nCmd)
{
bool bValid = false;
auto itFind = mapCmd.find(strCmd);
if(itFind != mapCmd.end()) {
bValid = true;
nCmd = itFind->second;
}
return bValid;
}
// install/uninstall/start/stop service via inner action
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
if(argc > 1) {
int nIndex = 0;
std::string strCmd = argv[++nIndex];
ServiceCmdType nCmdType = kServiceCmdTypeUnknown;
if(!CheckValidCmd(strCmd, nCmdType) || kServiceCmdTypeHelp == nCmdType) {
Usage();
return 0;
}
if(kServiceCmdTypeCommon == nCmdType) {
SERVER_CTRL_INST.start();
auto nCode = a.exec();
SERVER_CTRL_INST.stop();
return nCode;
}
if(argc < 3) {
Usage();
return 0;
}
std::string strServiceName = argv[++nIndex];
switch(nCmdType) {
case kServiceCmdTypeInstall: {
SERVER_CTRL_INST.InstallService(strServiceName);
break;
}
case kServiceCmdTypeUninstall: {
SERVER_CTRL_INST.UninstallService(strServiceName);
break;
}
case kServiceCmdTypeStart: {
SERVER_CTRL_INST.StartService(strServiceName);
break;
}
case kServiceCmdTypeStop: {
SERVER_CTRL_INST.StopService(strServiceName);
break;
}
default:
break;
}
return 0;
}
// start exe with service(default)
CustomService service(argc, argv);
auto nCode = service.exec();
service.DoClean();
return nCode;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。