libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
ProcessManager.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef LIBHOMEGEAR_BASE_PROCESSMANAGER_H
32 #define LIBHOMEGEAR_BASE_PROCESSMANAGER_H
33 
34 #include "../Exception.h"
35 #include "ThreadManager.h"
36 #include "Environment.h"
37 
38 #include <string>
39 #include <vector>
40 #include <memory>
41 #include <functional>
42 #include <signal.h>
43 
44 namespace BaseLib
45 {
46 
53 {
54 public:
55  explicit ProcessException(const std::string& message) : Exception(message) {}
56 };
57 
59 {
60 public:
61  ProcessManager() = delete;
62 
67  static void startSignalHandler();
68 
73  static void startSignalHandler(BaseLib::ThreadManager& threadManager);
74  static void stopSignalHandler();
75  static void stopSignalHandler(BaseLib::ThreadManager& threadManager);
76 
77  static int32_t registerCallbackHandler(std::function<void(pid_t pid, int exitCode, int signal, bool coreDumped)> callbackHandler);
78  static void unregisterCallbackHandler(int32_t id);
79 
80  static std::vector<std::string> splitArguments(const std::string& arguments);
81 
82  static std::string findProgramInPath(const std::string& relativePath);
83 
93  static pid_t system(const std::string& path, const std::vector<std::string>& arguments, int maxFd);
94 
106  static pid_t systemp(const std::string& path, const std::vector<std::string>& arguments, int maxFd, int& stdIn, int& stdOut, int& stdErr);
107 
116  static int32_t exec(const std::string& command, int maxFd, std::string& output);
117 
125  static bool exec(const std::string& command, int maxFd);
126 
135  static FILE* popen2(const std::string& command, const std::string& type, int maxFd, pid_t& pid);
136 private:
137  struct OpaquePointer;
138 };
139 
140 }
141 
142 #endif //LIBHOMEGEAR_BASE_PROCESSMANAGER_H
Definition: ThreadManager.h:44
Exception class for Process.
Definition: ProcessManager.h:52
Definition: BaseLib.cpp:34
ProcessException(const std::string &message)
Definition: ProcessManager.h:55
Definition: ProcessManager.h:58
Base class for all exceptions defined in Homegear.
Definition: Exception.h:41
Definition: ProcessManager.cpp:55