Add destructor for AlsaCard

This commit is contained in:
Julian Ospald 2017-06-30 22:36:34 +02:00
parent f3fc6aca23
commit 92514a2fd0
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28

View File

@ -18,6 +18,34 @@ use std::u8;
#[derive(Clone, Copy, Debug)]
pub enum AudioUser {
AudioUserUnknown,
AudioUserPopup,
AudioUserTrayIcon,
AudioUserHotkeys,
}
#[derive(Clone, Copy, Debug)]
pub enum AudioSignal {
AudioNoCard,
AudioCardInitialized,
AudioCardCleanedUp,
AudioCardDisconnected,
AudioCardError,
AudioValuesChanged,
}
#[derive(Clone, Copy, Debug)]
pub enum AlsaEvent {
AlsaCardError,
AlsaCardDiconnected,
AlsaCardValuesChanged,
}
// TODO: implement free/destructor // TODO: implement free/destructor
pub struct AlsaCard { pub struct AlsaCard {
_cannot_construct: (), _cannot_construct: (),
@ -163,31 +191,11 @@ impl AlsaCard {
} }
#[derive(Clone, Copy, Debug)] impl Drop for AlsaCard {
pub enum AudioUser { fn drop (&mut self) {
AudioUserUnknown, debug!("Destructing watch_ids: {:?}", self.watch_ids);
AudioUserPopup, unwatch_poll_descriptors(&self.watch_ids);
AudioUserTrayIcon, }
AudioUserHotkeys,
}
#[derive(Clone, Copy, Debug)]
pub enum AudioSignal {
AudioNoCard,
AudioCardInitialized,
AudioCardCleanedUp,
AudioCardDisconnected,
AudioCardError,
AudioValuesChanged,
}
#[derive(Clone, Copy, Debug)]
pub enum AlsaEvent {
AlsaCardError,
AlsaCardDiconnected,
AlsaCardValuesChanged,
} }
@ -218,6 +226,15 @@ fn watch_poll_descriptors(polls: Vec<pollfd>,
} }
fn unwatch_poll_descriptors(watch_ids: &Vec<u32>) {
for watch_id in watch_ids {
unsafe {
glib_sys::g_source_remove(*watch_id);
}
}
}
extern "C" fn watch_cb(chan: *mut glib_sys::GIOChannel, extern "C" fn watch_cb(chan: *mut glib_sys::GIOChannel,
cond: glib_sys::GIOCondition, cond: glib_sys::GIOCondition,
data: glib_sys::gpointer) data: glib_sys::gpointer)