Compare commits
5 Commits
1a292c6316
...
c9b1895e0c
Author | SHA1 | Date | |
---|---|---|---|
c9b1895e0c | |||
7992f3df0e | |||
59c325024a | |||
473212c2e6 | |||
f71b99a4c0 |
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1 +0,0 @@
|
||||
Cargo.lock -merge linguist-generated=false
|
@ -1,12 +0,0 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(unused)]
|
||||
|
||||
pub mod BINDINGS_V1_40_14 {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.14.rs"));
|
||||
}
|
||||
|
||||
pub mod BINDINGS_V1_40_13 {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.13.rs"));
|
||||
}
|
@ -1,17 +1,16 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
mod bindings;
|
||||
use bindings::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SupportedFsvVersion {
|
||||
pub enum SUPPORTED_FSV_VERSIONS {
|
||||
V1_40_14, // 1.40.14
|
||||
V1_40_13, // 1.40.13
|
||||
}
|
||||
|
||||
impl SupportedFsvVersion {
|
||||
impl SUPPORTED_FSV_VERSIONS {
|
||||
fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::V1_40_14 => "1.40.14",
|
||||
@ -20,6 +19,14 @@ impl SupportedFsvVersion {
|
||||
}
|
||||
}
|
||||
|
||||
mod BINDINGS_V1_40_14 {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.14.rs"));
|
||||
}
|
||||
|
||||
mod BINDINGS_V1_40_13 {
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.13.rs"));
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
@ -59,26 +66,26 @@ mod sealed { pub trait Sealed {}}
|
||||
/// Wrapper around the SESAM-VITALE library
|
||||
/// This struct is responsible for loading the library and providing an interface to call its functions.
|
||||
/// The library is loaded at creation and kept in memory until the struct is dropped.
|
||||
pub trait SSVLibraryCommon {
|
||||
pub trait SSVLibrary_Common {
|
||||
fn new(path: &str) -> Result<Self, Error> where Self: Sized;
|
||||
}
|
||||
|
||||
pub trait SSVLibraryVersion: sealed::Sealed {}
|
||||
pub trait SSVLibrary_Version: sealed::Sealed {}
|
||||
|
||||
pub struct V1_40_13 {}
|
||||
impl sealed::Sealed for V1_40_13 {}
|
||||
impl SSVLibraryVersion for V1_40_13 {}
|
||||
impl SSVLibrary_Version for V1_40_13 {}
|
||||
|
||||
pub struct V1_40_14 {}
|
||||
impl sealed::Sealed for V1_40_14 {}
|
||||
impl SSVLibraryVersion for V1_40_14 {}
|
||||
impl SSVLibrary_Version for V1_40_14 {}
|
||||
|
||||
pub struct SSVLibrary<Version: SSVLibraryVersion> {
|
||||
pub struct SSVLibrary<Version: SSVLibrary_Version> {
|
||||
_version: PhantomData<Version>,
|
||||
library: libloading::Library,
|
||||
}
|
||||
|
||||
impl<Version: SSVLibraryVersion> SSVLibraryCommon for SSVLibrary<Version> {
|
||||
impl<Version: SSVLibrary_Version> SSVLibrary_Common for SSVLibrary<Version> {
|
||||
fn new(path: &str) -> Result<Self, Error> {
|
||||
let library = unsafe { libloading::Library::new(path)?};
|
||||
Ok(Self {
|
||||
@ -130,14 +137,14 @@ impl SSVLibrary<V1_40_13> {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_library_path(version: &SupportedFsvVersion) -> String {
|
||||
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}")
|
||||
}
|
||||
|
||||
pub fn sesam_ini_path(version: &SupportedFsvVersion) -> String {
|
||||
pub fn sesam_ini_path(version: &SUPPORTED_FSV_VERSIONS) -> String {
|
||||
let root_path = get_sesam_ini_root_path();
|
||||
let version = version.as_str();
|
||||
format!("{root_path}/{version}/conf/sesam.ini")
|
||||
@ -164,22 +171,22 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_initlib2() {
|
||||
let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
|
||||
let lib_path = &get_library_path(&SUPPORTED_FSV_VERSIONS::V1_40_13);
|
||||
let ssv_library = SSVLibrary::<V1_40_13>::new(lib_path).expect("SSVLibrary::new failed");
|
||||
|
||||
let sesam_ini_str =
|
||||
CString::new(sesam_ini_path(&SupportedFsvVersion::V1_40_13)).expect("CString::new failed");
|
||||
CString::new(sesam_ini_path(&SUPPORTED_FSV_VERSIONS::V1_40_13)).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 lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
|
||||
let lib_path = &get_library_path(&SUPPORTED_FSV_VERSIONS::V1_40_13);
|
||||
let ssv_library = SSVLibrary::<V1_40_13>::new(lib_path).expect("SSVLibrary::new failed");
|
||||
|
||||
let sesam_ini_str =
|
||||
CString::new(sesam_ini_path(&SupportedFsvVersion::V1_40_13)).expect("CString::new failed");
|
||||
CString::new(sesam_ini_path(&SUPPORTED_FSV_VERSIONS::V1_40_13)).expect("CString::new failed");
|
||||
let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap();
|
||||
assert_eq!(result, 0);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user