]> git.localhorst.tv Git - blank.git/blob - src/app/Process.hpp
6f5a5ae6f429806a3a9001885cecd26092c017f7
[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         using Arguments = std::vector<std::string>;
15         using Environment = std::vector<std::string>;
16
17 public:
18         /// launch process executing the file at given path with
19         /// given arguments and environment
20         Process(
21                 const std::string &path,
22                 const Arguments &args,
23                 const Environment &env);
24         ~Process();
25
26 public:
27         /// write to the process' input stream
28         /// data is taken from given buffer, at most max_len bytes
29         /// @return the number of bytes written
30         std::size_t WriteIn(const void *buffer, std::size_t max_len);
31         /// close program's input stream
32         void CloseIn();
33
34         /// read from the process' output stream
35         /// data is stored in the given buffer, at most max_len bytes
36         /// @return the number of bytes read
37         std::size_t ReadOut(void *buffer, std::size_t max_len);
38         /// close program's output stream
39         void CloseOut();
40
41         /// read from the process' error stream
42         /// data is stored in the given buffer, at most max_len bytes
43         /// @return the number of bytes read
44         std::size_t ReadErr(void *buffer, std::size_t max_len);
45         /// close program's output stream
46         void CloseErr();
47
48         /// ask the process nicely to terminate
49         /// (except on win32)
50         void Terminate();
51         /// check if the process has terminated
52         bool Terminated();
53         /// wait until the process exits and fetch its exit status
54         int Join();
55
56 private:
57         struct Impl;
58         std::unique_ptr<Impl> impl;
59
60 };
61
62 }
63
64 #endif