diff options
author | crupest <crupest@outlook.com> | 2023-12-16 21:05:42 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-12-16 21:05:42 +0800 |
commit | c9555b5649bd1e886f96276eb392d65fffe2eb47 (patch) | |
tree | 1adcb8efb151379c3c51c226a460a5adf01b581a /include/cru/common/SubProcess.h | |
parent | 8f7505d7fd35058870a4a937ca9670e383778dca (diff) | |
download | cru-c9555b5649bd1e886f96276eb392d65fffe2eb47.tar.gz cru-c9555b5649bd1e886f96276eb392d65fffe2eb47.tar.bz2 cru-c9555b5649bd1e886f96276eb392d65fffe2eb47.zip |
Bootstrap subprocess.
Diffstat (limited to 'include/cru/common/SubProcess.h')
-rw-r--r-- | include/cru/common/SubProcess.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/include/cru/common/SubProcess.h b/include/cru/common/SubProcess.h new file mode 100644 index 00000000..341afc5c --- /dev/null +++ b/include/cru/common/SubProcess.h @@ -0,0 +1,54 @@ +#pragma once +#include "Base.h" +#include "String.h" + +#include <chrono> +#include <optional> +#include <vector> + +namespace cru { +enum class PlatformSubProcessStatus { + /** + * @brief The process has not been created and started. + */ + Prepare, + /** + * @brief The process is running now. + */ + Running, + /** + * @brief The process has been exited. + */ + Exited, +}; + +/** + * Interface of a platform process. It is one-time, which means it starts and + * exits and can't start again. + */ +struct IPlatformSubProcess : virtual Interface { + /** + * Create and start a real process. + */ + void Start(String program, std::vector<String> arguments, + std::vector<String> environments); + void Wait(std::optional<std::chrono::milliseconds> wait_time); + void Reap(); + PlatformSubProcessStatus GetStatus() const; + int GetExitCode() const; +}; + +class CRU_BASE_API SubProcess : public Object { + public: + SubProcess(); + + CRU_DELETE_COPY(SubProcess) + + SubProcess(SubProcess&& other); + SubProcess& operator=(SubProcess&& other); + + ~SubProcess(); + + private: +}; +} // namespace cru |