mux: remove dep on clientsession/pollable_channel
This commit is contained in:
1 parent
99df89eaa1
commit
b94c4a11f8
2 files changed
+13
-12
No files matched your search
+9
-9
@@ -2,7 +2,6 @@ use crate::mux::pane::{Pane, PaneId};
|
||||
use crate::mux::tab::{Tab, TabId};
|
||||
use crate::mux::window::{Window, WindowId};
|
||||
use crate::ratelim::RateLimiter;
|
||||
use crate::server::pollable::{pollable_channel, PollableReceiver, PollableSender};
|
||||
use anyhow::{anyhow, Error};
|
||||
use domain::{Domain, DomainId};
|
||||
use log::error;
|
||||
@@ -29,8 +28,6 @@ pub enum MuxNotification {
|
||||
|
||||
static SUB_ID: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
pub type MuxSubscriber = PollableReceiver<MuxNotification>;
|
||||
|
||||
pub struct Mux {
|
||||
tabs: RefCell<HashMap<TabId, Rc<Tab>>>,
|
||||
panes: RefCell<HashMap<PaneId, Rc<dyn Pane>>>,
|
||||
@@ -38,7 +35,7 @@ pub struct Mux {
|
||||
default_domain: RefCell<Option<Arc<dyn Domain>>>,
|
||||
domains: RefCell<HashMap<DomainId, Arc<dyn Domain>>>,
|
||||
domains_by_name: RefCell<HashMap<String, Arc<dyn Domain>>>,
|
||||
subscribers: RefCell<HashMap<usize, PollableSender<MuxNotification>>>,
|
||||
subscribers: RefCell<HashMap<usize, Box<dyn Fn(MuxNotification) -> bool>>>,
|
||||
}
|
||||
|
||||
fn read_from_pane_pty(pane_id: PaneId, mut reader: Box<dyn std::io::Read>) {
|
||||
@@ -130,16 +127,19 @@ impl Mux {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subscribe(&self) -> anyhow::Result<MuxSubscriber> {
|
||||
pub fn subscribe<F>(&self, subscriber: F)
|
||||
where
|
||||
F: Fn(MuxNotification) -> bool + 'static,
|
||||
{
|
||||
let sub_id = SUB_ID.fetch_add(1, Ordering::Relaxed);
|
||||
let (tx, rx) = pollable_channel()?;
|
||||
self.subscribers.borrow_mut().insert(sub_id, tx);
|
||||
Ok(rx)
|
||||
self.subscribers
|
||||
.borrow_mut()
|
||||
.insert(sub_id, Box::new(subscriber));
|
||||
}
|
||||
|
||||
pub fn notify(&self, notification: MuxNotification) {
|
||||
let mut subscribers = self.subscribers.borrow_mut();
|
||||
subscribers.retain(|_, tx| tx.send(notification.clone()).is_ok());
|
||||
subscribers.retain(|_, notify| notify(notification.clone()));
|
||||
}
|
||||
|
||||
pub fn default_domain(&self) -> Arc<dyn Domain> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::mux::{Mux, MuxNotification, MuxSubscriber};
|
||||
use crate::mux::{Mux, MuxNotification};
|
||||
use crate::server::codec::*;
|
||||
use crate::server::listener::sessionhandler::SessionHandler;
|
||||
use crate::server::pollable::*;
|
||||
@@ -11,7 +11,7 @@ use std::collections::HashSet;
|
||||
pub struct ClientSession<S: ReadAndWrite> {
|
||||
stream: S,
|
||||
to_write_rx: PollableReceiver<DecodedPdu>,
|
||||
mux_rx: MuxSubscriber,
|
||||
mux_rx: PollableReceiver<MuxNotification>,
|
||||
handler: SessionHandler,
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ impl<S: ReadAndWrite> ClientSession<S> {
|
||||
let (to_write_tx, to_write_rx) =
|
||||
pollable_channel().expect("failed to create pollable_channel");
|
||||
let mux = Mux::get().expect("to be running on gui thread");
|
||||
let mux_rx = mux.subscribe().expect("Mux::subscribe to succeed");
|
||||
let (mux_tx, mux_rx) = pollable_channel().expect("failed to create pollable_channel");
|
||||
mux.subscribe(move |n| mux_tx.send(n).is_ok());
|
||||
let handler = SessionHandler::new(to_write_tx);
|
||||
Self {
|
||||
stream,
|
||||
|
||||
Reference in new issue
Block a user