Cppcheck
processexecutor.h
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2024 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 #ifndef PROCESSEXECUTOR_H
20 #define PROCESSEXECUTOR_H
21 
22 #include "cppcheck.h"
23 #include "executor.h"
24 
25 #include <cstddef>
26 #include <list>
27 #include <string>
28 #include <utility>
29 
30 class Settings;
31 class ErrorLogger;
32 class SuppressionList;
33 struct FileSettings;
34 class FileWithDetails;
35 
36 /// @addtogroup CLI
37 /// @{
38 
39 /**
40  * This class will take a list of filenames and settings and check then
41  * all files using threads.
42  */
43 class ProcessExecutor : public Executor {
44 public:
45  ProcessExecutor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand);
46  ProcessExecutor(const ProcessExecutor &) = delete;
48 
49  unsigned int check() override;
50 
51 private:
52  /**
53  * Read from the pipe, parse and handle what ever is in there.
54  * @return False in case of an recoverable error - will exit process on others
55  */
56  bool handleRead(int rpipe, unsigned int &result, const std::string& filename);
57 
58  /**
59  * @brief Check load average condition
60  * @param nchildren - count of currently ran children
61  * @return true - if new process can be started
62  */
63  bool checkLoadAverage(size_t nchildren);
64 
65  /**
66  * @brief Reports internal errors related to child processes
67  * @param msg The error message
68  */
69  void reportInternalChildErr(const std::string &childname, const std::string &msg);
70 
72 };
73 
74 /// @}
75 
76 #endif // PROCESSEXECUTOR_H
std::function< int(std::string, std::vector< std::string >, std::string, std::string &)> ExecuteCmdFn
Definition: cppcheck.h:62
This is an interface, which the class responsible of error logging should implement.
Definition: errorlogger.h:214
This class will take a list of filenames and settings and check then all files using threads.
Definition: executor.h:43
This class will take a list of filenames and settings and check then all files using threads.
void reportInternalChildErr(const std::string &childname, const std::string &msg)
Reports internal errors related to child processes.
CppCheck::ExecuteCmdFn mExecuteCommand
bool checkLoadAverage(size_t nchildren)
Check load average condition.
ProcessExecutor(const ProcessExecutor &)=delete
bool handleRead(int rpipe, unsigned int &result, const std::string &filename)
Read from the pipe, parse and handle what ever is in there.
unsigned int check() override
ProcessExecutor(const std::list< FileWithDetails > &files, const std::list< FileSettings > &fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
ProcessExecutor & operator=(const ProcessExecutor &)=delete
This is just a container for general settings so that we don't need to pass individual values to func...
Definition: settings.h:95
class for handling suppressions
Definition: suppressions.h:42
File settings.
Definition: filesettings.h:57