Display on air state
This commit is contained in:
parent
3b74ea2bfc
commit
6bfc1ee008
29
src/main.rs
29
src/main.rs
@ -9,6 +9,7 @@ use std::{
|
||||
},
|
||||
collections::{
|
||||
HashMap,
|
||||
HashSet,
|
||||
},
|
||||
rc::{
|
||||
Rc,
|
||||
@ -27,6 +28,8 @@ fn main() -> Result<()> {
|
||||
let nodes: Rc<RefCell<HashMap<u32, Box<dyn pw::proxy::ProxyT>>>> = Rc::new(RefCell::new(HashMap::new()));
|
||||
let listeners: Rc<RefCell<HashMap<u32, Vec<Box<dyn pw::proxy::Listener>>>>> = Rc::new(RefCell::new(HashMap::new()));
|
||||
|
||||
let running_cameras: Rc<RefCell<HashSet<u32>>> = Rc::new(RefCell::new(HashSet::new()));
|
||||
|
||||
// Listen for new nodes
|
||||
let _registry_listener = registry
|
||||
.add_listener_local()
|
||||
@ -37,12 +40,34 @@ fn main() -> Result<()> {
|
||||
|
||||
let node: pw::node::Node = registry.bind(obj).unwrap();
|
||||
|
||||
let running_cameras_weak = Rc::downgrade(&running_cameras);
|
||||
|
||||
// Listen for camera node changes
|
||||
let node_listener = node
|
||||
.add_listener_local()
|
||||
.info(|info| {
|
||||
.info(move |info| {
|
||||
|
||||
if let Some(running_cameras) = running_cameras_weak.upgrade() {
|
||||
let cameras_are_running_before = running_cameras.borrow_mut().len() > 0;
|
||||
|
||||
if let pw::node::NodeState::Running = info.state() {
|
||||
running_cameras.borrow_mut().insert(info.id());
|
||||
}
|
||||
else {
|
||||
running_cameras.borrow_mut().remove(&info.id());
|
||||
}
|
||||
|
||||
let cameras_are_running_after = running_cameras.borrow_mut().len() > 0;
|
||||
if cameras_are_running_before != cameras_are_running_after {
|
||||
if cameras_are_running_after {
|
||||
println!("On air");
|
||||
}
|
||||
else {
|
||||
println!("Off air");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}: {:?}", info.id(), info.state());
|
||||
})
|
||||
.register();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user