chiark / gitweb /
mgmtchannel: Prepare for progress updates
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 10 May 2021 00:52:58 +0000 (01:52 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 10 May 2021 00:52:58 +0000 (01:52 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs
src/commands.rs
src/mgmtchannel.rs

index f9c9457fbcd22adc16877aa0ef8859770d502c9d..791dc8730f7e7ef6cc7f8687058d7cb07994f250 100644 (file)
@@ -1349,7 +1349,7 @@ mod upload_bundle {
       game: instance_name.clone(),
       hash: bundles::Hash(hash.into()), kind,
     };
-    chan.cmd_withbulk(&cmd, &mut f, &mut io::sink())?;
+    chan.cmd_withbulk(&cmd, &mut f, &mut io::sink(), &mut |_|Ok((/*todo*/)))?;
   }
 
   inventory::submit!{Subcommand(
@@ -1452,7 +1452,7 @@ mod download_bundle {
       game: instance_name.clone(),
       id,
     };
-    chan.cmd_withbulk(&cmd, &mut io::empty(), &mut f)
+    chan.cmd_withbulk(&cmd, &mut io::empty(), &mut f, &mut |_| Ok(()))
       .context("download bundle")?;
     f.flush().context("flush bundle file")?;
     if let Some((path, tmp)) = path_tmp {
index 0d221c4afcbc57b8948e01a71fe4cb2eefbbbd68..b17cafdc08839482dbf31b4a09bb11927431a267 100644 (file)
@@ -84,6 +84,7 @@ pub struct AccountDetails {
 #[derive(Debug,Serialize,Deserialize)]
 pub enum MgmtResponse {
   Fine,
+  Progress(ProgressInfo),
   Error { error: MgmtError },
   AlterGame { error: Option<MgmtError>, responses: Vec<MgmtGameResponse> },
   AccountsList(Vec<Arc<AccountName>>),
@@ -133,6 +134,12 @@ pub enum MgmtGameInstruction {
   // RemovePlayer { player: PlayerId },  todo, does a special setacl
 }
 
+#[derive(Debug,Clone,Serialize,Deserialize)]
+pub struct ProgressInfo {
+  count: usize,
+  of: usize,
+}
+
 #[derive(Debug,Serialize,Deserialize)]
 pub struct MgmtPlayerDetails {
   pub nick: Option<String>,
index 3869b8bcfb9c9021661ce282ab4390c2a4e50eea..016b83b5e663f0329e37f1eef2899808f2ec0077 100644 (file)
@@ -69,17 +69,25 @@ impl MgmtChannel {
   }
 
   #[throws(AE)]
-  pub fn cmd_withbulk<U,D>(&mut self, cmd: &MgmtCommand,
-                           up: &mut U, down: &mut D)
-                           -> MgmtResponse
-  where U: Read, D: Write
+  pub fn cmd_withbulk<U,D,P>(&mut self, cmd: &MgmtCommand,
+                             up: &mut U, down: &mut D, progress: &mut P)
+                             -> MgmtResponse
+  where U: Read, D: Write,
+        P: FnMut(ProgressInfo) -> Result<(),AE>,
   {
     use MgmtResponse::*;
     let mut wbulk = self.write.write_withbulk(&cmd).context("send command")?;
     io::copy(up,&mut wbulk).context("copy bulk upload")?;
     wbulk.finish().context("finish sending command and data")?;
-    let (resp, mut rbulk)= self.read.read_withbulk().context("read response")?;
+    let (mut resp, mut rbulk) =
+      self.read.read_withbulk()
+      .context("read response")?;
+    while let MR::Progress(pi) = resp {
+      resp = (&mut rbulk).read_rmp()?;
+      progress(pi)?;
+    }
     match &resp {
+      Progress(_) => panic!(),
       Fine | AccountsList{..} | GamesList{..} |
       LibraryItems(_) | Bundles{..} => { },
       AlterGame { error: None, .. } => { },
@@ -109,7 +117,7 @@ impl MgmtChannel {
 
   #[throws(AE)]
   pub fn cmd(&mut self, cmd: &MgmtCommand) -> MgmtResponse {
-    self.cmd_withbulk(cmd, &mut io::empty(), &mut io::sink())?
+    self.cmd_withbulk(cmd, &mut io::empty(), &mut io::sink(), &mut |_|Ok(()))?
   }
 
   #[throws(AE)]