diff --git a/src/commands.rs b/src/commands.rs new file mode 100644 index 0000000..5935fcc --- /dev/null +++ b/src/commands.rs @@ -0,0 +1,18 @@ +use std::fmt::Display; + +use serde::Deserialize; + +#[derive(Debug, Deserialize)] +pub enum Command { + SendMessage { channel: String, message: String }, +} + +impl Display for Command { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::SendMessage { channel, message } => { + write!(f, "[{channel}]: {message}") + } + } + } +} diff --git a/src/event_manager.rs b/src/event_manager.rs index 6a6dfcd..bfe0b1f 100644 --- a/src/event_manager.rs +++ b/src/event_manager.rs @@ -4,14 +4,12 @@ use color_eyre::Result; use nix::{NixPath, sys::stat, unistd::mkfifo}; use tokio::{ io::{AsyncBufReadExt, AsyncWriteExt, BufReader}, - net::{ - unix::pipe, UnixListener, UnixStream - }, - sync::{broadcast, RwLock}, + net::{UnixListener, UnixStream, unix::pipe}, + sync::{RwLock, broadcast, mpsc}, }; use tracing::{error, info}; -use crate::event::Event; +use crate::{commands::Command, event::Event}; // Hard coding for now. Maybe make this a parameter to new. const EVENT_BUF_MAX: usize = 1000; @@ -50,7 +48,7 @@ impl EventManager { } // NB: This assumes it has exclusive control of the FIFO. - pub async fn start_fifo
(path: &P) -> Result<()> + pub async fn start_fifo
(path: &P, command_tx: mpsc::Sender