aboutsummaryrefslogtreecommitdiff
path: root/pulse/src/communication.rs
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2021-05-02 16:01:55 +0200
committerAndreas Grois <andi@grois.info>2021-05-02 16:01:55 +0200
commitd2fd2da41dbc9c2f19711c14cd68142d5484eb40 (patch)
tree799ae403bd62b37a5011680745d3c2e10d71f5b9 /pulse/src/communication.rs
parent18a96163d730b7e44270603a4c6de071b725db5f (diff)
Factor out all unsafe code into its own module (unfinished)
Diffstat (limited to 'pulse/src/communication.rs')
-rw-r--r--pulse/src/communication.rs28
1 files changed, 20 insertions, 8 deletions
diff --git a/pulse/src/communication.rs b/pulse/src/communication.rs
index c8578b7..cfb800e 100644
--- a/pulse/src/communication.rs
+++ b/pulse/src/communication.rs
@@ -1,5 +1,5 @@
use std::sync::mpsc::*;
-use crate::runnable::*;
+use crate::runnable::pulse::*;
use swaystatus_plugin::*;
pub enum MessagesFromMain {
@@ -9,21 +9,27 @@ pub enum MessagesFromMain {
pub struct SenderForMain {
sender : Sender<MessagesFromMain>,
- pulse_loop : std::sync::Arc<PulseMainLoop>
+ pulse_waker : PulseWakeUp
}
impl<'p> SenderForMain {
- pub fn new(sender : Sender<MessagesFromMain>, pulse_loop : std::sync::Arc<PulseMainLoop>) -> Self {
+ pub fn new(sender : Sender<MessagesFromMain>, pulse_waker : PulseWakeUp) -> Self {
SenderForMain{
sender,
- pulse_loop
+ pulse_waker
}
}
- fn send(&self, message : MessagesFromMain) -> Result<(), PluginCommunicationError>
- {
- //TODO!!!!
- Ok(())
+ fn send(&self, message : MessagesFromMain) -> Result<(), PluginCommunicationError> {
+ if let Ok(_) = self.sender.send(message) {
+ //The cool thing about pulse using poll() is that poll() also wakes up if started after
+ //the actual wake up call. So no need to worry about races, this is inherently sane!
+ self.pulse_waker.wake_up()?;
+ Ok(())
+ }
+ else {
+ Err(PluginCommunicationError{})
+ }
}
}
@@ -35,3 +41,9 @@ impl MsgMainToModule for SenderForMain {
self.send(MessagesFromMain::Refresh)
}
}
+
+impl From<PulseWakeUpError> for PluginCommunicationError {
+ fn from(error : PulseWakeUpError) -> Self {
+ PluginCommunicationError {}
+ }
+}