#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(dead_code)]
use std::mem::size_of;
use std::os::raw::{c_int, c_void};
use std::ptr;
use crate::ported::diskiometer::DiskIOData;
use crate::ported::networkiometer::NetworkIOData;
const VM_LOADAVG: c_int = 2;
const THREAD_PID_OFFSET: libc::pid_t = 100000;
#[repr(C)]
struct loadavg {
ldavg: [u32; 3],
fscale: libc::c_long,
}
pub fn Platform_init() -> bool {
true
}
pub fn Platform_done() {
}
pub fn Platform_setBindings() {
}
pub fn Platform_getUptime() -> c_int {
let mut bootTime: libc::timeval = unsafe { std::mem::zeroed() };
let mib: [c_int; 2] = [libc::CTL_KERN, libc::KERN_BOOTTIME];
let mut size = size_of::<libc::timeval>();
let err = unsafe {
libc::sysctl(
mib.as_ptr(),
2,
&mut bootTime as *mut libc::timeval as *mut c_void,
&mut size,
ptr::null_mut(),
0,
)
};
if err != 0 {
return -1;
}
let mut currTime: libc::timeval = unsafe { std::mem::zeroed() };
unsafe { libc::gettimeofday(&mut currTime, ptr::null_mut()) };
(currTime.tv_sec - bootTime.tv_sec) as c_int
}
pub fn Platform_getLoadAverage(one: &mut f64, five: &mut f64, fifteen: &mut f64) {
let mut loadAverage: loadavg = unsafe { std::mem::zeroed() };
let mib: [c_int; 2] = [libc::CTL_VM, VM_LOADAVG];
let mut size = size_of::<loadavg>();
let err = unsafe {
libc::sysctl(
mib.as_ptr(),
2,
&mut loadAverage as *mut loadavg as *mut c_void,
&mut size,
ptr::null_mut(),
0,
)
};
if err != 0 {
*one = 0.0;
*five = 0.0;
*fifteen = 0.0;
return;
}
*one = loadAverage.ldavg[0] as f64 / loadAverage.fscale as f64;
*five = loadAverage.ldavg[1] as f64 / loadAverage.fscale as f64;
*fifteen = loadAverage.ldavg[2] as f64 / loadAverage.fscale as f64;
}
pub fn Platform_getMaxPid() -> libc::pid_t {
2 * THREAD_PID_OFFSET
}
pub fn Platform_setCPUValues() {
todo!("port of Platform.c:201")
}
pub fn Platform_setMemoryValues() {
todo!("port of Platform.c:243")
}
pub fn Platform_setSwapValues() {
todo!("port of Platform.c:259")
}
pub fn Platform_getProcessEnv() {
todo!("port of Platform.c:265")
}
pub fn Platform_getProcessLocks() {
todo!("port of Platform.c:320")
}
pub fn Platform_getFileDescriptors(used: &mut f64, max: &mut f64) {
let mib_kern_maxfile: [c_int; 2] = [libc::CTL_KERN, libc::KERN_MAXFILES];
let mut sysctl_maxfile: c_int = 0;
let mut size_maxfile = size_of::<c_int>();
if unsafe {
libc::sysctl(
mib_kern_maxfile.as_ptr(),
2,
&mut sysctl_maxfile as *mut c_int as *mut c_void,
&mut size_maxfile,
ptr::null_mut(),
0,
)
} < 0
{
*max = f64::NAN;
} else if size_maxfile != size_of::<c_int>() || sysctl_maxfile < 1 {
*max = f64::NAN;
} else {
*max = sysctl_maxfile as f64;
}
let mib_kern_nfiles: [c_int; 2] = [libc::CTL_KERN, libc::KERN_NFILES];
let mut sysctl_nfiles: c_int = 0;
let mut size_nfiles = size_of::<c_int>();
if unsafe {
libc::sysctl(
mib_kern_nfiles.as_ptr(),
2,
&mut sysctl_nfiles as *mut c_int as *mut c_void,
&mut size_nfiles,
ptr::null_mut(),
0,
)
} < 0
{
*used = f64::NAN;
} else if size_nfiles != size_of::<c_int>() || sysctl_nfiles < 0 {
*used = f64::NAN;
} else {
*used = sysctl_nfiles as f64;
}
}
pub fn Platform_getDiskIO(_data: &mut DiskIOData) -> bool {
false
}
pub fn Platform_getNetworkIO(_data: &mut NetworkIOData) -> bool {
false
}
pub fn findDevice() {
todo!("port of Platform.c:361")
}
pub fn Platform_getBattery() {
todo!("port of Platform.c:376")
}