From c9555b5649bd1e886f96276eb392d65fffe2eb47 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 16 Dec 2023 21:05:42 +0800 Subject: Bootstrap subprocess. --- include/cru/common/SubProcess.h | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 include/cru/common/SubProcess.h (limited to 'include/cru/common/SubProcess.h') 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 +#include +#include + +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 arguments, + std::vector environments); + void Wait(std::optional 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 -- cgit v1.2.3