#![allow(non_camel_case_types)]
#[cfg(mln_platform_crate)]
extern crate mln_ffi_platform as _;
mod generated;
pub use generated::*;
pub trait NativeHandle: Copy + 'static {
fn to_raw(self) -> u64;
fn from_raw(raw: u64) -> Self;
}
impl NativeHandle for () {
fn to_raw(self) -> u64 {
0
}
fn from_raw(_: u64) -> Self {}
}
macro_rules! native_handles {
($($handle:ident),* $(,)?) => {$(
impl $crate::NativeHandle for $handle {
fn to_raw(self) -> u64 {
self.0
}
fn from_raw(raw: u64) -> Self {
Self(raw)
}
}
)*};
}
use native_handles;
#[repr(C)]
pub struct mln_plugin_descriptor_v1 {
_opaque: [u8; 0],
}
pub type mln_plugin_status = std::ffi::c_uint;
pub const MLN_PLUGIN_STATUS_OK: mln_plugin_status = 0;
pub const MLN_PLUGIN_STATUS_ALREADY_REGISTERED: mln_plugin_status = 1;
pub const MLN_PLUGIN_STATUS_INVALID_ARGUMENT: mln_plugin_status = 2;
pub const MLN_PLUGIN_STATUS_UNSUPPORTED_ABI: mln_plugin_status = 3;
pub const MLN_PLUGIN_STATUS_CONFLICT: mln_plugin_status = 4;
pub const MLN_PLUGIN_STATUS_NOT_FOUND: mln_plugin_status = 5;
pub const MLN_PLUGIN_STATUS_CALLBACK_ERROR: mln_plugin_status = 6;
pub type mln_plugin_register_function_v1 = Option<
unsafe extern "C" fn(
descriptor: *const mln_plugin_descriptor_v1,
error_message: *mut std::ffi::c_char,
error_message_capacity: usize,
) -> mln_plugin_status,
>;
unsafe extern "C" {
pub fn mln_plugin_register_v1(
descriptor: *const mln_plugin_descriptor_v1,
error_message: *mut std::ffi::c_char,
error_message_capacity: usize,
) -> mln_plugin_status;
}
#[cfg(test)]
mod tests {
#[test]
fn loads_the_native_library() {
assert_ne!(unsafe { super::mln_supported_render_backend_mask() }, 0);
}
#[test]
fn links_plugin_registration() {
let status =
unsafe { super::mln_plugin_register_v1(std::ptr::null(), std::ptr::null_mut(), 0) };
assert_eq!(status, super::MLN_PLUGIN_STATUS_INVALID_ARGUMENT);
}
#[test]
fn links_delivery_queue() {
let mut queue = super::mln_delivery_queue(0);
let status = unsafe {
super::mln_delivery_queue_create(std::ptr::null(), &mut queue, std::ptr::null_mut())
};
assert_eq!(status, super::MLN_STATUS_OK);
unsafe { super::mln_delivery_queue_release(queue) };
}
}