summaryrefslogtreecommitdiff
path: root/cros_alsa/src/card.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cros_alsa/src/card.rs')
-rw-r--r--cros_alsa/src/card.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/cros_alsa/src/card.rs b/cros_alsa/src/card.rs
index fa88018f..42beef2c 100644
--- a/cros_alsa/src/card.rs
+++ b/cros_alsa/src/card.rs
@@ -10,6 +10,7 @@ use remain::sorted;
use crate::control::{self, Control};
use crate::control_primitive;
use crate::control_primitive::{Ctl, ElemId, ElemIface};
+use crate::control_tlv::{self, ControlTLV};
pub type Result<T> = std::result::Result<T, Error>;
@@ -21,6 +22,8 @@ pub enum Error {
AlsaControlAPI(control_primitive::Error),
/// Error occurs in Control.
Control(control::Error),
+ /// Error occurs in ControlTLV.
+ ControlTLV(control_tlv::Error),
}
impl error::Error for Error {}
@@ -31,6 +34,12 @@ impl From<control::Error> for Error {
}
}
+impl From<control_tlv::Error> for Error {
+ fn from(err: control_tlv::Error) -> Error {
+ Error::ControlTLV(err)
+ }
+}
+
impl From<control_primitive::Error> for Error {
fn from(err: control_primitive::Error) -> Error {
Error::AlsaControlAPI(err)
@@ -43,11 +52,13 @@ impl fmt::Display for Error {
match self {
AlsaControlAPI(e) => write!(f, "{}", e),
Control(e) => write!(f, "{}", e),
+ ControlTLV(e) => write!(f, "{}", e),
}
}
}
/// `Card` represents a sound card.
+#[derive(Debug)]
pub struct Card {
handle: Ctl,
name: String,
@@ -82,7 +93,7 @@ impl Card {
/// # Errors
///
/// * If control name is an invalid CString.
- /// * If control dose not exist.
+ /// * If control does not exist.
/// * If `Control` elem_type() mismatches the type of underlying mixer control.
/// * If `Control` size() mismatches the number of value entries of underlying mixer control.
pub fn control_by_name<'a, T: 'a>(&'a mut self, control_name: &str) -> Result<T>
@@ -92,4 +103,15 @@ impl Card {
let id = ElemId::new(ElemIface::Mixer, control_name)?;
Ok(T::from(&mut self.handle, id)?)
}
+
+ /// Creates a `ControlTLV` from control name.
+ ///
+ /// # Errors
+ ///
+ /// * If control name is an invalid CString.
+ /// * If control does not exist.
+ pub fn control_tlv_by_name<'a>(&'a mut self, control_name: &str) -> Result<ControlTLV<'a>> {
+ let id = ElemId::new(ElemIface::Mixer, control_name)?;
+ Ok(ControlTLV::new(&mut self.handle, id)?)
+ }
}