|
UCILoader 1.1.2
Small C++ library that allows user to connect to a chess engines via UCI protocol.
|
Cross-platform wrapper for managing a chess engine process. More...
#include <ProcessWrapper.h>
Inherited by UnixProcessWrapper, and WindowsEngineProcess.
Public Member Functions | |
| virtual | ~ProcessWrapper ()=default |
| Virtual destructor that ensures listening thread is properly joined. | |
| virtual std::shared_ptr< AbstractPipeWriter > | getWriter ()=0 |
| Get the pipe writer for the process's standard input. | |
| virtual void | kill ()=0 |
| Immediately terminate the underlying process. | |
| virtual bool | isAlive () const =0 |
| Check if the process is alive using OS calls. | |
| virtual bool | healthCheck () |
| Perform a safe health check of the process. | |
| void | listen (std::function< void(std::string)> lineReceiver, std::function< void()> onCrash=[](){}) |
| Start a background listening thread for reading process output lines. | |
Protected Member Functions | |
| virtual std::shared_ptr< AbstractPipeReader > | getReader ()=0 |
| Get the pipe reader for the process's standard output. | |
Cross-platform wrapper for managing a chess engine process.
ProcessWrapper provides platform-independent abstraction for creating, monitoring, and communicating with external processes (chess engines). It handles:
While ProcessWrapper is typically passed to an EngineInstance for automatic management, it can also be used independently for custom use cases (see proxy example in examples/ folder).
Platform-Specific Implementations:
Typical Usage:
|
protectedpure virtual |
Get the pipe reader for the process's standard output.
This is a protected method implemented by platform-specific subclasses. Used internally by listen() to set up line reading from the process.
|
pure virtual |
Get the pipe writer for the process's standard input.
Used to send commands to the process. The returned writer can be used independently at any time after construction.
|
inlinevirtual |
Perform a safe health check of the process.
Unlike isAlive(), this method handles platform-specific edge cases:
Safe to call repeatedly without performance penalty.
|
pure virtual |
Check if the process is alive using OS calls.
|
pure virtual |
Immediately terminate the underlying process.
Uses platform-specific OS calls to forcefully kill the process. This is safe to call multiple times.
|
inline |
Start a background listening thread for reading process output lines.
| lineReceiver | Callback function invoked for each line received from the process. The string is passed without the trailing newline character. |
| onCrash | Optional callback invoked when the listening thread terminates due to pipe closure (process crash or EOF). Defaults to a no-op lambda. |
This method spawns a background thread that continuously:
Important Notes:
Usage Example: