use core::ffi::{c_char, c_ulong, c_void};
use super::types::{Data, Handle, PortDescriptor, PortRangeHintDescriptor, Properties};
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct PortRangeHint {
pub hint_descriptor: PortRangeHintDescriptor,
pub lower_bound: Data,
pub upper_bound: Data,
}
#[repr(C)]
pub struct Descriptor {
pub unique_id: c_ulong,
pub label: *const c_char,
pub properties: Properties,
pub name: *const c_char,
pub maker: *const c_char,
pub copyright: *const c_char,
pub port_count: c_ulong,
pub port_descriptors: *const PortDescriptor,
pub port_names: *const *const c_char,
pub port_range_hints: *const PortRangeHint,
pub implementation_data: *mut c_void,
pub instantiate:
Option<unsafe extern "C" fn(descriptor: *const Descriptor, sample_rate: c_ulong) -> Handle>,
pub connect_port:
Option<unsafe extern "C" fn(instance: Handle, port: c_ulong, data_location: *mut Data)>,
pub activate: Option<unsafe extern "C" fn(instance: Handle)>,
pub run: Option<unsafe extern "C" fn(instance: Handle, sample_count: c_ulong)>,
pub run_adding: Option<unsafe extern "C" fn(instance: Handle, sample_count: c_ulong)>,
pub set_run_adding_gain: Option<unsafe extern "C" fn(instance: Handle, gain: Data)>,
pub deactivate: Option<unsafe extern "C" fn(instance: Handle)>,
pub cleanup: Option<unsafe extern "C" fn(instance: Handle)>,
}
pub type DescriptorFn = unsafe extern "C" fn(index: c_ulong) -> *const Descriptor;
#[cfg(test)]
mod tests {
use super::*;
use core::mem::{align_of, size_of};
#[test]
fn port_range_hint_layout_is_packed_three_ints() {
assert_eq!(size_of::<PortRangeHint>(), 12);
assert_eq!(align_of::<PortRangeHint>(), 4);
}
#[test]
fn descriptor_callback_slots_are_nullable() {
assert_eq!(
size_of::<Option<unsafe extern "C" fn(Handle, c_ulong)>>(),
size_of::<*const c_void>(),
);
}
}