10 #ifndef DAQ_ASYNC_PROCESS_HPP
11 #define DAQ_ASYNC_PROCESS_HPP
18 #include <boost/process.hpp>
19 #include <boost/signals2/signal.hpp>
20 #include <boost/thread/future.hpp>
36 [[nodiscard]]
virtual boost::future<int>
Initiate() = 0;
43 virtual std::optional<pid_t>
GetPid() const noexcept = 0;
52 virtual std::error_code
Abort() noexcept = 0;
62 virtual std::error_code
Signal(
int sig) noexcept = 0;
67 virtual std::vector<std::
string> const&
GetArguments() const noexcept = 0;
82 using
SigOutStream = boost::signals2::signal<
void(pid_t, std::
string const&)>;
135 explicit AsyncProcess(boost::asio::io_context& ctx, std::vector<std::string> args);
148 [[nodiscard]] boost::future<int>
Initiate()
override;
149 std::optional<pid_t>
GetPid()
const noexcept
override;
158 std::error_code
Abort() noexcept
override;
168 std::error_code
Signal(
int sig) noexcept
override;
174 bool IsRunning()
const noexcept
override;
176 std::vector<std::string>
const&
GetArguments() const noexcept
override {
185 boost::signals2::connection
ConnectStdout(SigOutStream::slot_type
const& slot)
override {
186 return m_stdout.signal.connect(slot);
188 boost::signals2::connection
ConnectStderr(SigOutStream::slot_type
const& slot)
override {
189 return m_stderr.signal.connect(slot);
209 boost::process::async_pipe pipe;
210 boost::asio::streambuf buffer = boost::asio::streambuf();
226 void CheckCompleted();
229 void AsyncReadStream(Pipe&);
231 boost::asio::io_context& m_io_ctx;
232 std::vector<std::string> m_args;
240 boost::process::child m_proc;
242 std::optional<Result> m_result;
243 boost::promise<int> m_promise;
Interface to asynchronous process.
virtual boost::future< int > Initiate()=0
Initiates async operation by executing the specified process.
virtual std::error_code Abort() noexcept=0
Aborts the operation by terminating process which completes the operation.
virtual std::vector< std::string > const & GetArguments() const noexcept=0
virtual boost::signals2::connection ConnectStdout(SigOutStream::slot_type const &slot)=0
Connect slot to line-buffered stdout signal.
virtual ~AsyncProcessIf()
boost::signals2::signal< void(pid_t, std::string const &)> SigOutStream
Signal type for stdout/stderr signals.
virtual std::error_code Signal(int sig) noexcept=0
Send signal to process.
virtual boost::signals2::connection ConnectStderr(SigOutStream::slot_type const &slot)=0
Connect slot to line-buffered stderr signal.
virtual bool IsRunning() const noexcept=0
virtual std::optional< pid_t > GetPid() const noexcept=0
Get PID.
Represents a subprocess as an asynchronous operation.
boost::signals2::connection ConnectStdout(SigOutStream::slot_type const &slot) override
Signal type for stdout/stderr signals.
std::vector< std::string > const & GetArguments() const noexcept override
boost::signals2::connection ConnectStderr(SigOutStream::slot_type const &slot) override
Signal type for stdout/stderr signals.
Utility class that represents a result and an error.