1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
use std;
use capi;
use std::os::raw::c_void;
use std::ptr::null_mut;
use super::{ContextInternal, Context};
pub use capi::pa_ext_device_restore_info as InfoInternal;
#[repr(C)]
pub struct Info {
pub dtype: ::def::Device,
pub index: u32,
pub n_formats: u8,
pub formats: *mut *mut ::format::InfoInternal,
}
pub struct DeviceRestore {
context: *mut ContextInternal,
weak: bool,
}
impl Context {
pub fn device_restore(&self) -> DeviceRestore {
unsafe { capi::pa_context_ref(self.ptr) };
DeviceRestore::from_raw(self.ptr)
}
}
pub type TestCb = extern "C" fn(c: *mut ContextInternal, version: u32, userdata: *mut c_void);
pub type SubscribeCb = extern "C" fn(c: *mut ContextInternal,
type_: ::def::Device, idx: u32, userdata: *mut c_void);
pub type ReadDevFormatsCb = extern "C" fn(c: *mut ContextInternal, info: *const InfoInternal,
eol: i32, userdata: *mut c_void);
impl DeviceRestore {
fn from_raw(context: *mut ContextInternal) -> Self {
Self { context: context, weak: false }
}
pub fn from_raw_weak(context: *mut ContextInternal) -> Self {
Self { context: context, weak: true }
}
pub fn test(&mut self, cb: (TestCb, *mut c_void)) -> Option<::operation::Operation> {
let ptr = unsafe { capi::pa_ext_device_restore_test(self.context, Some(cb.0), cb.1) };
if ptr.is_null() {
return None;
}
Some(::operation::Operation::from_raw(ptr))
}
pub fn subscribe(&mut self, enable: bool, cb: (::context::ContextSuccessCb, *mut c_void)
) -> Option<::operation::Operation>
{
let ptr = unsafe { capi::pa_ext_device_restore_subscribe(self.context, enable as i32,
Some(cb.0), cb.1) };
if ptr.is_null() {
return None;
}
Some(::operation::Operation::from_raw(ptr))
}
pub fn set_subscribe_cb(&mut self, cb: (SubscribeCb, *mut c_void)) {
unsafe { capi::pa_ext_device_restore_set_subscribe_cb(self.context, Some(cb.0), cb.1); }
}
pub fn read_formats_all(&mut self, cb: (ReadDevFormatsCb, *mut c_void)
) -> Option<::operation::Operation>
{
let ptr = unsafe { capi::pa_ext_device_restore_read_formats_all(self.context, Some(cb.0),
cb.1) };
if ptr.is_null() {
return None;
}
Some(::operation::Operation::from_raw(ptr))
}
pub fn read_formats(&mut self, type_: ::def::Device, idx: u32, cb: (ReadDevFormatsCb, *mut c_void)
) -> Option<::operation::Operation>
{
let ptr = unsafe { capi::pa_ext_device_restore_read_formats(self.context, type_, idx,
Some(cb.0), cb.1) };
if ptr.is_null() {
return None;
}
Some(::operation::Operation::from_raw(ptr))
}
pub fn save_formats(&mut self, type_: ::def::Device, idx: u32, formats: &mut [&mut ::format::Info],
cb: (::context::ContextSuccessCb, *mut c_void)) -> Option<::operation::Operation>
{
let mut format_ptrs: Vec<*mut capi::pa_format_info> = Vec::with_capacity(formats.len());
for format in formats {
format_ptrs.push(unsafe { std::mem::transmute(&format.ptr) });
}
let ptr = unsafe {
capi::pa_ext_device_restore_save_formats(self.context, type_, idx,
format_ptrs.len() as u8, format_ptrs.as_ptr(), Some(cb.0), cb.1)
};
if ptr.is_null() {
return None;
}
Some(::operation::Operation::from_raw(ptr))
}
}
impl Drop for DeviceRestore {
fn drop(&mut self) {
if !self.weak {
unsafe { capi::pa_context_unref(self.context) };
}
self.context = null_mut::<ContextInternal>();
}
}