aboutsummaryrefslogtreecommitdiff
path: root/alsa/src/communication.rs
blob: b55a78650b36d0892ebfa7c5a2b6a33d496aecba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::sync::mpsc::*;
use swaystatus_plugin::*;

pub(crate) mod pipe_chan;

#[repr(C)]
pub enum MessagesFromMain {
    Quit,
    Refresh
}

pub struct SenderForMain {
    sender : Sender<MessagesFromMain>,
}

impl<'p> SenderForMain {
    pub fn new(sender : Sender<MessagesFromMain>) -> Self {
        Self { sender }
    }
    
    fn send(&self, message : MessagesFromMain) -> Result<(), PluginCommunicationError> {
        self.sender.send(message).map_err(|_| PluginCommunicationError)
    }
}

impl MsgMainToModule for SenderForMain {
    fn send_quit(&self) -> Result<(),PluginCommunicationError> {
        self.send(MessagesFromMain::Quit)
    }
    fn send_refresh(&self) -> Result<(),PluginCommunicationError> {
        self.send(MessagesFromMain::Refresh)
    }
}