libfilezilla
Loading...
Searching...
No Matches
process.hpp
Go to the documentation of this file.
1#ifndef LIBFILEZILLA_PROCESS_HEADER
2#define LIBFILEZILLA_PROCESS_HEADER
3
4#include "libfilezilla.hpp"
5#include "fsresult.hpp"
6#include "event.hpp"
7#include "time.hpp"
8
12
13#include <vector>
14
15namespace fz {
16class event_handler;
19class thread_pool;
20
21
27{
29 read = 0x1,
30
32 write = 0x2,
33};
34
36struct process_event_type;
37
38class process;
39
54
61class FZ_PUBLIC_SYMBOL process final
62{
63public:
66
71 process(thread_pool & pool, event_handler & handler);
72
75 process(process const&) = delete;
76 process& operator=(process const&) = delete;
77
79 enum class io_redirection {
81 redirect,
82
84 none,
85
87 closeall,
88
90 redirect_except_stderr
91 };
92
106 bool spawn(native_string const& cmd, std::vector<native_string> const& args = std::vector<native_string>(), io_redirection redirect_mode = io_redirection::redirect);
107
108 bool spawn(std::vector<native_string> const& command_with_args, io_redirection redirect_mode = io_redirection::redirect);
109
111 bool spawn(impersonation_token const& it, native_string const& cmd, std::vector<native_string> const& args, io_redirection redirect_mode = io_redirection::redirect);
112
114 bool spawn(impersonation_token const& it, native_string const& cmd, std::vector<native_string> const& args, io_redirection redirect_mode, logger_interface &logger);
115
116#ifndef FZ_WINDOWS
123 bool spawn(native_string const& cmd, std::vector<native_string> const& args, std::vector<int> const& extra_fds, io_redirection redirect_mode = io_redirection::redirect);
124
125 bool spawn(impersonation_token const& it, native_string const& cmd, std::vector<native_string> const& args, std::vector<int> const& extra_fds, io_redirection redirect_mode = io_redirection::redirect);
126
127 bool spawn(impersonation_token const& it, native_string const& cmd, std::vector<native_string> const& args, std::vector<int> const& extra_fds, io_redirection redirect_mode, logger_interface &logger);
128#endif
129
135 void kill();
136
149 bool stop(duration const& timeout = {});
150
157 rwresult read(void* buffer, size_t len);
158
164 rwresult write(void const* buffer, size_t len);
165
166 inline rwresult write(std::string_view const& s) {
167 return write(s.data(), s.size());
168 }
169
170#if FZ_WINDOWS
174 void* handle() const;
175#endif
176
177private:
178 class impl;
179 impl* impl_;
180};
181
182
191bool FZ_PUBLIC_SYMBOL spawn_detached_process(std::vector<native_string> const& cmd_with_args);
192
193#if !FZ_WINDOWS
203class FZ_PUBLIC_SYMBOL forkblock final
204{
205public:
206 forkblock();
207 ~forkblock();
208
209 forkblock(forkblock const&) = delete;
210 forkblock& operator=(forkblock const&) = delete;
211};
212#endif
213
214}
215
216#endif
Definition buffer.hpp:200
The duration class represents a time interval in milliseconds.
Definition time.hpp:298
Definition event_handler.hpp:63
Impersonation tokens for a given user can be used to spawn processes running as that user.
Definition impersonation.hpp:213
Abstract interface for logging strings.
Definition logger.hpp:51
rwresult write(void const *buffer, size_t len)
Write data data process.
process(thread_pool &pool, event_handler &handler)
Creates instance with non-blocking event-based redirected communication.
void * handle() const
Returns the HANDLE of the process.
bool spawn(impersonation_token const &it, native_string const &cmd, std::vector< native_string > const &args, io_redirection redirect_mode, logger_interface &logger)
Creates a process running under the user represented by the impersonation token, logging platform-spe...
rwresult read(void *buffer, size_t len)
Read data from process.
bool spawn(native_string const &cmd, std::vector< native_string > const &args=std::vector< native_string >(), io_redirection redirect_mode=io_redirection::redirect)
Start the process.
process()
Creates instance for blocking I/O.
~process()
If process still running, calls process::kill().
bool stop(duration const &timeout={})
Stops the spawned process.
io_redirection
IO redirection modes.
Definition process.hpp:79
@ redirect
Redirect the child's stdin/out/err to pipes which will be interacted with through fz::process::read a...
Definition process.hpp:81
bool spawn(impersonation_token const &it, native_string const &cmd, std::vector< native_string > const &args, io_redirection redirect_mode=io_redirection::redirect)
Creates a process running under the user represented by the impersonation token.
Holds the result of read/write operations.
Definition fsresult.hpp:80
This is the recommended event class.
Definition event.hpp:68
A dumb thread-pool for asynchronous tasks.
Definition thread_pool.hpp:64
Declares event_base and simple_event<>.
result and rwresult wrappers for dealing with file system errors.
Sets some global macros and further includes string.hpp.
The namespace used by libfilezilla.
Definition apply.hpp:17
simple_event< process_event_type, process *, process_event_flag > process_event
Definition process.hpp:53
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition string.hpp:69
bool spawn_detached_process(std::vector< native_string > const &cmd_with_args)
Starts a detached process.
process_event_flag
The type of a process event.
Definition process.hpp:27
@ read
Data has become available.
Definition process.hpp:29
@ write
data can be written.
Definition process.hpp:32
Assorted classes dealing with time.