Collect nodes an listeners in separate hashmaps
This commit is contained in:
parent
085f63e075
commit
1a3c02a577
12
src/main.rs
12
src/main.rs
@ -2,10 +2,14 @@ use anyhow::{
|
||||
Result,
|
||||
};
|
||||
use pipewire as pw;
|
||||
use pw::proxy::ProxyT;
|
||||
use std::{
|
||||
cell::{
|
||||
RefCell,
|
||||
},
|
||||
collections::{
|
||||
HashMap,
|
||||
},
|
||||
rc::{
|
||||
Rc,
|
||||
},
|
||||
@ -20,7 +24,8 @@ fn main() -> Result<()> {
|
||||
let registry = Rc::new(core.get_registry()?);
|
||||
let registry_weak = Rc::downgrade(®istry);
|
||||
|
||||
let nodes = RefCell::new(Vec::new());
|
||||
let nodes: RefCell<HashMap<u32, Box<dyn pw::proxy::ProxyT>>> = RefCell::new(HashMap::new());
|
||||
let listeners: RefCell<HashMap<u32, Vec<Box<dyn pw::proxy::Listener>>>> = RefCell::new(HashMap::new());
|
||||
|
||||
// Listen for new nodes
|
||||
let _registry_listener = registry
|
||||
@ -41,7 +46,10 @@ fn main() -> Result<()> {
|
||||
})
|
||||
.register();
|
||||
|
||||
nodes.borrow_mut().push((node, node_listener));
|
||||
let node_id = node.upcast_ref().id();
|
||||
|
||||
nodes.borrow_mut().insert(node_id, Box::new(node));
|
||||
listeners.borrow_mut().entry(node_id).or_default().push(Box::new(node_listener));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user