1#ifndef SDL3PP_PROCESS_H_
2#define SDL3PP_PROCESS_H_
4#include <SDL3/SDL_process.h>
5#include "SDL3pp_iostream.h"
6#include "SDL3pp_properties.h"
7#include "SDL3pp_stdinc.h"
85 SDL_PROCESS_STDIO_INHERITED;
89 SDL_PROCESS_STDIO_NULL;
115 constexpr Process(std::nullptr_t =
nullptr) noexcept
116 : m_resource(
nullptr)
128 : m_resource(resource)
184 Process(
const char*
const* args,
bool pipe_stdio);
264 std::swap(m_resource, other.m_resource);
278 m_resource =
nullptr;
286 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
390 if (data.
empty())
return {};
391 size_t sz = data.
size() /
sizeof(T);
462 void Kill(
bool force);
494 bool Wait(
bool block,
int* exitcode);
610 return Process(args, pipe_stdio);
614 : m_resource(SDL_CreateProcess(args, pipe_stdio))
619 : m_resource(SDL_CreateProcessWithProperties(props))
698namespace prop::process {
700constexpr auto CREATE_ARGS_POINTER = SDL_PROP_PROCESS_CREATE_ARGS_POINTER;
702constexpr auto CREATE_ENVIRONMENT_POINTER =
703 SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER;
705#if SDL_VERSION_ATLEAST(3, 4, 0)
707constexpr auto CREATE_WORKING_DIRECTORY_STRING =
708 SDL_PROP_PROCESS_CREATE_WORKING_DIRECTORY_STRING;
712constexpr auto CREATE_STDIN_NUMBER = SDL_PROP_PROCESS_CREATE_STDIN_NUMBER;
714constexpr auto CREATE_STDIN_POINTER = SDL_PROP_PROCESS_CREATE_STDIN_POINTER;
716constexpr auto CREATE_STDOUT_NUMBER = SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER;
718constexpr auto CREATE_STDOUT_POINTER = SDL_PROP_PROCESS_CREATE_STDOUT_POINTER;
720constexpr auto CREATE_STDERR_NUMBER = SDL_PROP_PROCESS_CREATE_STDERR_NUMBER;
722constexpr auto CREATE_STDERR_POINTER = SDL_PROP_PROCESS_CREATE_STDERR_POINTER;
724constexpr auto CREATE_STDERR_TO_STDOUT_BOOLEAN =
725 SDL_PROP_PROCESS_CREATE_STDERR_TO_STDOUT_BOOLEAN;
727constexpr auto CREATE_BACKGROUND_BOOLEAN =
728 SDL_PROP_PROCESS_CREATE_BACKGROUND_BOOLEAN;
730#if SDL_VERSION_ATLEAST(3, 4, 0)
732constexpr auto CREATE_CMDLINE_STRING = SDL_PROP_PROCESS_CREATE_CMDLINE_STRING;
736constexpr auto PID_NUMBER = SDL_PROP_PROCESS_PID_NUMBER;
738constexpr auto STDIN_POINTER = SDL_PROP_PROCESS_STDIN_POINTER;
740constexpr auto STDOUT_POINTER = SDL_PROP_PROCESS_STDOUT_POINTER;
742constexpr auto STDERR_POINTER = SDL_PROP_PROCESS_STDERR_POINTER;
744constexpr auto BACKGROUND_BOOLEAN = SDL_PROP_PROCESS_BACKGROUND_BOOLEAN;
779 return {
CheckError(SDL_GetProcessProperties(process))};
817 auto data =
static_cast<char*
>(SDL_ReadProcess(process, &size, exitcode));
852 return {SDL_GetProcessInput(process)};
884 return {SDL_GetProcessOutput(process)};
951 return SDL_WaitProcess(process, block, exitcode);
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr bool empty() const
True if size() == 0.
Definition SDL3pp_ownPtr.h:74
T * release()
Release control on object.
Definition SDL3pp_ownPtr.h:91
constexpr size_t size() const
Size.
Definition SDL3pp_ownPtr.h:83
An opaque handle representing a system process.
Definition SDL3pp_process.h:110
constexpr auto operator<=>(const Process &other) const noexcept=default
Comparison.
constexpr Process(Process &&other) noexcept
Move constructor.
Definition SDL3pp_process.h:136
constexpr ProcessRaw release() noexcept
Retrieves underlying ProcessRaw and clear this.
Definition SDL3pp_process.h:275
Process & operator=(const Process &other)=delete
Assignment operator.
constexpr Process & operator=(Process &&other) noexcept
Assignment operator.
Definition SDL3pp_process.h:262
constexpr ProcessRaw get() const noexcept
Retrieves underlying ProcessRaw.
Definition SDL3pp_process.h:272
constexpr Process(const Process &other) noexcept=delete
Copy constructor.
constexpr Process(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition SDL3pp_process.h:115
OwnArray< T > ReadAs(int *exitcode=nullptr)
Read all the output from a process.
Definition SDL3pp_process.h:387
~Process()
Destructor.
Definition SDL3pp_process.h:259
constexpr Process(ProcessRaw resource) noexcept
Constructs from raw Process.
Definition SDL3pp_process.h:127
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
StringResult ReadProcess(ProcessRef process, int *exitcode=nullptr)
Read all the output from a process.
Definition SDL3pp_process.h:814
IOStreamRef GetOutput()
Get the IOStream associated with process standard output.
Definition SDL3pp_process.h:887
void Destroy()
Destroy a previously created process object.
Definition SDL3pp_process.h:977
SDL_ProcessIO ProcessIO
Description of where standard I/O should be directed when creating a process.
Definition SDL3pp_process.h:82
IOStreamRef GetProcessOutput(ProcessRef process)
Get the IOStream associated with process standard output.
Definition SDL3pp_process.h:882
PropertiesRef GetProperties() const
Get the properties associated with a process.
Definition SDL3pp_process.h:782
PropertiesRef GetProcessProperties(ProcessRef process)
Get the properties associated with a process.
Definition SDL3pp_process.h:777
Process CreateProcess(const char *const *args, bool pipe_stdio)
Create a new process.
Definition SDL3pp_process.h:608
constexpr ProcessIO PROCESS_STDIO_APP
The I/O stream is connected to a new IOStream that the application can read or write.
Definition SDL3pp_process.h:95
constexpr ProcessIO PROCESS_STDIO_NULL
The I/O stream is ignored.
Definition SDL3pp_process.h:88
void KillProcess(ProcessRef process, bool force)
Stop a process.
Definition SDL3pp_process.h:911
bool Wait(bool block, int *exitcode)
Wait for a process to finish.
Definition SDL3pp_process.h:954
Process CreateProcessWithProperties(PropertiesRef props)
Create a new process with the specified properties.
Definition SDL3pp_process.h:693
bool WaitProcess(ProcessRef process, bool block, int *exitcode)
Wait for a process to finish.
Definition SDL3pp_process.h:949
void Kill(bool force)
Stop a process.
Definition SDL3pp_process.h:916
void DestroyProcess(ProcessRaw process)
Destroy a previously created process object.
Definition SDL3pp_process.h:975
SDL_Process * ProcessRaw
Alias to raw representation for Process.
Definition SDL3pp_process.h:37
IOStreamRef GetProcessInput(ProcessRef process)
Get the IOStream associated with process standard input.
Definition SDL3pp_process.h:850
IOStreamRef GetInput()
Get the IOStream associated with process standard input.
Definition SDL3pp_process.h:855
constexpr ProcessIO PROCESS_STDIO_REDIRECT
The I/O stream is redirected to an existing IOStream.
Definition SDL3pp_process.h:98
constexpr ProcessIO PROCESS_STDIO_INHERITED
The I/O stream is inherited from the application.
Definition SDL3pp_process.h:84
StringResult Read(int *exitcode=nullptr)
Read all the output from a process.
Definition SDL3pp_process.h:821
Main include header for the SDL3pp library.
Reference for IOStream.
Definition SDL3pp_iostream.h:1627
Reference for Process.
Definition SDL3pp_process.h:503
~ProcessRef()
Destructor.
Definition SDL3pp_process.h:555
constexpr ProcessRef(ProcessRaw resource) noexcept
Constructs from raw Process.
Definition SDL3pp_process.h:513
constexpr ProcessRef(Process &&resource) noexcept
Constructs from Process.
Definition SDL3pp_process.h:537
constexpr ProcessRef(ProcessRef &&other) noexcept
Move constructor.
Definition SDL3pp_process.h:549
constexpr ProcessRef(const ProcessRef &other) noexcept
Copy constructor.
Definition SDL3pp_process.h:543
constexpr Process(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition SDL3pp_process.h:115
ProcessRef & operator=(const ProcessRef &other) noexcept
Assignment operator.
Definition SDL3pp_process.h:558
constexpr ProcessRef(const Process &resource) noexcept
Constructs from Process.
Definition SDL3pp_process.h:525
Reference for Properties.
Definition SDL3pp_properties.h:687
A simple std::string-like interface for SDL allocated strings.
Definition SDL3pp_strings.h:147