From: Ian Jackson Date: Sun, 26 Jul 2020 19:38:51 +0000 (+0100) Subject: command format changes X-Git-Tag: otter-0.2.0~1241 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=ee095a28f8a376050faee3a269e92394d83f8ccd;p=otter.git command format changes --- diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index 1c2f57c4..1159d013 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -68,8 +68,9 @@ from_instance_lock_error!{MgmtError} #[throws(CSE)] fn decode_and_process(cs: &mut CommandStream, s: &str) { let resp = self::decode_process_inner(cs, s) - .unwrap_or_else(|e| MgmtResponse::Error( - MgmtError::ParseFailed(format!("{}", e)))); + .unwrap_or_else(|e| MgmtResponse::Error { + error: MgmtError::ParseFailed(format!("{}", e)) + }); serde_lexpr::to_writer(&mut cs.write, &resp)?; } @@ -191,7 +192,7 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { match cmd { Noop { } => Fine { }, - SetScope(wanted_scope) => { + SetScope{ scope: wanted_scope } => { let authorised : AuthorisedSatisfactory = authorise_scope(cs, &wanted_scope) .map_err(|e| cs.map_auth_err(e)) @@ -200,7 +201,7 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { Fine { } }, - CreateGame(name, subcommands) => { + CreateGame { name, insns } => { let gs = GameState { pieces : Default::default(), players : Default::default(), @@ -216,7 +217,7 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { let gref = Instance::new(name, gs)?; let mut ig = gref.lock()?; - execute_for_game(cs, &mut ig, subcommands, MgmtGameUpdateMode::Bulk) + execute_for_game(cs, &mut ig, insns, MgmtGameUpdateMode::Bulk) .map_err(|e|{ Instance::destroy(ig); e @@ -318,19 +319,19 @@ impl UpdateHandler { #[throws(ME)] fn execute_for_game(cs: &CommandStream, ig: &mut InstanceGuard, - mut subcommands: Vec, + mut insns: Vec, how: MgmtGameUpdateMode) -> MgmtResponse { - let mut subcommands = subcommands.drain(0..).zip(0..); + let mut insns = insns.drain(0..).zip(0..); let mut uh = UpdateHandler::from_how(how); let response = 'subcommands: loop { - let (subcommand, index) = match subcommands.next() { + let (insn, index) = match insns.next() { None => break 'subcommands Fine { }, Some(r) => r, }; - let (upieces, ulogs) = match execute_game_update(&mut ig.gs, subcommand) { - Err(e) => break 'subcommands ErrorAfter(index, e), + let (upieces, ulogs) = match execute_game_insn(&mut ig.gs, insn) { + Err(e) => break 'subcommands ErrorAfter { successes: index, error: e }, Ok(r) => r, }; @@ -343,9 +344,9 @@ fn execute_for_game(cs: &CommandStream, ig: &mut InstanceGuard, } #[throws(ME)] -fn execute_game_update(_gs: &mut GameState, update: MgmtGameUpdate) - -> (Vec<(PieceId,PieceUpdateOp<()>)>, Vec) { - use MgmtGameUpdate::*; +fn execute_game_insn(_gs: &mut GameState, update: MgmtGameInstruction) + -> (Vec<(PieceId,PieceUpdateOp<()>)>, Vec) { + use MgmtGameInstruction::*; match update { Noop { } => (vec![], vec![]), } diff --git a/src/commands.rs b/src/commands.rs index 1f1b6d08..3a411005 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -3,22 +3,22 @@ use crate::imports::*; #[derive(Debug,Serialize,Deserialize)] pub enum MgmtCommand { - Noop(), - SetScope(ManagementScope), - CreateGame(String, Vec), -// AddPiece(Box), + Noop { }, + SetScope { scope: ManagementScope }, + CreateGame { name: String, insns: Vec }, } #[derive(Debug,Serialize,Deserialize)] -pub enum MgmtGameUpdate { - Noop(), +pub enum MgmtGameInstruction { + Noop { }, + // AddPiece(Box), } #[derive(Debug,Serialize,Deserialize)] pub enum MgmtResponse { - Fine(), - Error(MgmtError), - ErrorAfter(usize, MgmtError), + Fine { }, + Error { error: MgmtError }, + ErrorAfter { successes: usize, error: MgmtError }, } #[derive(Debug,Serialize,Deserialize)]