chiark / gitweb /
updates: Allow ToRecompute to return UnpreparedUpdates
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 24 Mar 2021 19:56:16 +0000 (19:56 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 24 Mar 2021 19:56:16 +0000 (19:56 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
daemon/cmdlistener.rs
src/hidden.rs

index ff5ac09f2da2223df1d5410ebf6b1101a4f22112..54320492f9f55e1c2d02045196a512fc20b6217c 100644 (file)
@@ -106,7 +106,7 @@ fn api_piece_op<O: op::Complex>(form: Json<ApiPiece<O>>)
   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<O: op::Complex>(form: Json<ApiPiece<O>>)
                              &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?;
   ""
 }
 
index 90e7b096e912b8bfd6259305ae56d4b749bf2382..4d1cc87b2aa5e0f6f3245d0b1c397d208900e53d 100644 (file)
@@ -797,7 +797,7 @@ fn execute_for_game<'cs, 'igr, 'ig: 'igr>(
   mut insns: Vec<MgmtGameInstruction>,
   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)]
index 0287af9a578faa58b5e58c1e240d72c496b72dbb..e328970682246aa5f836e618d5ef067ad1ba909e 100644 (file)
@@ -701,14 +701,23 @@ mod recompute {
   pub struct ToRecalculate {
     outdated: HashSet<OccId>,
   }
-  #[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, F: FnOnce(Self) -> (R, Implemented)>(f: F) -> R {
+    pub fn with<R, F: FnOnce(Self) -> (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)
     }
   }
 }