use crate::compiler::ColorMode;
use crate::coordinator::{CoordinatorInfo, DistInfo};
use std::ffi::OsString;
/// A client request.
#[derive(Serialize, Deserialize, Debug)]
pub enum Request {
/// Zero the server's statistics.
ZeroStats,
/// Get coordinator statistics.
GetStats,
/// Get dist status.
DistStatus,
/// Shut the coordinator down gracefully.
Shutdown,
/// Execute a compile or fetch a cached compilation result.
Compile(Compile),
ClearCache,
}
/// A coordinator response.
#[derive(Serialize, Deserialize, Debug)]
pub enum Response {
/// Response for `Request::Compile`.
Compile(CompileResponse),
/// Response for `Request::GetStats`, containing coordinator statistics.
Stats(Box<CoordinatorInfo>),
/// Response for `Request::DistStatus`, containing client info.
DistStatus(DistInfo),
/// Response for `Request::Shutdown`, containing coordinator statistics.
ShuttingDown(Box<CoordinatorInfo>),
/// Second response for `Request::Compile`, containing the results of the compilation.
CompileFinished(CompileFinished),
/// Response for Request::ClearCache.
ClearCacheComplete,
}
/// Possible responses from the coordinator for a `Compile` request.
#[derive(Serialize, Deserialize, Debug)]
pub enum CompileResponse {
/// The compilation was started.
CompileStarted,
/// The coordinator could not handle this compilation request.
UnhandledCompile,
/// The compiler was not supported.
UnsupportedCompiler(OsString),
}
/// Information about a finished compile, either from cache or executed locally.
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct CompileFinished {
/// The return code of the compile process, if available.
pub retcode: Option<i32>,
/// The signal that terminated the compile process, if available.
pub signal: Option<i32>,
/// The compiler's stdout.
pub stdout: Vec<u8>,
/// The compiler's stderr.
pub stderr: Vec<u8>,
/// The state of any compiler options passed to control color output.
pub color_mode: ColorMode,
}
/// The contents of a compile request from a client.
#[derive(Serialize, Deserialize, Debug)]
pub struct Compile {
/// The full path to the compiler executable.
pub exe: OsString,
/// The current working directory in which to execute the compile.
pub cwd: OsString,
/// The commandline arguments passed to the compiler.
pub args: Vec<OsString>,
/// The environment variables present when the compiler was executed, as (var, val).
pub env_vars: Vec<(OsString, OsString)>,
}