use std::collections::HashSet; use std::path::PathBuf; use tokio::sync::{mpsc, oneshot}; use uuid::Uuid; use super::error::Result; use super::{Update, UpdateStatus, UpdateStoreInfo}; #[derive(Debug)] pub enum UpdateMsg { Update { uuid: Uuid, update: Update, ret: oneshot::Sender>, }, ListUpdates { uuid: Uuid, ret: oneshot::Sender>>, }, GetUpdate { uuid: Uuid, ret: oneshot::Sender>, id: u64, }, Delete { uuid: Uuid, ret: oneshot::Sender>, }, Snapshot { uuids: HashSet, path: PathBuf, ret: oneshot::Sender>, }, Dump { uuids: HashSet, path: PathBuf, ret: oneshot::Sender>, }, GetInfo { ret: oneshot::Sender>, }, } impl UpdateMsg { pub async fn dump( sender: &mpsc::Sender, uuids: HashSet, path: PathBuf, ) -> Result<()> { let (ret, rcv) = oneshot::channel(); let msg = Self::Dump { path, uuids, ret, }; sender.send(msg).await?; rcv.await? } pub async fn update( sender: &mpsc::Sender, uuid: Uuid, update: Update, ) -> Result { let (ret, rcv) = oneshot::channel(); let msg = Self::Update { uuid, update, ret, }; sender.send(msg).await?; rcv.await? } pub async fn get_update( sender: &mpsc::Sender, uuid: Uuid, id: u64, ) -> Result { let (ret, rcv) = oneshot::channel(); let msg = Self::GetUpdate { uuid, id, ret, }; sender.send(msg).await?; rcv.await? } pub async fn list_updates( sender: &mpsc::Sender, uuid: Uuid, ) -> Result> { let (ret, rcv) = oneshot::channel(); let msg = Self::ListUpdates { uuid, ret, }; sender.send(msg).await?; rcv.await? } pub async fn get_info( sender: &mpsc::Sender, ) -> Result { let (ret, rcv) = oneshot::channel(); let msg = Self::GetInfo { ret, }; sender.send(msg).await?; rcv.await? } }