alsactl 0.8.0

API binding for alsactl library
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{ffi, ElemIfaceType};
use glib::translate::*;

glib::wrapper! {
    /// A boxed object to express the identifier of element.
    ///
    /// A [`ElemId`][crate::ElemId] is a boxed object to express the identifier of element. It points to a
    /// element by two ways; by the numeric identifier, or by the combination of the type of interface,
    /// the numeric identifier of device, the numeric identifier of subdevice, the name, and the index.
    ///
    /// The object wraps `struct snd_ctl_elem_id` in UAPI of Linux sound subsystem.
    #[derive(Debug, PartialOrd, Ord, Hash)]
    pub struct ElemId(Boxed<ffi::ALSACtlElemId>);

    match fn {
        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::alsactl_elem_id_get_type(), ptr as *mut _) as *mut ffi::ALSACtlElemId,
        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::alsactl_elem_id_get_type(), ptr as *mut _),
        type_ => || ffi::alsactl_elem_id_get_type(),
    }
}

impl ElemId {
    /// Allocates and return an instance of [`ElemId`][crate::ElemId] by the name.
    /// ## `iface`
    /// The interface of element, one of ALSACtlElemIfaceType.
    /// ## `device_id`
    /// The numeric identifier of device to which the element belongs.
    /// ## `subdevice_id`
    /// The numeric identifier of subdevice to which the element belongs.
    /// ## `name`
    /// The name of element, up to 44 byte (=`SNDRV_CTL_ELEM_ID_NAME_MAXLEN`) including
    ///                  terminator.
    /// ## `index`
    /// The index of element in a set of elements with the same name.
    ///
    /// # Returns
    ///
    /// A [`ElemId`][crate::ElemId].
    #[doc(alias = "alsactl_elem_id_new_by_name")]
    pub fn new_by_name(
        iface: ElemIfaceType,
        device_id: u32,
        subdevice_id: u32,
        name: &str,
        index: u32,
    ) -> ElemId {
        unsafe {
            from_glib_full(ffi::alsactl_elem_id_new_by_name(
                iface.into_glib(),
                device_id,
                subdevice_id,
                name.to_glib_none().0,
                index,
            ))
        }
    }

    /// Allocates and return an instance of [`ElemId`][crate::ElemId] by the numeric identifier.
    /// ## `numid`
    /// The numeric identifier of the element.
    ///
    /// # Returns
    ///
    /// A [`ElemId`][crate::ElemId].
    #[doc(alias = "alsactl_elem_id_new_by_numid")]
    pub fn new_by_numid(numid: u32) -> ElemId {
        unsafe { from_glib_full(ffi::alsactl_elem_id_new_by_numid(numid)) }
    }

    #[doc(alias = "alsactl_elem_id_equal")]
    fn equal(&self, target: &ElemId) -> bool {
        unsafe {
            from_glib(ffi::alsactl_elem_id_equal(
                self.to_glib_none().0,
                target.to_glib_none().0,
            ))
        }
    }

    /// Get the numeric identifier of device to which the element belongs.
    ///
    /// # Returns
    ///
    ///
    /// ## `device_id`
    /// The numeric identifier of device to which the element belongs.
    #[doc(alias = "alsactl_elem_id_get_device_id")]
    #[doc(alias = "get_device_id")]
    pub fn device_id(&self) -> u32 {
        unsafe {
            let mut device_id = std::mem::MaybeUninit::uninit();
            ffi::alsactl_elem_id_get_device_id(self.to_glib_none().0, device_id.as_mut_ptr());
            device_id.assume_init()
        }
    }

    /// Get the interface of element.
    ///
    /// # Returns
    ///
    ///
    /// ## `iface`
    /// The interface of element.
    #[doc(alias = "alsactl_elem_id_get_iface")]
    #[doc(alias = "get_iface")]
    pub fn iface(&self) -> ElemIfaceType {
        unsafe {
            let mut iface = std::mem::MaybeUninit::uninit();
            ffi::alsactl_elem_id_get_iface(self.to_glib_none().0, iface.as_mut_ptr());
            from_glib(iface.assume_init())
        }
    }

    /// Get the index of element.
    ///
    /// # Returns
    ///
    ///
    /// ## `index`
    /// The index of element.
    #[doc(alias = "alsactl_elem_id_get_index")]
    #[doc(alias = "get_index")]
    pub fn index(&self) -> u32 {
        unsafe {
            let mut index = std::mem::MaybeUninit::uninit();
            ffi::alsactl_elem_id_get_index(self.to_glib_none().0, index.as_mut_ptr());
            index.assume_init()
        }
    }

    /// Get the name of element.
    ///
    /// # Returns
    ///
    ///
    /// ## `name`
    /// The name of element.
    #[doc(alias = "alsactl_elem_id_get_name")]
    #[doc(alias = "get_name")]
    pub fn name(&self) -> glib::GString {
        unsafe {
            let mut name = std::ptr::null();
            ffi::alsactl_elem_id_get_name(self.to_glib_none().0, &mut name);
            from_glib_none(name)
        }
    }

    /// Get the numeric identifier of element.
    ///
    /// # Returns
    ///
    ///
    /// ## `numid`
    /// The numeric identifier of element.
    #[doc(alias = "alsactl_elem_id_get_numid")]
    #[doc(alias = "get_numid")]
    pub fn numid(&self) -> u32 {
        unsafe {
            let mut numid = std::mem::MaybeUninit::uninit();
            ffi::alsactl_elem_id_get_numid(self.to_glib_none().0, numid.as_mut_ptr());
            numid.assume_init()
        }
    }

    /// Get the numeric identifier of element.
    ///
    /// # Returns
    ///
    ///
    /// ## `subdevice_id`
    /// The numeric identifier of subdevice to which the element belongs.
    #[doc(alias = "alsactl_elem_id_get_subdevice_id")]
    #[doc(alias = "get_subdevice_id")]
    pub fn subdevice_id(&self) -> u32 {
        unsafe {
            let mut subdevice_id = std::mem::MaybeUninit::uninit();
            ffi::alsactl_elem_id_get_subdevice_id(self.to_glib_none().0, subdevice_id.as_mut_ptr());
            subdevice_id.assume_init()
        }
    }
}

impl PartialEq for ElemId {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for ElemId {}

unsafe impl Send for ElemId {}
unsafe impl Sync for ElemId {}