use crate::libc as c;
use crate::unix::errno::Errno;
use std::io;
use std::ops;
use thiserror::Error;
#[repr(transparent)]
pub struct CString {
ptr: *mut c::c_char,
}
impl CString {
pub unsafe fn from_raw(ptr: *mut c::c_char) -> Self {
Self { ptr }
}
}
impl Drop for CString {
fn drop(&mut self) {
unsafe {
c::free(self.ptr as *mut _);
}
}
}
impl ops::Deref for CString {
type Target = std::ffi::CStr;
fn deref(&self) -> &Self::Target {
unsafe { std::ffi::CStr::from_ptr(self.ptr) }
}
}
unsafe impl Send for CString {}
unsafe impl Sync for CString {}
#[derive(Debug, Error)]
pub enum Error {
#[error("system error: {0}")]
Sys(#[from] Errno),
#[error("i/o error: {0}")]
Io(
#[source]
#[from]
io::Error,
),
#[error("type `{ty}` is not appropriate to use with format `{format}`")]
FormatMismatch {
ty: &'static str,
format: Format,
},
#[error("mismatch in number of channels in buffer; actual = {actual}, expected = {expected}")]
ChannelsMismatch {
actual: usize,
expected: usize,
},
#[error("bad format identifier ({0})")]
BadFormat(c::c_int),
#[error("bad access identifier ({0})")]
BadAccess(c::c_uint),
#[error("bad timestamp mode identifier ({0})")]
BadTimestamp(c::c_uint),
#[error("bad timestamp type identifier ({0})")]
BadTimestampType(c::c_uint),
#[error("pcm device is not pollable")]
MissingPollFds,
}
pub type Result<T, E = Error> = ::std::result::Result<T, E>;
mod card;
pub use self::card::{cards, Card};
mod pcm;
pub use self::pcm::Pcm;
mod hardware_parameters;
pub use self::hardware_parameters::{HardwareParameters, HardwareParametersMut};
mod software_parameters;
pub use self::software_parameters::{SoftwareParameters, SoftwareParametersMut};
mod format_mask;
pub use self::format_mask::FormatMask;
mod access_mask;
pub use self::access_mask::AccessMask;
mod enums;
pub use self::enums::{Access, Direction, Format, State, Stream, Timestamp, TimestampType};
mod channel_area;
#[doc(hidden)]
pub use self::channel_area::ChannelArea;
mod writer;
pub use self::writer::Writer;
cfg_poll_driver! {
mod async_writer;
pub use self::async_writer::AsyncWriter;
}
mod sample;
pub use self::sample::Sample;
mod configurator;
pub use self::configurator::{Config, Configurator};