use libpulse_binding::context::State as ContextState;
use super::types::{device::DeviceType, stream::StreamType};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MissingMonitoringComponent {
CancellationToken,
EventSender,
}
impl std::fmt::Display for MissingMonitoringComponent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::CancellationToken => write!(f, "cancellation token"),
Self::EventSender => write!(f, "event sender"),
}
}
}
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("cannot create pulseaudio context")]
ContextCreationFailed,
#[error("cannot connect to pulseaudio server")]
ConnectionFailed(#[source] libpulse_binding::error::PAErr),
#[error("pulseaudio context entered failed state: {0:?}")]
ContextStateFailed(ContextState),
#[error("device {index:?} ({device_type:?}) not found")]
DeviceNotFound {
index: u32,
device_type: DeviceType,
},
#[error("stream {index:?} ({stream_type:?}) not found")]
StreamNotFound {
index: u32,
stream_type: StreamType,
},
#[error("command channel disconnected")]
CommandChannelDisconnected,
#[error("shared data lock poisoned")]
LockPoisoned,
#[error("cannot start monitoring: {0} not available")]
MonitoringNotInitialized(MissingMonitoringComponent),
#[error("cannot connect to dbus session bus")]
DbusConnectionFailed(#[source] zbus::Error),
#[error("cannot register dbus object at {path}")]
DbusObjectRegistrationFailed {
path: &'static str,
#[source]
source: zbus::Error,
},
#[error("cannot acquire dbus name {name}")]
DbusNameAcquisitionFailed {
name: &'static str,
#[source]
source: zbus::Error,
},
}