8 #ifndef WPIUTIL_WPI_UV_PROCESS_H_
9 #define WPIUTIL_WPI_UV_PROCESS_H_
16 #include "wpi/ArrayRef.h"
17 #include "wpi/Signal.h"
18 #include "wpi/SmallVector.h"
19 #include "wpi/Twine.h"
20 #include "wpi/uv/Handle.h"
34 struct private_init {};
37 explicit Process(
const private_init&) {}
38 ~
Process() noexcept
override =
default;
61 Option() : m_type(kNone) {}
67 Option(
const std::string& arg) {
68 m_data.str = arg.data();
73 m_data.str = m_strData.c_str();
78 : m_strData(arg.
data(), arg.size()) {
79 m_data.str = m_strData.c_str();
83 : m_strData(arg.
str()) {
84 m_data.str = m_strData.c_str();
87 explicit Option(Type type) : m_type(type) {}
90 std::string m_strData;
114 o.m_strData = env.
str();
115 o.m_data.str = o.m_strData.c_str();
125 o.m_strData = cwd.
str();
126 o.m_data.str = o.m_strData.c_str();
155 Option o(Option::kSetFlags);
156 o.m_data.flags = flags;
165 Option o(Option::kClearFlags);
166 o.m_data.flags = flags;
175 Option o(Option::kStdioIgnore);
176 o.m_data.stdio.index = index;
186 Option o(Option::kStdioInheritFd);
187 o.m_data.stdio.index = index;
188 o.m_data.stdio.fd = fd;
198 Option o(Option::kStdioInheritPipe);
199 o.m_data.stdio.index = index;
200 o.m_data.stdio.pipe = &pipe;
212 Option o(Option::kStdioCreatePipe);
213 o.m_data.stdio.index = index;
214 o.m_data.stdio.pipe = &pipe;
215 o.m_data.stdio.flags = flags;
246 template <
typename... Args>
247 static std::shared_ptr<Process> Spawn(
Loop& loop,
const Twine& file,
248 const Args&... options) {
265 static std::shared_ptr<Process>
SpawnArray(
const std::shared_ptr<Loop>& loop,
271 template <
typename... Args>
272 static std::shared_ptr<Process> Spawn(
const std::shared_ptr<Loop>& loop,
274 const Args&... options) {
282 void Kill(
int signum) { Invoke(&uv_process_kill,
GetRaw(), signum); }
290 static int Kill(
int pid,
int signum) noexcept {
return uv_kill(pid, signum); }
308 #endif // WPIUTIL_WPI_UV_PROCESS_H_
uv_pid_t GetPid() const noexcept
Get the process ID.
Definition: Process.h:296
uv_process_t * GetRaw() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:264
static Option Gid(uv_gid_t gid)
Set the child process' group id.
Definition: Process.h:144
Handle.
Definition: Handle.h:249
static int Kill(int pid, int signum) noexcept
Sends the specified signal to the given PID.
Definition: Process.h:290
static void DisableStdioInheritance()
Disables inheritance for file descriptors / handles that this process inherited from its parent...
Definition: Process.h:228
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
Structure for Spawn() option temporaries.
Definition: Process.h:45
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
static Option StdioCreatePipe(size_t index, Pipe &pipe, unsigned int flags)
Create a pipe between the child and the parent.
Definition: Process.h:211
sig::Signal< int64_t, int > exited
Signal generated when the process exits.
Definition: Process.h:302
Process handle.
Definition: Process.h:33
static std::shared_ptr< Process > SpawnArray(const std::shared_ptr< Loop > &loop, const Twine &file, ArrayRef< Option > options)
Starts a process.
Definition: Process.h:265
static Option Env(const Twine &env)
Set environment variable for the subprocess.
Definition: Process.h:112
Pipe handle.
Definition: Pipe.h:31
static Option StdioIgnore(size_t index)
Explicitly ignore a stdio.
Definition: Process.h:174
static Option ClearFlags(unsigned int flags)
Clear spawn flags.
Definition: Process.h:164
std::string str() const
Return the twine contents as a std::string.
static Option SetFlags(unsigned int flags)
Set spawn flags.
Definition: Process.h:154
static std::shared_ptr< Process > SpawnArray(Loop &loop, const Twine &file, ArrayRef< Option > options)
Starts a process.
Event loop.
Definition: Loop.h:39
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static Option Uid(uv_uid_t uid)
Set the child process' user id.
Definition: Process.h:134
static Option StdioInherit(size_t index, Pipe &pipe)
Inherit a pipe from the parent process.
Definition: Process.h:197
void Kill(int signum)
Sends the specified signal to the process.
Definition: Process.h:282
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495
static Option Cwd(const Twine &cwd)
Set the current working directory for the subprocess.
Definition: Process.h:123
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
pointer data()
Return a pointer to the vector's buffer, even if empty().
Definition: SmallVector.h:151
static Option StdioInherit(size_t index, int fd)
Inherit a file descriptor from the parent process.
Definition: Process.h:185