3#include "AbstractPipe.h"
38 const char*
what() const noexcept
override {
39 return reason.c_str();
90 std::unique_ptr<std::thread> listener =
nullptr;
91 bool healthCheckFailed =
false;
105 virtual std::shared_ptr<AbstractPipeReader>
getReader() = 0;
125 virtual std::shared_ptr<AbstractPipeWriter>
getWriter() = 0;
159 if (!healthCheckFailed && !
isAlive()) {
161 healthCheckFailed =
true;
163 return !healthCheckFailed;
200 void listen(std::function<
void(std::string)> lineReceiver, std::function<
void()> onCrash = [](){}) {
201 assert(listener ==
nullptr);
205 listener = std::make_unique<std::thread>(
206 [scanner, lineReceiver, onCrash]() {
209 lineReceiver(scanner->
getLine());
211 catch (PipeClosedException) {
254 ProcessWrapper* openProcess(
const std::vector<std::string>& args,
const std::string& workingDirectory);
Exception thrown when a process cannot be opened or started.
Definition: ProcessWrapper.h:21
const char * what() const noexcept override
Get the exception message explaining the failure.
Definition: ProcessWrapper.h:38
CanNotOpenProcessException(const std::string &reason)
Constructor for the exception.
Definition: ProcessWrapper.h:31
Blocking line-oriented reader built on top of AbstractPipeReader.
Definition: AbstractPipe.h:202
std::string getLine()
Read the next complete line from the pipe.
Definition: AbstractPipe.cpp:36
Cross-platform wrapper for managing a chess engine process.
Definition: ProcessWrapper.h:88
void listen(std::function< void(std::string)> lineReceiver, std::function< void()> onCrash=[](){})
Start a background listening thread for reading process output lines.
Definition: ProcessWrapper.h:200
virtual void kill()=0
Immediately terminate the underlying process.
virtual std::shared_ptr< AbstractPipeReader > getReader()=0
Get the pipe reader for the process's standard output.
virtual std::shared_ptr< AbstractPipeWriter > getWriter()=0
Get the pipe writer for the process's standard input.
virtual bool isAlive() const =0
Check if the process is alive using OS calls.
virtual ~ProcessWrapper()=default
Virtual destructor that ensures listening thread is properly joined.
virtual bool healthCheck()
Perform a safe health check of the process.
Definition: ProcessWrapper.h:158