8 #ifndef WPIUTIL_WPI_UV_PROCESS_H_
9 #define WPIUTIL_WPI_UV_PROCESS_H_
13 #include <initializer_list>
17 #include "wpi/ArrayRef.h"
18 #include "wpi/Signal.h"
19 #include "wpi/SmallVector.h"
20 #include "wpi/Twine.h"
21 #include "wpi/uv/Handle.h"
35 struct private_init {};
38 explicit Process(
const private_init&) {}
39 ~
Process() noexcept
override =
default;
62 Option() : m_type(kNone) {}
68 Option(
const std::string& arg) {
69 m_data.str = arg.data();
74 m_data.str = m_strData.c_str();
79 : m_strData(arg.
data(), arg.size()) {
80 m_data.str = m_strData.c_str();
84 : m_strData(arg.
str()) {
85 m_data.str = m_strData.c_str();
88 explicit Option(Type type) : m_type(type) {}
91 std::string m_strData;
115 o.m_strData = env.
str();
116 o.m_data.str = o.m_strData.c_str();
126 o.m_strData = cwd.
str();
127 o.m_data.str = o.m_strData.c_str();
156 Option o(Option::kSetFlags);
157 o.m_data.flags = flags;
166 Option o(Option::kClearFlags);
167 o.m_data.flags = flags;
176 Option o(Option::kStdioIgnore);
177 o.m_data.stdio.index = index;
187 Option o(Option::kStdioInheritFd);
188 o.m_data.stdio.index = index;
189 o.m_data.stdio.fd = fd;
199 Option o(Option::kStdioInheritPipe);
200 o.m_data.stdio.index = index;
201 o.m_data.stdio.pipe = &pipe;
213 Option o(Option::kStdioCreatePipe);
214 o.m_data.stdio.index = index;
215 o.m_data.stdio.pipe = &pipe;
216 o.m_data.stdio.flags = flags;
248 Loop& loop,
const Twine& file, std::initializer_list<Option> options) {
252 template <
typename... Args>
253 static std::shared_ptr<Process> Spawn(Loop& loop,
const Twine& file,
254 const Args&... options) {
271 static std::shared_ptr<Process>
SpawnArray(
const std::shared_ptr<Loop>& loop,
278 const std::shared_ptr<Loop>& loop,
const Twine& file,
279 std::initializer_list<Option> options) {
283 template <
typename... Args>
284 static std::shared_ptr<Process> Spawn(
const std::shared_ptr<Loop>& loop,
286 const Args&... options) {
294 void Kill(
int signum) { Invoke(&uv_process_kill,
GetRaw(), signum); }
302 static int Kill(
int pid,
int signum) noexcept {
return uv_kill(pid, signum); }
320 #endif // WPIUTIL_WPI_UV_PROCESS_H_
uv_process_t * GetRaw() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:288
static Option Gid(uv_gid_t gid)
Set the child process' group id.
Definition: Process.h:145
uv_pid_t GetPid() const noexcept
Get the process ID.
Definition: Process.h:308
static int Kill(int pid, int signum) noexcept
Sends the specified signal to the given PID.
Definition: Process.h:302
static Option StdioCreatePipe(size_t index, Pipe &pipe, unsigned int flags)
Create a pipe between the child and the parent.
Definition: Process.h:212
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
static void DisableStdioInheritance()
Disables inheritance for file descriptors / handles that this process inherited from its parent.
Definition: Process.h:229
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:447
static Option Env(const Twine &env)
Set environment variable for the subprocess.
Definition: Process.h:113
WPILib C++ utilities (wpiutil) namespace.
Definition: EventLoopRunner.h:17
sig::Signal< int64_t, int > exited
Signal generated when the process exits.
Definition: Process.h:314
pointer data()
Return a pointer to the vector's buffer, even if empty().
Definition: SmallVector.h:158
static Option ClearFlags(unsigned int flags)
Clear spawn flags.
Definition: Process.h:165
Structure for Spawn() option temporaries.
Definition: Process.h:46
static Option StdioIgnore(size_t index)
Explicitly ignore a stdio.
Definition: Process.h:175
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static std::shared_ptr< Process > SpawnArray(const std::shared_ptr< Loop > &loop, const Twine &file, ArrayRef< Option > options)
Starts a process.
Definition: Process.h:271
Handle.
Definition: Handle.h:273
static Option SetFlags(unsigned int flags)
Set spawn flags.
Definition: Process.h:155
static Option StdioInherit(size_t index, Pipe &pipe)
Inherit a pipe from the parent process.
Definition: Process.h:198
static Option Uid(uv_uid_t uid)
Set the child process' user id.
Definition: Process.h:135
Pipe handle.
Definition: Pipe.h:31
std::string str() const
Return the twine contents as a std::string.
static std::shared_ptr< Process > SpawnArray(Loop &loop, const Twine &file, ArrayRef< Option > options)
Starts a process.
Event loop.
Definition: Loop.h:39
static Option StdioInherit(size_t index, int fd)
Inherit a file descriptor from the parent process.
Definition: Process.h:186
Process handle.
Definition: Process.h:34
static Option Cwd(const Twine &cwd)
Set the current working directory for the subprocess.
Definition: Process.h:124
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:85
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495
void Kill(int signum)
Sends the specified signal to the process.
Definition: Process.h:294