WIP: creation-sys-crate-ssv #69
@ -1,8 +1,8 @@
|
|||||||
mod bindings;
|
mod bindings;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
use bindings::SSV_LireConfig;
|
use bindings::{SSV_InitLIB2, SSV_LireConfig, SSV_TermLIB};
|
||||||
use std::{fmt, ptr};
|
use std::{ffi::CString, fmt, path::Path, ptr};
|
||||||
use types::serialization_types::{read_from_buffer, Configuration};
|
use types::serialization_types::{read_from_buffer, Configuration};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[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> {
|
pub fn read_config() -> Result<Configuration, SesamVitaleError> {
|
||||||
let mut buffer_ptr: *mut libc::c_void = ptr::null_mut();
|
let mut buffer_ptr: *mut libc::c_void = ptr::null_mut();
|
||||||
let mut size: libc::size_t = 0;
|
let mut size: libc::size_t = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user