X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FProcess.hpp;h=0e84ccdd1e1f1c5c4fb5ed1b81ca623e21498997;hb=7f829070c9a5e4e036b483863e5ee75a3a824c38;hp=3efe96383ef36bae5956c18754a26ba3d7385447;hpb=fd86376a8e7d3f1b09be3d018f772ef884937238;p=blank.git diff --git a/src/app/Process.hpp b/src/app/Process.hpp index 3efe963..0e84ccd 100644 --- a/src/app/Process.hpp +++ b/src/app/Process.hpp @@ -11,12 +11,21 @@ namespace blank { class Process { public: + using Arguments = std::vector; + using Environment = std::vector; + +public: + /// launch process executing the file at given path with + /// given arguments and environment of parent process + Process( + const std::string &path, + const Arguments &args); /// launch process executing the file at given path with - /// given arguments and environment + /// given arguments and given environment Process( const std::string &path, - const std::vector &args, - const std::vector &env); + const Arguments &args, + const Environment &env); ~Process(); public: @@ -24,18 +33,32 @@ public: /// data is taken from given buffer, at most max_len bytes /// @return the number of bytes written std::size_t WriteIn(const void *buffer, std::size_t max_len); + /// close program's input stream + void CloseIn(); + /// read from the process' output stream /// data is stored in the given buffer, at most max_len bytes + /// timeout is the number of milliseconds to wait for the process + /// to produce output, -1 for indefinite /// @return the number of bytes read - std::size_t ReadOut(void *buffer, std::size_t max_len); + std::size_t ReadOut(void *buffer, std::size_t max_len, int timeout); + /// close program's output stream + void CloseOut(); + /// read from the process' error stream /// data is stored in the given buffer, at most max_len bytes + /// timeout is the number of milliseconds to wait for the process + /// to produce output, -1 for indefinite /// @return the number of bytes read - std::size_t ReadErr(void *buffer, std::size_t max_len); + std::size_t ReadErr(void *buffer, std::size_t max_len, int timeout); + /// close program's output stream + void CloseErr(); /// ask the process nicely to terminate /// (except on win32) void Terminate(); + /// check if the process has terminated + bool Terminated(); /// wait until the process exits and fetch its exit status int Join(); @@ -43,9 +66,6 @@ private: struct Impl; std::unique_ptr impl; - bool joined; - int status; - }; }