Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  device_name.rs

  Sprache: Rust
 

//! Enumerate devices in the alsa library configuration
//!
//! # Example
//! Print all devices found in various categories.
//!
//! ```
//! use std::ffi::CString;
//! use alsa::device_name::HintIter;
//!
//! for t in &["pcm", "ctl", "rawmidi", "timer", "seq", "hwdep"] {
//!     println!("{} devices:", t);
//!     let i = HintIter::new(None, &*CString::new(*t).unwrap()).unwrap();
//!     for a in i { println!("  {:?}", a) }
//! }
//! ```

use std::ptr;
use libc::{c_void, c_int};
use crate::alsa;
use super::{Card, Direction};
use super::error::*;
use std::ffi::{CStr, CString};

/// [snd_device_name_hint](http://www.alsa-project.org/alsa-doc/alsa-lib/group___control.html) wrapper
pub struct HintIter(*mut *mut c_void, isize);

impl Drop for HintIter {
    fn drop(&mut self) { unsafe { alsa::snd_device_name_free_hint(self.0); }}
}

impl HintIter {
    /// typical interfaces are: "pcm", "ctl", "rawmidi", "timer", "seq" and "hwdep".
    pub fn new(card: Option<&Card>, iface: &CStr) -> Result<HintIter> {
        let mut p = ptr::null_mut();
        let cnr = card.map(|c| c.get_index()).unwrap_or(-1as c_int;
        acheck!(snd_device_name_hint(cnr, iface.as_ptr(), &mut p))
            .map(|_| HintIter(p, 0))
    }

    /// A constructor variant that takes the interface as a Rust string slice.
    pub fn new_str(card: Option<&Card>, iface: &str) -> Result<HintIter> {
        HintIter::new(card, &CString::new(iface).unwrap())
    }
}

impl Iterator for HintIter {
    type Item = Hint;
    fn next(&mut self) -> Option<Hint> {
        if self.0.is_null() { return None; }
        let p = unsafe { *self.0.offset(self.1) };
        if p.is_null() { return None; }
        self.1 += 1;
        Some(Hint::new(p))
    }
}


/// [snd_device_name_get_hint](http://www.alsa-project.org/alsa-doc/alsa-lib/group___control.html) wrapper
#[derive(Debug, Clone)]
pub struct Hint {
    pub name: Option<String>,
    pub desc: Option<String>,
    pub direction: Option<Direction>,
}

impl Hint {
    fn get_str(p: *const c_void, name: &str) -> Option<String> {
        let name = CString::new(name).unwrap();
        let c = unsafe { alsa::snd_device_name_get_hint(p, name.as_ptr()) };
        from_alloc("snd_device_name_get_hint", c).ok()
    }

    fn new(p: *const c_void) -> Hint {
       let d = Hint::get_str(p, "IOID").and_then(|x| match &*x {
            "Input" => Some(Direction::Capture),
            "Output" => Some(Direction::Playback),
            _ => None,
       });
       Hint { name: Hint::get_str(p, "NAME"), desc: Hint::get_str(p, "DESC"), direction: d }
    }
}

#[test]
fn print_hints() {
    for t in &["pcm""ctl""rawmidi""timer""seq""hwdep"] {
        println!("{} devices:", t);
        let i = HintIter::new(None, &*CString::new(*t).unwrap()).unwrap();
        for a in i { println!("  {:?}", a) }
    }
}

Messung V0.5 in Prozent
C=64 H=96 G=81

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-06-18) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik