1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2021 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
20 #ifndef THREADRESULT_H
21 #define THREADRESULT_H
22 
23 #include <QMutex>
24 #include <QObject>
25 #include <QStringList>
26 #include "color.h"
27 #include "errorlogger.h"
28 #include "importproject.h"
29 
30 class ErrorItem;
31 
32 /// @addtogroup GUI
33 /// @{
34 
35 /**
36  * @brief Threads use this class to obtain new files to process and to publish results
37  *
38  */
39 class ThreadResult : public QObject, public ErrorLogger {
40     Q_OBJECT
41 public:
42     ThreadResult();
43     virtual ~ThreadResult();
44 
45     /**
46      * @brief Get next unprocessed file
47      * @return File path
48      */
49     QString getNextFile();
50 
51     ImportProject::FileSettings getNextFileSettings();
52 
53     /**
54      * @brief Set list of files to check
55      * @param files List of files to check
56      */
57     void setFiles(const QStringList &files);
58 
59     void setProject(const ImportProject &prj);
60 
61     /**
62      * @brief Clear files to check
63      *
64      */
65     void clearFiles();
66 
67     /**
68      * @brief Get the number of files to check
69      *
70      */
71     int getFileCount() const;
72 
73     /**
74      * ErrorLogger methods
75      */
76     void reportOut(const std::string &outmsg, Color c = Color::Reset) override;
77     void reportErr(const ErrorMessage &msg) override;
78     void bughuntingReport(const std::string &str) override;
79 
80 public slots:
81 
82     /**
83      * @brief Slot threads use to signal this class that a specific file is checked
84      * @param file File that is checked
85      */
86     void fileChecked(const QString &file);
87 signals:
88     /**
89      * @brief Progress signal
90      * @param value Current progress
91      * @param description Description of the current stage
92      */
93     void progress(int value, const QString& description);
94 
95     /**
96      * @brief Signal of a new error
97      *
98      * @param item Error data
99      */
100     void error(const ErrorItem &item);
101 
102     /**
103      * @brief Signal of a new log message
104      *
105      * @param logline Log line
106      */
107     void log(const QString &logline);
108 
109     /**
110      * @brief Signal of a debug error
111      *
112      * @param item Error data
113      */
114     void debugError(const ErrorItem &item);
115 
116     /** @brief bug hunting report */
117     void bughuntingReportLine(QString line);
118 
119 protected:
120 
121     /**
122      * @brief Mutex
123      *
124      */
125     mutable QMutex mutex;
126 
127     /**
128      * @brief List of files to check
129      *
130      */
131     QStringList mFiles;
132 
133     std::list<ImportProject::FileSettings> mFileSettings;
134 
135     /**
136      * @brief Max progress
137      *
138      */
139     quint64 mMaxProgress;
140 
141     /**
142      * @brief Current progress
143      *
144      */
145     quint64 mProgress;
146 
147     /**
148      * @brief Current number of files checked
149      *
150      */
151     unsigned long mFilesChecked;
152 
153     /**
154      * @brief Total number of files
155      *
156      */
157     unsigned long mTotalFiles;
158 };
159 /// @}
160 #endif // THREADRESULT_H
161