From: Ian Jackson Date: Tue, 16 Feb 2021 20:35:18 +0000 (+0000) Subject: api: Allow a piece api op to return updates for other pieces X-Git-Tag: otter-0.4.0~431 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0778719630cb8854fb392f1c9a88fe41d0ada3d6;p=otter.git api: Allow a piece api op to return updates for other pieces Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index 2b8545e9..f06ccfc9 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -47,6 +47,12 @@ trait ApiPieceOp: Debug { #[throws(ApiPieceOpError)] fn op(&self, a: ApiPieceOpArgs) -> PieceUpdate; + #[throws(ApiPieceOpError)] + fn op_complex(&self, a: ApiPieceOpArgs) + -> (PieceUpdate, Vec<(PieceId, PieceUpdateOps)>) { + (self.op(a)?, vec![]) + } + #[throws(OnlineError)] fn check_held(&self, pc: &PieceState, player: PlayerId) { if pc.held != None && pc.held != Some(player) { @@ -121,7 +127,7 @@ fn api_piece_op(form: Json>) if u_gen > q_gen { throw!(PieceOpError::Conflict) } form.op.check_held(pc,player)?; let update = - form.op.op(ApiPieceOpArgs { + form.op.op_complex(ApiPieceOpArgs { gs, player, piece, ipieces, p: p.as_ref(), })?; @@ -145,12 +151,13 @@ fn api_piece_op(form: Json>) warn!("api_piece_op ERROR {:?}: {:?}", &form, &err); Err(err)?; }, - Ok(PieceUpdate { wrc, log, ops }) => { + Ok((PieceUpdate { wrc, log, ops }, updates)) => { let mut buf = PrepareUpdatesBuffer::new(g, Some((wrc, client, form.cseq)), Some(1 + log.len())); buf.piece_update(piece, ops); + buf.piece_updates(updates); buf.log_updates(log); debug!("api_piece_op OK: {:?}", &form); diff --git a/src/updates.rs b/src/updates.rs index dbc43437..43f54a29 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -589,6 +589,12 @@ impl<'r> PrepareUpdatesBuffer<'r> { self.us.push(update); } + pub fn piece_updates(&mut self, updates: Vec<(PieceId, PieceUpdateOps)>) { + for (piece, ops) in updates { + self.piece_update(piece, ops); + } + } + pub fn raw_updates(&mut self, mut raw: Vec) { self.us.append(&mut raw) }