From e28faaa2ed63c30c8e13f8fd57ac4255efafdde3 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 2 Jul 2017 01:35:12 +0200 Subject: [PATCH] Update --- src/alsa_pn.rs | 25 ++++++++++++------------- src/audio.rs | 19 ++++++++++--------- src/main.rs | 4 ++-- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/alsa_pn.rs b/src/alsa_pn.rs index 455ca46fe..f3a883090 100644 --- a/src/alsa_pn.rs +++ b/src/alsa_pn.rs @@ -10,7 +10,7 @@ use libc::c_int; use libc::c_uint; use libc::pollfd; use libc::size_t; -use std::cell::RefCell; +use std::cell::Cell; use std::iter::Map; use std::mem; use std::ptr; @@ -30,9 +30,9 @@ pub enum AlsaEvent { pub struct AlsaCard { _cannot_construct: (), pub card: Card, - pub mixer: Rc, + pub mixer: Mixer, pub selem_id: SelemId, - pub watch_ids: RefCell>, + pub watch_ids: Cell>, pub cb: Rc, } @@ -48,8 +48,10 @@ impl AlsaCard { None => get_default_alsa_card(), } }; - let mixer = Rc::new(get_mixer(&card)?); - let mixer2 = mixer.clone(); + let mixer = get_mixer(&card)?; + + let vec_pollfd = PollDescriptors::get(&mixer)?; + let selem_id = get_selem_by_name(&mixer, elem_name.unwrap_or(String::from("Master"))) @@ -61,17 +63,16 @@ impl AlsaCard { card: card, mixer: mixer, selem_id: selem_id, - watch_ids: RefCell::new(vec![]), + watch_ids: Cell::new(vec![]), cb: cb, }); - let vec_pollfd = PollDescriptors::get(mixer2.as_ref())?; /* TODO: callback is registered here, which must be unregistered * when the card is destroyed!! * poll descriptors must be unwatched too */ let watch_ids = AlsaCard::watch_poll_descriptors(vec_pollfd, acard.as_ref()); - *acard.watch_ids.borrow_mut() = watch_ids; + acard.watch_ids.set(watch_ids); return Ok(acard); } @@ -167,6 +168,7 @@ impl AlsaCard { } +// TODO: test that this is actually triggered when switching cards impl Drop for AlsaCard { // call Box::new(x), transmute the Box into a raw pointer, and then // std::mem::forget @@ -182,15 +184,12 @@ impl Drop for AlsaCard { // callback and frees the Box, by simply transmuting the // raw pointer to a Box fn drop(&mut self) { - debug!("Destructing watch_ids: {:?}", self.watch_ids); - AlsaCard::unwatch_poll_descriptors(&self.watch_ids.borrow()); + debug!("Destructing watch_ids: {:?}", self.watch_ids.get_mut()); + AlsaCard::unwatch_poll_descriptors(&self.watch_ids.get_mut()); } } - - - extern "C" fn watch_cb(chan: *mut glib_sys::GIOChannel, cond: glib_sys::GIOCondition, data: glib_sys::gpointer) diff --git a/src/audio.rs b/src/audio.rs index 743c5a803..0c3bfd767 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -1,5 +1,6 @@ use errors::*; use glib; +use std::cell::Cell; use std::cell::RefCell; use std::rc::Rc; use std::f64; @@ -32,7 +33,7 @@ pub struct Audio { pub acard: RefCell>, pub last_action_timestamp: RefCell, pub handlers: Rc>>>, - pub scroll_step: RefCell, + pub scroll_step: Cell, } @@ -57,7 +58,7 @@ impl Audio { acard: RefCell::new(AlsaCard::new(card_name, elem_name, cb)?), last_action_timestamp: last_action_timestamp.clone(), handlers: handlers.clone(), - scroll_step: RefCell::new(5), + scroll_step: Cell::new(5), }; return Ok(audio); @@ -68,12 +69,12 @@ impl Audio { card_name: Option, elem_name: Option) -> Result<()> { + debug!("Switching cards"); + let cb = self.acard.borrow().cb.clone(); let mut ac = self.acard.borrow_mut(); - let cb = self.acard - .borrow() - .cb - .clone(); - *ac = AlsaCard::new(card_name, elem_name, cb)?; + *ac = AlsaCard::new(card_name, + elem_name, + cb)?; return Ok(()); } @@ -102,7 +103,7 @@ impl Audio { *rc = glib::get_monotonic_time(); } let old_vol = self.vol()?; - let new_vol = f64::ceil(old_vol + (*self.scroll_step.borrow() as f64)); + let new_vol = f64::ceil(old_vol + (self.scroll_step.get() as f64)); debug!("Increase vol by {:?} to {:?}", (new_vol - old_vol), new_vol); @@ -116,7 +117,7 @@ impl Audio { *rc = glib::get_monotonic_time(); } let old_vol = self.vol()?; - let new_vol = old_vol - (*self.scroll_step.borrow() as f64); + let new_vol = old_vol - (self.scroll_step.get() as f64); debug!("Decrease vol by {:?} to {:?}", (new_vol - old_vol), new_vol); diff --git a/src/main.rs b/src/main.rs index 1192c9c08..8bffc04b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,14 +43,14 @@ use app_state::*; fn main() { gtk::init().unwrap(); - let apps = Rc::new(AppS::new()); - flexi_logger::LogOptions::new() .log_to_file(false) // ... your configuration options go here ... .init(Some("pnmixer=debug".to_string())) .unwrap_or_else(|e| panic!("Logger initialization failed with {}", e)); + let apps = Rc::new(AppS::new()); + ui_entry::init(apps); gtk::main();