From: Ian Jackson Date: Sun, 2 May 2021 21:14:00 +0000 (+0100) Subject: bundles: rework ListBundles return value X-Git-Tag: otter-0.6.0~467 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=376aed8e534e623ff64ff0f611855f375a0d49d8;p=otter.git bundles: rework ListBundles return value Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 5873b979..606b699e 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -250,7 +250,8 @@ fn execute_and_respond(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 } => { diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 5e378878..edf02006 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -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(), ¬e); + for (id, state) in bundles { + println!("{} {:?}", id, &state); } } diff --git a/src/bundles.rs b/src/bundles.rs index b9c56bfd..b8459b72 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -55,8 +55,6 @@ pub struct InstanceBundles { bundles: Vec>, } -pub type MgmtList = Vec>; - #[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 { diff --git a/src/commands.rs b/src/commands.rs index 6f1205ee..63c169ac 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -92,9 +92,11 @@ pub enum MgmtResponse { AccountsList(Vec>), GamesList(Vec>), LibraryItems(Vec), - Bundles(bundles::MgmtList), + Bundles { bundles: MgmtBundleList }, } +pub type MgmtBundleList = BTreeMap; + #[derive(Debug,Serialize,Deserialize)] pub enum MgmtGameInstruction { Noop, diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index 58a890ea..3869b8bc 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -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( diff --git a/src/prelude.rs b/src/prelude.rs index 77683e20..70847be9 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -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::*;