WIP: creation-sys-crate-ssv #69

Closed
florian_briand wants to merge 12 commits from creation-sys-crate-ssv into main
Showing only changes of commit ecd84bf242 - Show all commits

View File

@ -1,8 +1,8 @@
mod bindings;
pub mod types;
use bindings::SSV_LireConfig;
use std::{fmt, ptr};
use bindings::{SSV_InitLIB2, SSV_LireConfig, SSV_TermLIB};
use std::{ffi::CString, fmt, path::Path, ptr};
use types::serialization_types::{read_from_buffer, Configuration};
#[derive(Debug)]
@ -16,6 +16,29 @@ impl fmt::Display for SesamVitaleError {
}
}
pub fn init_library(sesam_ini_path: &Path) -> Result<(), SesamVitaleError> {
// TODO: better error handling
let path_str = sesam_ini_path.to_str().unwrap();
let path_ptr = CString::new(path_str).expect("failed to create cstring");
let exit_code: u16 = unsafe { SSV_InitLIB2(path_ptr.as_ptr()) };
if exit_code != 0 {
let error = SesamVitaleError { code: exit_code };
return Err(error);
};
Ok(())
}
pub fn close_library() -> Result<(), SesamVitaleError> {
let exit_code: u16 = unsafe { SSV_TermLIB() };
if exit_code != 0 {
let error = SesamVitaleError { code: exit_code };
return Err(error);
};
Ok(())
}
pub fn read_config() -> Result<Configuration, SesamVitaleError> {
let mut buffer_ptr: *mut libc::c_void = ptr::null_mut();
let mut size: libc::size_t = 0;