use core::ffi::c_void;
use core::sync::atomic::AtomicU32;
use crate::abi::{Header, Layout, Str};
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, bytemuck::Zeroable)]
pub struct PointMode(pub u32);
impl PointMode {
pub const OBSERVE: Self = Self(0);
pub const ADVISE: Self = Self(1);
pub const OVERRIDE: Self = Self(2);
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, bytemuck::Zeroable)]
pub struct PointFlags(pub u32);
impl PointFlags {
pub const NONE: Self = Self(0);
pub const REFUSE: Self = Self(1);
#[must_use]
pub const fn contains(self, other: Self) -> bool {
self.0 & other.0 == other.0
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, bytemuck::Zeroable)]
pub struct PointSpec {
pub header: Header,
pub name: Str,
pub mode: PointMode,
pub flags: PointFlags,
pub input: Layout,
pub output: Layout,
}
impl_headed!(PointSpec);
#[repr(C)]
#[derive(Clone, Copy, Debug, bytemuck::Zeroable)]
pub struct PointLink {
pub header: Header,
pub point: *const PointSpec,
pub before: *const Str,
pub after: *const Str,
pub before_count: u32,
pub after_count: u32,
pub priority: i32,
}
impl_headed!(PointLink);
#[repr(C)]
#[derive(Clone, Copy, Debug, bytemuck::Zeroable)]
pub struct PointHandle {
pub header: Header,
pub id: u32,
pub live: *const AtomicU32,
}
impl_headed!(PointHandle);
impl PointHandle {
pub const EMPTY: Self = Self {
header: Header::of::<Self>(),
id: 0,
live: core::ptr::null(),
};
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct PointVerdict(pub u32);
impl PointVerdict {
pub const PASS: Self = Self(0);
pub const SET: Self = Self(1);
pub const REFUSE: Self = Self(2);
pub const PANICKED: Self = Self(3);
}
pub type PointFn = unsafe extern "system" fn(
input: *const c_void,
value: *mut c_void,
user: *mut c_void,
) -> PointVerdict;