]> git.localhorst.tv Git - blank.git/blob - src/app/Process.hpp
first test for actual program binary
[blank.git] / src / app / Process.hpp
1 #ifndef BLANK_APP_PROCESS_HPP_
2 #define BLANK_APP_PROCESS_HPP_
3
4 #include <memory>
5 #include <string>
6 #include <vector>
7
8
9 namespace blank {
10
11 class Process {
12
13 public:
14         /// launch process executing the file at given path with
15         /// given arguments and environment
16         Process(
17                 const std::string &path,
18                 const std::vector<std::string> &args,
19                 const std::vector<std::string> &env);
20         ~Process();
21
22 public:
23         /// write to the process' input stream
24         /// data is taken from given buffer, at most max_len bytes
25         /// @return the number of bytes written
26         std::size_t WriteIn(const void *buffer, std::size_t max_len);
27         /// read from the process' output stream
28         /// data is stored in the given buffer, at most max_len bytes
29         /// @return the number of bytes read
30         std::size_t ReadOut(void *buffer, std::size_t max_len);
31         /// read from the process' error stream
32         /// data is stored in the given buffer, at most max_len bytes
33         /// @return the number of bytes read
34         std::size_t ReadErr(void *buffer, std::size_t max_len);
35
36         /// ask the process nicely to terminate
37         /// (except on win32)
38         void Terminate();
39         /// wait until the process exits and fetch its exit status
40         int Join();
41
42 private:
43         struct Impl;
44         std::unique_ptr<Impl> impl;
45
46         bool joined;
47         int status;
48
49 };
50
51 }
52
53 #endif