From: Ian Jackson Date: Wed, 24 Mar 2021 19:56:16 +0000 (+0000) Subject: updates: Allow ToRecompute to return UnpreparedUpdates X-Git-Tag: otter-0.5.0~441 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c06713c8d87683307efbc2057407abd2e971c183;p=otter.git updates: Allow ToRecompute to return UnpreparedUpdates Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index ff5ac09f..54320492 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -106,7 +106,7 @@ fn api_piece_op(form: Json>) let mut ig = iad.gref.lock()?; ig.save_game_later(); - ToRecalculate::with(|mut to_recalculate| { + let (ok, unprepared_outer) = ToRecalculate::with(|mut to_recalculate| { let r = (||{ let g = &mut *ig; @@ -208,7 +208,15 @@ fn api_piece_op(form: Json>) &mut gs.pieces, &mut gs.occults, &g.ipieces)) - })?; + }); + + if let Some(unprepared) = unprepared_outer { + let mut prepub = PrepareUpdatesBuffer::new(&mut ig, None, None); + unprepared(&mut prepub); + prepub.finish(); + } + + ok?; "" } diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 90e7b096..4d1cc87b 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -797,7 +797,7 @@ fn execute_for_game<'cs, 'igr, 'ig: 'igr>( mut insns: Vec, how: MgmtGameUpdateMode) -> MgmtResponse { - ToRecalculate::with(|mut to_permute| { + let (ok, uu) = ToRecalculate::with(|mut to_permute| { let r = (||{ let mut uh = UpdateHandler::from_how(how); @@ -855,7 +855,16 @@ fn execute_for_game<'cs, 'igr, 'ig: 'igr>( &mut gs.occults, &g.ipieces) }) - })? + }); + + if let Some(uu) = uu { + let mut ig = igu.by_mut(Authorisation::authorise_any()); + let mut prepub = PrepareUpdatesBuffer::new(&mut ig, None, None); + uu(&mut prepub); + prepub.finish(); + } + + ok? } #[derive(Debug,Default)] diff --git a/src/hidden.rs b/src/hidden.rs index 0287af9a..e3289706 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -701,14 +701,23 @@ mod recompute { pub struct ToRecalculate { outdated: HashSet, } - #[derive(Debug)] - pub struct Implemented(()); + #[must_use] + pub struct Implemented(UnpreparedUpdates); + impl Debug for Implemented { + #[throws(fmt::Error)] + fn fmt(&self, f: &mut Formatter) { + write!(f, "Implemented({})", + if self.0.is_some() { "Some(..)" } else { "None" })?; + } + } impl ToRecalculate { - pub fn with (R, Implemented)>(f: F) -> R { + pub fn with (R, Implemented)> + (f: F) -> (R, UnpreparedUpdates) + { let to_recalculate = ToRecalculate { outdated: default() }; - let (r, Implemented(())) = f(to_recalculate); - r + let (r, Implemented(uu)) = f(to_recalculate); + (r, uu) } pub fn mark_dirty(&mut self, occid: OccId) { self.outdated.insert(occid); } pub fn implement(self, @@ -724,7 +733,7 @@ mod recompute { consistency_check(gplayers, gpieces, goccults); - Implemented(()) + Implemented(None) } } }