Skip to content

Commit

Permalink
updatehub-sdk: listener: Add support for Probe callbacks
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
  • Loading branch information
otavio committed Oct 19, 2020
1 parent da4dc0a commit e6d68be
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions updatehub-sdk/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type CallbackFn = dyn Fn(Handler) -> Pin<Box<dyn Future<Output = Result<()>>>>;

#[derive(Default)]
pub struct StateChangeListener {
probe_callbacks: Vec<Box<CallbackFn>>,
download_callbacks: Vec<Box<CallbackFn>>,
install_callbacks: Vec<Box<CallbackFn>>,
reboot_callbacks: Vec<Box<CallbackFn>>,
Expand All @@ -27,6 +28,7 @@ pub struct StateChangeListener {

#[derive(Debug)]
pub enum State {
Probe,
Download,
Install,
Reboot,
Expand Down Expand Up @@ -63,6 +65,7 @@ impl StateChangeListener {
Fut: Future<Output = Result<()>> + 'static,
{
match state {
State::Probe => self.probe_callbacks.push(Box::new(move |d| Box::pin(f(d)))),
State::Download => self.download_callbacks.push(Box::new(move |d| Box::pin(f(d)))),
State::Install => self.install_callbacks.push(Box::new(move |d| Box::pin(f(d)))),
State::Reboot => self.reboot_callbacks.push(Box::new(move |d| Box::pin(f(d)))),
Expand Down Expand Up @@ -100,6 +103,7 @@ impl StateChangeListener {

async fn emit(&self, stream: UnixStream, input: &str) -> Result<()> {
let callbacks = match input {
"probe" => &self.probe_callbacks,
"download" => &self.download_callbacks,
"install" => &self.install_callbacks,
"reboot" => &self.reboot_callbacks,
Expand Down

0 comments on commit e6d68be

Please sign in to comment.