hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
StarterExecutor.hpp
Go to the documentation of this file.
1 
14 #ifndef STARTER_EXECUTOR_HPP
15 #define STARTER_EXECUTOR_HPP
16 
17 #include <Poco/Pipe.h>
18 #include <Poco/PipeStream.h>
19 
20 #include <iostream>
21 #include <sstream>
22 
23 namespace HCE
24 {
25 //-----------------------------------------------------------------------------
26 namespace starter_const
27 {
28  const std::string starterFileName = "hce-starter-bash.sh";
29  const std::string starterPathName = "/usr/bin";
30  const std::string starterTemplate = "#!/bin/bash\neval \"$1 < $2\"";
31 } // end namespace starter_const
32 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 {
36 public:
38  {
42  };
43 public:
44  explicit StarterExecutor(const std::string& homeDir_, const std::string& starterFileName_="");
45  virtual ~StarterExecutor(void);
46 
47  pid_t execute(const std::string& cmd, const std::string& inputStream, const Poco::Process::Env& env);
48  unsigned int wait(unsigned int waitTime=0);
49 
50  void setStarterFileName(const std::string& starterFileName_);
51  std::string getStarterFileName(void) const {return starterFileName;}
52 
53  void setHomeDir(const std::string& homeDir_);
54  std::string getHomeDir(void) const {return homeDir;}
55  std::string getStarterFullName(void) const;
56 
57  std::stringstream& getOutStream(void) {return outStream;}
58  std::stringstream& getErrStream(void) {return errStream;}
59 
60  pid_t getPid(void) const {return pid;}
61  StatusExecution getStatusExecution(void) const {return statusExecution;}
62 
63  static bool isExistShellScript(const std::string& homeDir, const std::string& scriptName);
64  static bool canExecuteShellScript(const std::string& homeDir, const std::string& scriptName);
65 private:
66  static std::string getStarterFullName(const std::string& homeDir, const std::string& scriptName);
67 private:
68  Poco::Pipe outPipe;
69  Poco::Pipe errPipe;
70  Poco::PipeInputStream outInputStream;
71  Poco::PipeInputStream errInputStream;
72 
73  std::stringstream outStream;
74  std::stringstream errStream;
75 
76  std::string starterFileName;
77  std::string homeDir;
78  std::string inputStreamFileName;
79  pid_t pid;
80 
81  StatusExecution statusExecution;
82 };
83 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
85 } // end namespace HCE
86 
87 #endif // STARTER_EXECUTOR_HPP