chiark / gitweb /
bundles: rework ListBundles return value
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 May 2021 21:14:00 +0000 (22:14 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 May 2021 21:14:00 +0000 (22:14 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/bin/otter.rs
src/bundles.rs
src/commands.rs
src/mgmtchannel.rs
src/prelude.rs

index 5873b979dff43a9a907f67c0cc17cffcb3dade70..606b699e8e4248e676cbb9b60431d8c84618fc5d 100644 (file)
@@ -250,7 +250,8 @@ fn execute_and_respond<R,W>(cs: &mut CommandStreamData, cmd: MgmtCommand,
       let (_ig, auth) = cs.check_acl(&ag, &mut igu, PCH::Instance,
                                     TP_ACCESS_BUNDLES)?;
       let bundles = bundles.by(auth);
-      MR::Bundles(bundles.list())
+      let bundles = bundles.list();
+      MR::Bundles { bundles }
     }
 
     MC::ListGames { all } => {
index 5e378878382ffbcf18a7ab9ed599ac6fc509d070..edf02006b925446e0027ab48f4ecae6cae13aae9 100644 (file)
@@ -1388,11 +1388,10 @@ mod list_bundles {
     let resp = chan.cmd(&MC::ListBundles {
       game: instance_name.clone(),
     })?;
-    if_let!{ MR::Bundles(bundles) = resp;
+    if_let!{ MR::Bundles { bundles } = resp;
              else throw!(anyhow!("unexpected {:?}", &resp)) };
-    for (index, note) in bundles.into_iter().enumerate() {
-      if_let!{ Some(note) = note; else continue; }
-      println!("{} {:?}", bundles::Index::try_from(index).unwrap(), &note);
+    for (id, state) in bundles {
+      println!("{} {:?}", id, &state);
     }
   }
 
index b9c56bfd0dcd20696632184d35b7418286d7ade6..b8459b72ea9209e751e1db55fa49a028753ec4dd 100644 (file)
@@ -55,8 +55,6 @@ pub struct InstanceBundles {
   bundles: Vec<Option<Note>>,
 }
 
-pub type MgmtList = Vec<Option<Note>>;
-
 #[derive(Debug,Clone,Serialize,Deserialize)]
 pub struct Note {
   pub kind: Kind,
@@ -180,7 +178,14 @@ fn incorporate_bundle(ib: &mut InstanceBundles, ig: &mut Instance,
 impl InstanceBundles {
   pub fn new() -> Self { InstanceBundles{ bundles: default() } }
 
-  pub fn list(&self) -> MgmtList { self.bundles.clone() }
+  pub fn list(&self) -> MgmtBundleList {
+    self.bundles.iter().enumerate().filter_map(|(index, slot)| {
+      let note = slot.as_ref()?;
+      let index = index.try_into().unwrap();
+      Some((Id { index, kind: note.kind },
+            note.state.clone()))
+    }).collect()
+  }
 
   #[throws(IE)]
   pub fn load_game_bundles(ig: &mut Instance) -> Self {
index 6f1205eea0e77c00fcd36fc0cd8a179080b9824e..63c169acff8fa6add89258e1ba5f5fe79fcdb94c 100644 (file)
@@ -92,9 +92,11 @@ pub enum MgmtResponse {
   AccountsList(Vec<Arc<AccountName>>),
   GamesList(Vec<Arc<InstanceName>>),
   LibraryItems(Vec<shapelib::ItemEnquiryData>),
-  Bundles(bundles::MgmtList),
+  Bundles { bundles: MgmtBundleList },
 }
 
+pub type MgmtBundleList = BTreeMap<bundles::Id, bundles::State>;
+
 #[derive(Debug,Serialize,Deserialize)]
 pub enum MgmtGameInstruction {
   Noop,
index 58a890ead9f60dee8b7b751b9dad22b4d98c0508..3869b8bcfb9c9021661ce282ab4390c2a4e50eea 100644 (file)
@@ -81,7 +81,7 @@ impl MgmtChannel {
     let (resp, mut rbulk)= self.read.read_withbulk().context("read response")?;
     match &resp {
       Fine | AccountsList{..} | GamesList{..} |
-      LibraryItems(_) | Bundles(..) => { },
+      LibraryItems(_) | Bundles{..} => { },
       AlterGame { error: None, .. } => { },
       Error { error } => {
         Err(error.clone()).context(
index 77683e20d5b9ba66783ede5bee822e1096b5bc44..70847be91353c0269301ea0fa81673c096185c66 100644 (file)
@@ -126,7 +126,7 @@ pub use crate::bundles::{self, InstanceBundles};
 pub use crate::commands::{AccessTokenInfo, AccessTokenReport, MgmtError};
 pub use crate::commands::{MgmtCommand, MgmtResponse};
 pub use crate::commands::{MgmtGameInstruction, MgmtGameResponse};
-pub use crate::commands::{MgmtGameUpdateMode};
+pub use crate::commands::{MgmtBundleList, MgmtGameUpdateMode};
 pub use crate::config::*;
 pub use crate::debugreader::DebugReader;
 pub use crate::error::*;