aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-12-16 21:05:42 +0800
committercrupest <crupest@outlook.com>2023-12-16 21:05:42 +0800
commitc9555b5649bd1e886f96276eb392d65fffe2eb47 (patch)
tree1adcb8efb151379c3c51c226a460a5adf01b581a
parent8f7505d7fd35058870a4a937ca9670e383778dca (diff)
downloadcru-c9555b5649bd1e886f96276eb392d65fffe2eb47.tar.gz
cru-c9555b5649bd1e886f96276eb392d65fffe2eb47.tar.bz2
cru-c9555b5649bd1e886f96276eb392d65fffe2eb47.zip
Bootstrap subprocess.
l---------.clangd1
-rw-r--r--.gitignore5
-rw-r--r--cru-words.txt1
-rw-r--r--include/cru/common/Event.h1
-rw-r--r--include/cru/common/Format.h2
-rw-r--r--include/cru/common/Range.h21
-rw-r--r--include/cru/common/SelfResolvable.h1
-rw-r--r--include/cru/common/SubProcess.h54
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/SubProcess.cpp6
10 files changed, 75 insertions, 18 deletions
diff --git a/.clangd b/.clangd
new file mode 120000
index 00000000..abaa2620
--- /dev/null
+++ b/.clangd
@@ -0,0 +1 @@
+build/clangd \ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 2d2573ea..c9d4e88a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,8 +4,5 @@
build
-vcpkg_installed
-vcpkg
-
compile_commands.json
-.clangd
+
diff --git a/cru-words.txt b/cru-words.txt
index fbd1a289..e9967942 100644
--- a/cru-words.txt
+++ b/cru-words.txt
@@ -1,5 +1,6 @@
emscripten
clangd
+IWYU
# cmake
endfunction
diff --git a/include/cru/common/Event.h b/include/cru/common/Event.h
index 564afc40..14d68833 100644
--- a/include/cru/common/Event.h
+++ b/include/cru/common/Event.h
@@ -5,7 +5,6 @@
#include <algorithm>
#include <functional>
-#include <initializer_list>
#include <memory>
#include <utility>
#include <vector>
diff --git a/include/cru/common/Format.h b/include/cru/common/Format.h
index a15e7ce7..e6935343 100644
--- a/include/cru/common/Format.h
+++ b/include/cru/common/Format.h
@@ -1,9 +1,9 @@
#pragma once
-#include <double-conversion/double-conversion.h>
#include "Exception.h"
#include "String.h"
+#include <double-conversion/double-conversion.h>
#include <charconv>
namespace cru {
diff --git a/include/cru/common/Range.h b/include/cru/common/Range.h
index e61d90ca..edc2ec55 100644
--- a/include/cru/common/Range.h
+++ b/include/cru/common/Range.h
@@ -3,23 +3,22 @@
namespace cru {
struct Range final {
- constexpr static Range FromTwoSides(gsl::index start, gsl::index end) {
+ constexpr static Range FromTwoSides(Index start, Index end) {
return Range(start, end - start);
}
- constexpr static Range FromTwoSides(gsl::index start, gsl::index end,
- gsl::index offset) {
+ constexpr static Range FromTwoSides(Index start, Index end, Index offset) {
return Range(start + offset, end - start);
}
constexpr Range() = default;
- constexpr Range(const gsl::index position, const gsl::index count = 0)
+ constexpr Range(const Index position, const Index count = 0)
: position(position), count(count) {}
- gsl::index GetStart() const { return position; }
- gsl::index GetEnd() const { return position + count; }
+ Index GetStart() const { return position; }
+ Index GetEnd() const { return position + count; }
- void ChangeEnd(gsl::index new_end) { count = new_end - position; }
+ void ChangeEnd(Index new_end) { count = new_end - position; }
Range Normalize() const {
auto result = *this;
@@ -30,14 +29,14 @@ struct Range final {
return result;
}
- Range CoerceInto(gsl::index min, gsl::index max) const {
- auto coerce = [min, max](gsl::index index) {
+ Range CoerceInto(Index min, Index max) const {
+ auto coerce = [min, max](Index index) {
return index > max ? max : (index < min ? min : index);
};
return Range::FromTwoSides(coerce(GetStart()), coerce(GetEnd()));
}
- gsl::index position = 0;
- gsl::index count = 0;
+ Index position = 0;
+ Index count = 0;
};
} // namespace cru
diff --git a/include/cru/common/SelfResolvable.h b/include/cru/common/SelfResolvable.h
index c8acd4b9..0cbb35fb 100644
--- a/include/cru/common/SelfResolvable.h
+++ b/include/cru/common/SelfResolvable.h
@@ -2,7 +2,6 @@
#include "PreConfig.h"
#include <memory>
-#include <type_traits>
namespace cru {
template <typename T>
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
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index b8d2ae16..e6048d44 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -6,6 +6,7 @@ add_library(CruBase
String.cpp
StringToNumberConverter.cpp
StringUtil.cpp
+ SubProcess.cpp
io/CFileStream.cpp
io/Stream.cpp
io/Resource.cpp
diff --git a/src/common/SubProcess.cpp b/src/common/SubProcess.cpp
new file mode 100644
index 00000000..7b585e2f
--- /dev/null
+++ b/src/common/SubProcess.cpp
@@ -0,0 +1,6 @@
+#include "cru/common/SubProcess.h"
+
+namespace cru {
+
+}
+