feat: handle multi-version bindings generation
This commit is contained in:
@ -2,8 +2,23 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SUPPORTED_FSV_VERSIONS {
|
||||
V1_40_14, // 1.40.14
|
||||
V1_40_13, // 1.40.13
|
||||
}
|
||||
|
||||
impl SUPPORTED_FSV_VERSIONS {
|
||||
fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::V1_40_14 => "1.40.14",
|
||||
Self::V1_40_13 => "1.40.13",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod BINDINGS {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.13.rs"));
|
||||
}
|
||||
|
||||
// We need to keep the this use statement to get `ssv_function` macro working well
|
||||
@ -41,28 +56,51 @@ pub enum Error {
|
||||
/// The library is loaded at creation and kept in memory until the struct is dropped.
|
||||
#[derive(Debug)]
|
||||
pub struct SSVLibrary {
|
||||
version: SUPPORTED_FSV_VERSIONS,
|
||||
library: libloading::Library,
|
||||
}
|
||||
|
||||
pub fn get_library_path() -> String {
|
||||
fn get_library_name() -> &'static str {
|
||||
// TODO : Use libloading::library_filename to get platform-specific filename ?
|
||||
"/opt/santesocial/fsv/1.40.13/lib/libssvlux64.so".to_string()
|
||||
"libssvlux64.so"
|
||||
}
|
||||
|
||||
fn get_library_root_path() -> &'static str {
|
||||
"/opt/santesocial/fsv"
|
||||
}
|
||||
|
||||
fn get_sesam_ini_root_path() -> &'static str {
|
||||
"/etc/opt/santesocial/fsv"
|
||||
}
|
||||
|
||||
impl SSVLibrary {
|
||||
pub fn new(library_path: &str) -> Result<Self, Error> {
|
||||
pub fn new(version: SUPPORTED_FSV_VERSIONS) -> Result<Self, Error> {
|
||||
let library_path = Self::get_library_path(&version);
|
||||
let library = unsafe { libloading::Library::new(library_path)? };
|
||||
Ok(SSVLibrary { library })
|
||||
Ok(SSVLibrary { version, library })
|
||||
}
|
||||
|
||||
pub fn library(&self) -> &libloading::Library {
|
||||
&self.library
|
||||
}
|
||||
|
||||
pub fn sesam_ini_path(&self) -> String {
|
||||
let root_path = get_sesam_ini_root_path();
|
||||
let version = self.version.as_str();
|
||||
format!("{root_path}/{version}/conf/sesam.ini")
|
||||
}
|
||||
|
||||
pub fn get_library_path(version: &SUPPORTED_FSV_VERSIONS) -> String {
|
||||
let root_path = get_library_root_path();
|
||||
let library_name = get_library_name();
|
||||
let version = version.as_str();
|
||||
format!("{root_path}/{version}/lib/{library_name}")
|
||||
}
|
||||
|
||||
ssv_function!(SSV_InitLIB2, ssv_init_lib2, {
|
||||
pcFichierSesam: *const i8
|
||||
});
|
||||
|
||||
|
||||
ssv_function!(SSV_LireConfig, ssv_lire_config, {
|
||||
pZDataOut: *mut *mut libc::c_void,
|
||||
psTailleDataOut: *mut usize
|
||||
@ -81,26 +119,26 @@ impl SSVLibrary {
|
||||
mod test {
|
||||
use std::{ffi::CString, ptr};
|
||||
|
||||
use super::*;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_initlib2() {
|
||||
let library_path = get_library_path();
|
||||
let ssv_library = SSVLibrary::new(&library_path).expect("SSVLibrary::new failed");
|
||||
let ssv_library =
|
||||
SSVLibrary::new(SUPPORTED_FSV_VERSIONS::V1_40_13).expect("SSVLibrary::new failed");
|
||||
|
||||
let sesam_ini_str = CString::new("/etc/opt/santesocial/fsv/1.40.13/conf/sesam.ini")
|
||||
.expect("CString::new failed");
|
||||
let sesam_ini_str =
|
||||
CString::new(ssv_library.sesam_ini_path()).expect("CString::new failed");
|
||||
let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap();
|
||||
assert_eq!(result, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lire_config_and_carte_ps() {
|
||||
let library_path = get_library_path();
|
||||
let ssv_library = SSVLibrary::new(&library_path).expect("SSVLibrary::new failed");
|
||||
let ssv_library =
|
||||
SSVLibrary::new(SUPPORTED_FSV_VERSIONS::V1_40_13).expect("SSVLibrary::new failed");
|
||||
|
||||
let sesam_ini_str = CString::new("/etc/opt/santesocial/fsv/1.40.13/conf/sesam.ini")
|
||||
.expect("CString::new failed");
|
||||
let sesam_ini_str =
|
||||
CString::new(ssv_library.sesam_ini_path()).expect("CString::new failed");
|
||||
let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap();
|
||||
assert_eq!(result, 0);
|
||||
|
||||
@ -109,10 +147,10 @@ mod test {
|
||||
let result = unsafe { ssv_library.ssv_lire_config(&mut buffer_ptr, &mut size) }.unwrap();
|
||||
assert_eq!(result, 0);
|
||||
|
||||
let nom_ressource_ps = CString::new("Gemalto PC Twin Reader (645D94C3) 00 00")
|
||||
.expect("CString::new failed");
|
||||
let nom_ressource_lecteur = CString::new("Gemalto PC Twin Reader (645D94C3) 00 00")
|
||||
.expect("CString::new failed");
|
||||
let nom_ressource_ps =
|
||||
CString::new("Gemalto PC Twin Reader (645D94C3) 00 00").expect("CString::new failed");
|
||||
let nom_ressource_lecteur =
|
||||
CString::new("Gemalto PC Twin Reader (645D94C3) 00 00").expect("CString::new failed");
|
||||
let code_porteur_ps = CString::new("1234").expect("CString::new failed");
|
||||
let mut buffer_ptr: *mut libc::c_void = ptr::null_mut();
|
||||
let mut size: libc::size_t = 0;
|
||||
@ -124,7 +162,8 @@ mod test {
|
||||
&mut buffer_ptr,
|
||||
&mut size,
|
||||
)
|
||||
}.unwrap();
|
||||
}
|
||||
.unwrap();
|
||||
assert_eq!(result, 0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user