| 42 | } |
| 43 | |
| 44 | void ServerApplication::start() |
| 45 | { |
| 46 | _globalServer = this; |
| 47 | QObject::connect(qApp, &QCoreApplication::destroyed, qApp, [=](){ |
| 48 | delete this; |
| 49 | }); |
| 50 | if (ServerCmdParse::parentPid()) { |
| 51 | unsigned int ppid = ServerCmdParse::parentPid().value(); |
| 52 | d->globalPPidWatcher = new QTimer; |
| 53 | d->globalPPidWatcher->setInterval(300); |
| 54 | QObject::connect(d->globalPPidWatcher, &QTimer::timeout, [=](){ |
| 55 | QProcess process; |
| 56 | #ifdef __linux__ |
| 57 | process.setProgram("ps"); |
| 58 | process.setArguments({"--pid", QString::number(ppid)}); |
| 59 | process.start(); |
| 60 | process.waitForFinished(); |
| 61 | QByteArray queryPidLines = process.readAllStandardOutput(); |
| 62 | if (queryPidLines.isEmpty() || queryPidLines.count('\n') < 2) { |
| 63 | lspServErr << "not found parent pid:" |
| 64 | << std::to_string(ppid) |
| 65 | << "qApp quit"; |
| 66 | exit(1001); |
| 67 | } |
| 68 | #endif |
| 69 | }); |
| 70 | d->globalPPidWatcher->start(); |
| 71 | } |
| 72 | |
| 73 | auto doStdioLauch = [=](){ |
| 74 | if (!d->stdinParser) { |
| 75 | d->stdinParser = new StdinJsonRpcParser; |
| 76 | QObject::connect(d->stdinParser, &StdinJsonRpcParser::readedJsonObject, |
| 77 | this, &ServerApplication::identifyJsonObject, |
| 78 | Qt::ConnectionType::DirectConnection); |
| 79 | d->stdinParser->start(); |
| 80 | } |
| 81 | lspServOut << "Initialization succeeded, mode's stdio"; |
| 82 | }; |
| 83 | |
| 84 | if (ServerCmdParse::mode()) { |
| 85 | std::string mode = ServerCmdParse::mode().value(); |
| 86 | if (mode == newlsp::tcp.toStdString()) { |
| 87 | lspServErr << "This function is not implemented yet. " |
| 88 | "It is started in stdio mode by default"; |
| 89 | } |
| 90 | if (ServerCmdParse::mode() == newlsp::stdio.toStdString()) { |
| 91 | doStdioLauch(); |
| 92 | } |
| 93 | } |
| 94 | doStdioLauch(); |
| 95 | } |
| 96 | |
| 97 | ServerApplication::ServerApplication(const QCoreApplication &app) |
| 98 | : ServerCmdParse (app) |
no test coverage detected