1 | /* |
2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) |
3 | * |
4 | * This program is free software: you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation, either version 3 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | */ |
17 | #ifndef COMPILERMANAGER_H |
18 | #define COMPILERMANAGER_H |
19 | |
20 | #include <QObject> |
21 | #include <QMutex> |
22 | #include "../utils.h" |
23 | #include "../common.h" |
24 | |
25 | class Runner; |
26 | class Compiler; |
27 | class Project; |
28 | struct OJProblemCase; |
29 | using POJProblemCase = std::shared_ptr<OJProblemCase>; |
30 | class CompilerManager : public QObject |
31 | { |
32 | Q_OBJECT |
33 | public: |
34 | explicit CompilerManager(QObject *parent = nullptr); |
35 | |
36 | bool compiling(); |
37 | bool backgroundSyntaxChecking(); |
38 | bool running(); |
39 | |
40 | void compile(const QString& filename, const QByteArray& encoding, bool rebuild, bool silent=false,bool onlyCheckSyntax=false); |
41 | void compileProject(std::shared_ptr<Project> project, bool rebuild, bool silent=false,bool onlyCheckSyntax=false); |
42 | void cleanProject(std::shared_ptr<Project> project); |
43 | void buildProjectMakefile(std::shared_ptr<Project> project); |
44 | void checkSyntax(const QString&filename, const QByteArray& encoding, const QString& content, std::shared_ptr<Project> project); |
45 | void run( |
46 | const QString& filename, |
47 | const QString& arguments, |
48 | const QString& workDir, |
49 | const QStringList& ); |
50 | void runProblem(const QString& filename, const QString& arguments, const QString& workDir, POJProblemCase problemCase); |
51 | void runProblem(const QString& filename, const QString& arguments, const QString& workDir, const QVector<POJProblemCase> &problemCases); |
52 | void stopRun(); |
53 | void stopAllRunners(); |
54 | void stopPausing(); |
55 | void stopCompile(); |
56 | void stopCheckSyntax(); |
57 | bool canCompile(const QString& filename); |
58 | int compileErrorCount() const; |
59 | |
60 | int syntaxCheckErrorCount() const; |
61 | |
62 | int compileIssueCount() const; |
63 | |
64 | int syntaxCheckIssueCount() const; |
65 | |
66 | signals: |
67 | void signalStopAllRunners(); |
68 | |
69 | private slots: |
70 | void doRunProblem(const QString& filename, const QString& arguments, const QString& workDir, const QVector<POJProblemCase> &problemCases); |
71 | void onRunnerTerminated(); |
72 | void onRunnerPausing(); |
73 | void onCompileFinished(); |
74 | void onCompileIssue(PCompileIssue issue); |
75 | void onSyntaxCheckFinished(); |
76 | void onSyntaxCheckIssue(PCompileIssue issue); |
77 | |
78 | private: |
79 | Compiler* mCompiler; |
80 | int mCompileErrorCount; |
81 | int mCompileIssueCount; |
82 | int mSyntaxCheckErrorCount; |
83 | int mSyntaxCheckIssueCount; |
84 | Compiler* mBackgroundSyntaxChecker; |
85 | Runner* mRunner; |
86 | QMutex mCompileMutex; |
87 | QMutex mBackgroundSyntaxCheckMutex; |
88 | QMutex mRunnerMutex; |
89 | }; |
90 | |
91 | class CompileError : public BaseError { |
92 | public: |
93 | explicit CompileError(const QString& reason); |
94 | }; |
95 | |
96 | #endif // COMPILERMANAGER_H |
97 | |