hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Process.hpp
Go to the documentation of this file.
1 
14 #ifndef PROCESS_HPP
15 #define PROCESS_HPP
16 
17 #include <signal.h>
18 #include <functional>
19 #include <Poco/Process.h>
20 
21 #include "ProcessHandle.hpp"
22 
23 void signalHandler(int signum);
24 
25 namespace HCE
26 {
27 //-----------------------------------------------------------------------------
28 /* list all possible exit status use in launch */
30 {
31  SUCCESS=0, // exit status success (no errors)
32  ERROR_FDOPEN_WRITE=1, // error fdopen() write
33  ERROR_FDOPEN_READ=2, // error fdopen() read
34  ERROR_WAITPID=3 // error waitpid()
35 };
36 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
38 class Process
39 {
40 public:
41  typedef std::function<void(pid_t)> CallbackFunction;
42 
43  static ProcessHandle launch(
44  const std::string& command,
45  const Poco::Process::Args& args,
46  const std::string& initialDirectory,
47  std::istream& in,
48  std::ostream& out,
49  std::ostream& err,
50  const Poco::Process::Env& env,
51  CallbackFunction fn);
52 
53  static ProcessHandle launch(
54  const std::string& command,
55  const Poco::Process::Args& args,
56  const std::string& initialDirectory,
57  std::istream& in,
58  std::ostream& out,
59  std::ostream& err,
60  const Poco::Process::Env& env);
61 
62  static ProcessHandle launch(
63  const std::string& command,
64  const Poco::Process::Args& args,
65  std::istream& in,
66  std::ostream& out,
67  std::ostream& err,
68  const Poco::Process::Env& env);
69 
70  static ProcessHandle launch(
71  const std::string& command,
72  const Poco::Process::Args& args,
73  const std::string& initialDirectory,
74  std::istream& in,
75  std::ostream& out,
76  std::ostream& err);
77 
78  static ProcessHandle launch(
79  const std::string& command,
80  const Poco::Process::Args& args,
81  std::istream& in,
82  std::ostream& out,
83  std::ostream& err);
84 
85  static ProcessHandle launch(
86  const std::string& command,
87  const Poco::Process::Args& args,
88  const std::string& initialDirectory);
89 
90  static ProcessHandle launch(
91  const std::string& command,
92  const Poco::Process::Args& args);
93 
94  static void requestKill(ProcessHandle& handle, unsigned int signum);
95  static void requestKill(pid_t pid, unsigned int signum);
96 
97  static void requestKill(ProcessHandle& handle);
98  static void requestKill(pid_t pid);
99 
100  static void requestTermination(ProcessHandle& handle);
101  static void requestTermination(pid_t pid);
102 
103  static std::string processStatus(ProcessHandle& handle);
104  static std::string processStatus(pid_t pid);
105 
106  static ProcessHandle processParent(ProcessHandle& handle);
107  static ProcessHandle processParent(pid_t pid);
108 
109  static bool isExistProcess(ProcessHandle& handle);
110  static bool isExistProcess(pid_t pid);
111 
112  static pid_t id(void);
113 private:
114  static void writeToPipe(int fd, const std::string& inputData="");
115  static void readFromPipe(int fd, std::stringstream& os);
116  static std::string toString(std::istream& in);
117 };
118 //-----------------------------------------------------------------------------
119 //-----------------------------------------------------------------------------
120 } // end namespace HCE
121 
122 #endif // PROCESS_HPP