1 use crate::compiler::ColorMode; 2 use crate::server::{DistInfo, ServerInfo}; 3 use std::ffi::OsString; 4 5 /// A client request. 6 #[derive(Serialize, Deserialize, Debug)] 7 pub enum Request { 8 /// Zero the server's statistics. 9 ZeroStats, 10 /// Get server statistics. 11 GetStats, 12 /// Get dist status. 13 DistStatus, 14 /// Shut the server down gracefully. 15 Shutdown, 16 /// Execute a compile or fetch a cached compilation result. 17 Compile(Compile), 18 } 19 20 /// A server response. 21 #[derive(Serialize, Deserialize, Debug)] 22 pub enum Response { 23 /// Response for `Request::Compile`. 24 Compile(CompileResponse), 25 /// Response for `Request::GetStats`, containing server statistics. 26 Stats(Box<ServerInfo>), 27 /// Response for `Request::DistStatus`, containing client info. 28 DistStatus(DistInfo), 29 /// Response for `Request::Shutdown`, containing server statistics. 30 ShuttingDown(Box<ServerInfo>), 31 /// Second response for `Request::Compile`, containing the results of the compilation. 32 CompileFinished(CompileFinished), 33 } 34 35 /// Possible responses from the server for a `Compile` request. 36 #[derive(Serialize, Deserialize, Debug)] 37 pub enum CompileResponse { 38 /// The compilation was started. 39 CompileStarted, 40 /// The server could not handle this compilation request. 41 UnhandledCompile, 42 /// The compiler was not supported. 43 UnsupportedCompiler(OsString), 44 } 45 46 /// Information about a finished compile, either from cache or executed locally. 47 #[derive(Serialize, Deserialize, Debug, Default)] 48 pub struct CompileFinished { 49 /// The return code of the compile process, if available. 50 pub retcode: Option<i32>, 51 /// The signal that terminated the compile process, if available. 52 pub signal: Option<i32>, 53 /// The compiler's stdout. 54 pub stdout: Vec<u8>, 55 /// The compiler's stderr. 56 pub stderr: Vec<u8>, 57 /// The state of any compiler options passed to control color output. 58 pub color_mode: ColorMode, 59 } 60 61 /// The contents of a compile request from a client. 62 #[derive(Serialize, Deserialize, Debug)] 63 pub struct Compile { 64 /// The full path to the compiler executable. 65 pub exe: OsString, 66 /// The current working directory in which to execute the compile. 67 pub cwd: OsString, 68 /// The commandline arguments passed to the compiler. 69 pub args: Vec<OsString>, 70 /// The environment variables present when the compiler was executed, as (var, val). 71 pub env_vars: Vec<(OsString, OsString)>, 72 } 73