use crate::utility::macros::macros::{
get_function_result_number, get_function_result_pointer, get_function_result_str,
};
use crate::{Host, HostNetworkInterface, VboxError};
use vbox_raw::sys_lib::IHostNetworkInterface;
impl Host {
pub fn get_processor_speed(&self, cpu_id: u32) -> Result<u32, VboxError> {
let count = get_function_result_number!(self.object, GetProcessorSpeed, u32, cpu_id)?;
Ok(count)
}
pub fn get_processor_description(&self, cpu_id: u32) -> Result<&'static str, VboxError> {
get_function_result_str!(self.object, GetProcessorDescription, cpu_id)
}
pub fn get_network_interfaces(&self) -> Result<Vec<HostNetworkInterface>, VboxError> {
let mut m_count = 0;
let network_interfaces_ptr = get_function_result_pointer!(
self.object,
GetNetworkInterfaces,
*mut *mut IHostNetworkInterface,
&mut m_count
)?;
let raw_nets = unsafe {
Vec::from_raw_parts(network_interfaces_ptr, m_count as usize, m_count as usize)
};
let mut nets = Vec::new();
for raw_net in raw_nets {
let net_tmp = raw_net.clone();
nets.push(HostNetworkInterface::new(net_tmp));
}
Ok(nets)
}
pub fn get_processor_count(&self) -> Result<u32, VboxError> {
let count = get_function_result_number!(self.object, GetProcessorCount, u32)?;
Ok(count)
}
pub fn get_processor_online_count(&self) -> Result<u32, VboxError> {
let count = get_function_result_number!(self.object, GetProcessorOnlineCount, u32)?;
Ok(count)
}
pub fn get_processor_core_count(&self) -> Result<u32, VboxError> {
let count = get_function_result_number!(self.object, GetProcessorCoreCount, u32)?;
Ok(count)
}
pub fn get_processor_online_core_count(&self) -> Result<u32, VboxError> {
let count = get_function_result_number!(self.object, GetProcessorOnlineCoreCount, u32)?;
Ok(count)
}
pub fn get_memory_size(&self) -> Result<u32, VboxError> {
let count = get_function_result_number!(self.object, GetMemorySize, u32)?;
Ok(count)
}
pub fn get_memory_available(&self) -> Result<u32, VboxError> {
let count = get_function_result_number!(self.object, GetMemoryAvailable, u32)?;
Ok(count)
}
pub fn get_operating_system(&self) -> Result<&'static str, VboxError> {
get_function_result_str!(self.object, GetOperatingSystem)
}
pub fn get_os_version(&self) -> Result<&'static str, VboxError> {
get_function_result_str!(self.object, GetOSVersion)
}
}