11//! Configuration file API
22//!
3- //! For now, just contains two functions regarding the global configuration
3+ //! For now, just contains functions regarding the global configuration
44//! stored as a cache inside alsa-lib. Calling `update_free_global` might help
55//! against valgrind reporting memory leaks.
66use crate :: { alsa} ;
77use super :: error:: * ;
8+ use super :: Output ;
9+ use std:: ptr;
810
9- pub fn update ( ) -> Result < ( ) > {
10- acheck ! ( snd_config_update( ) ) . map ( |_| ( ) )
11+ pub fn update ( ) -> Result < bool > {
12+ acheck ! ( snd_config_update( ) ) . map ( |x| x != 0 )
1113}
1214
1315pub fn update_free_global ( ) -> Result < ( ) > {
1416 acheck ! ( snd_config_update_free_global( ) ) . map ( |_| ( ) )
17+ }
18+
19+ /// [snd_config_t](https://alsa-project.org/alsa-doc/alsa-lib/group___config.html) wrapper
20+ pub struct Config ( * mut alsa:: snd_config_t ) ;
21+
22+ impl Drop for Config {
23+ fn drop ( & mut self ) { unsafe { alsa:: snd_config_unref ( self . 0 ) } ; }
24+ }
25+
26+ pub fn update_ref ( ) -> Result < Config > {
27+ let mut top = ptr:: null_mut ( ) ;
28+ acheck ! ( snd_config_update_ref( & mut top) ) . map ( |_| Config ( top) )
29+ }
30+
31+ impl Config {
32+ pub fn save ( & self , o : & mut Output ) -> Result < ( ) > {
33+ acheck ! ( snd_config_save( self . 0 , super :: io:: output_handle( o) ) ) . map ( |_| ( ) )
34+ }
35+ }
36+
37+ #[ test]
38+ fn config_save ( ) {
39+ let c = update_ref ( ) . unwrap ( ) ;
40+ let mut outp = Output :: buffer_open ( ) . unwrap ( ) ;
41+ c. save ( & mut outp) . unwrap ( ) ;
42+ println ! ( "== Config save ==\n {}" , outp) ;
1543}
0 commit comments