use crate::host::HostHandlers;
use clack_common::extensions::*;
use std::ffi::{CStr, c_void};
use std::marker::PhantomData;
use std::ptr::NonNull;
pub struct HostExtensions<'a, H: ?Sized> {
found: Option<NonNull<c_void>>,
requested: &'a CStr,
plugin_type: PhantomData<H>,
}
impl<'a, H: HostHandlers> HostExtensions<'a, H> {
#[inline]
pub(crate) fn new(requested: &'a CStr) -> Self {
Self {
found: None,
requested,
plugin_type: PhantomData,
}
}
#[inline]
pub(crate) fn found(&self) -> *const c_void {
self.found
.map(|p| p.as_ptr())
.unwrap_or(core::ptr::null_mut())
}
pub fn register<E: ExtensionImplementation<H, ExtensionSide = HostExtensionSide>>(
&mut self,
) -> &mut Self {
if self.found.is_some() {
return self;
}
if E::IDENTIFIERS.contains(&self.requested) {
self.found = Some(E::IMPLEMENTATION.as_ptr())
}
self
}
}