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;
248 #endif // #ifndef DAQ_ASYNC_PROCESS_HPP