use crate::core::detector;
use std::ffi::CStr;
use std::os::raw::{c_char, c_int};
#[unsafe(no_mangle)]
pub unsafe extern "C" fn deloxide_flush_logs() -> c_int {
match crate::core::detector::flush_global_detector_logs() {
Ok(_) => 0,
Err(e) => {
eprintln!("Failed to flush logs: {e:#}");
-1
}
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn deloxide_showcase(log_path: *const c_char) -> c_int {
if log_path.is_null() {
return -1;
}
let path_str = unsafe {
match CStr::from_ptr(log_path).to_str() {
Ok(s) => s,
Err(_) => return -1,
}
};
if let Err(e) = detector::flush_global_detector_logs() {
eprintln!("Failed to flush logs: {e:#}");
return -3;
}
match crate::showcase(path_str) {
Ok(_) => 0,
Err(e) => {
eprintln!("Showcase error: {e:#}");
-2
}
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn deloxide_showcase_current() -> c_int {
if let Err(e) = detector::flush_global_detector_logs() {
eprintln!("Failed to flush logs: {e:#}");
return -3;
}
match crate::showcase::showcase_this() {
Ok(_) => 0,
Err(e) => {
if e.to_string().contains("No active log file") {
-1
} else {
eprintln!("Showcase error: {e:#}");
-2
}
}
}
}