use crate::error::VZResult;
use std::ffi::c_void;
use super::mac::{MacAuxiliaryStorage, MacHardwareModel, MacMachineIdentifier};
pub trait Platform {
fn as_ptr(&self) -> *mut c_void;
}
pub struct GenericPlatform {
inner: *mut c_void,
}
unsafe impl Send for GenericPlatform {}
impl GenericPlatform {
pub fn new() -> VZResult<Self> {
let obj = unsafe { crate::shim_ffi::abx_platform_generic_new() };
Ok(Self { inner: obj })
}
pub fn is_nested_virt_supported() -> bool {
unsafe { crate::shim_ffi::abx_platform_generic_nested_supported() }
}
pub fn set_nested_virt_enabled(&self, enabled: bool) {
unsafe {
crate::shim_ffi::abx_platform_generic_set_nested(self.inner.cast(), enabled);
}
}
}
impl Default for GenericPlatform {
fn default() -> Self {
Self::new().expect("Failed to create generic platform")
}
}
impl Platform for GenericPlatform {
fn as_ptr(&self) -> *mut c_void {
self.inner
}
}
impl Drop for GenericPlatform {
fn drop(&mut self) {
if !self.inner.is_null() {
unsafe { crate::shim_ffi::abx_object_release(self.inner.cast()) };
}
}
}
pub struct MacPlatform {
inner: *mut c_void,
}
unsafe impl Send for MacPlatform {}
impl MacPlatform {
pub fn new(
hardware_model: &MacHardwareModel,
machine_identifier: &MacMachineIdentifier,
auxiliary_storage: &MacAuxiliaryStorage,
) -> VZResult<Self> {
let obj = unsafe {
crate::shim_ffi::abx_platform_mac_new(
hardware_model.as_ptr().cast(),
machine_identifier.as_ptr().cast(),
auxiliary_storage.as_ptr().cast(),
)
};
Ok(Self { inner: obj })
}
}
impl Platform for MacPlatform {
fn as_ptr(&self) -> *mut c_void {
self.inner
}
}
impl Drop for MacPlatform {
fn drop(&mut self) {
if !self.inner.is_null() {
unsafe { crate::shim_ffi::abx_object_release(self.inner.cast()) };
}
}
}