1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
---|---|
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "route.h" |
6 | |
7 | #include "serverapplication.h" |
8 | |
9 | #include <QString> |
10 | #include <QDir> |
11 | |
12 | namespace newlsp { |
13 | |
14 | ProjectKey Route::key(QProcess *value) const |
15 | { |
16 | return savedProcs.key(value); |
17 | } |
18 | |
19 | QList<ProjectKey> Route::keys() const |
20 | { |
21 | return savedProcs.keys(); |
22 | } |
23 | |
24 | QProcess *Route::value(const ProjectKey &key) |
25 | { |
26 | QString language = QString::fromStdString(key.language); |
27 | QProcess *ret{nullptr}; |
28 | ret = savedProcs.value(key); |
29 | return ret; |
30 | } |
31 | |
32 | void Route::save(const ProjectKey &key, QProcess *const value) |
33 | { |
34 | if (!savedProcs.value(key)) { |
35 | QObject::connect(value, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), |
36 | this, &Route::deleteProc, Qt::DirectConnection); |
37 | savedProcs.insert(key, value); |
38 | } |
39 | } |
40 | |
41 | void Route::deleteProc(int exitCode, QProcess::ExitStatus exitstatus) |
42 | { |
43 | Q_UNUSED(exitCode) |
44 | Q_UNUSED(exitstatus) |
45 | QProcess *proc = qobject_cast<QProcess*>(sender()); |
46 | if (proc) { |
47 | ProjectKey key = Route::key(proc); |
48 | savedProcs.remove(key); |
49 | proc->kill(); |
50 | proc->deleteLater(); |
51 | } |
52 | } |
53 | |
54 | } |
55 |