From 3c1e691cb8f789b73eddeebe4950ee76acc4b209 Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Tue, 1 Oct 2024 19:13:03 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Cr=C3=A9ation=20de=20la=20crate=20fsv,?= =?UTF-8?q?=20couche=20de=20haut=20niveau=20pour=20l'usage=20des=20librair?= =?UTF-8?q?ies=20FSV?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 9 +++++ Cargo.toml | 1 + crates/fsv/Cargo.toml | 10 ++++++ crates/fsv/src/lib.rs | 1 + crates/fsv/src/ssv.rs | 83 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 crates/fsv/Cargo.toml create mode 100644 crates/fsv/src/lib.rs create mode 100644 crates/fsv/src/ssv.rs diff --git a/Cargo.lock b/Cargo.lock index b9200a6..473e030 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1963,6 +1963,15 @@ dependencies = [ "libc", ] +[[package]] +name = "fsv" +version = "0.1.0" +dependencies = [ + "fsv-sys", + "thiserror", + "utils", +] + [[package]] name = "fsv-sys" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 5c19dfc..f7ad9d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "crates/backend", "crates/desktop", "crates/sesam-vitale", + "crates/fsv", "crates/fsv-sys", "crates/utils", "migration", diff --git a/crates/fsv/Cargo.toml b/crates/fsv/Cargo.toml new file mode 100644 index 0000000..385ee27 --- /dev/null +++ b/crates/fsv/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "fsv" +version = "0.1.0" +edition = "2021" + +[dependencies] +thiserror = "1.0.64" + +fsv-sys = { path = "../fsv-sys" } +utils = { path = "../utils" } \ No newline at end of file diff --git a/crates/fsv/src/lib.rs b/crates/fsv/src/lib.rs new file mode 100644 index 0000000..77a1012 --- /dev/null +++ b/crates/fsv/src/lib.rs @@ -0,0 +1 @@ +mod ssv; diff --git a/crates/fsv/src/ssv.rs b/crates/fsv/src/ssv.rs new file mode 100644 index 0000000..89cd354 --- /dev/null +++ b/crates/fsv/src/ssv.rs @@ -0,0 +1,83 @@ +use thiserror::Error; + +use fsv_sys::{get_library_path, Error as FsvError, SSVLibrary, SSVLibrary_Common, SUPPORTED_FSV_VERSIONS, V1_40_13, V1_40_14}; + +#[derive(Error, Debug)] +pub enum Error { + #[error(transparent)] + SysLibrary(#[from] FsvError) +} + +/// Enum to hold the different versions of the SSV library +enum SsvLibraryVersion { + V1_40_13(SSVLibrary), + V1_40_14(SSVLibrary), +} + +/// Struct to hold the SSV library and access its functions +pub struct SSV { + library: SsvLibraryVersion, +} + +impl SSV { + fn new(version: SUPPORTED_FSV_VERSIONS) -> Result { + let library = match version { + SUPPORTED_FSV_VERSIONS::V1_40_13 => { + let lib_path = get_library_path(&version); + let library = SSVLibrary::::new(&lib_path)?; + SsvLibraryVersion::V1_40_13(library) + }, + SUPPORTED_FSV_VERSIONS::V1_40_14 => { + let lib_path = get_library_path(&version); + let library = SSVLibrary::::new(&lib_path)?; + SsvLibraryVersion::V1_40_14(library) + }, + }; + Ok(Self { + library, + }) + } + + /// # Initialize the SSV library + /// Implement: SSV_InitLIB2 + pub fn init_library(&self, sesam_ini_path: &str) -> Result<(), Error> { + let sesam_ini_path = std::ffi::CString::new(sesam_ini_path).expect("CString::new failed"); + match &self.library { + SsvLibraryVersion::V1_40_13(library) => { + let result = unsafe { library.ssv_init_lib2(sesam_ini_path.as_ptr()) }?; + println!("SSV_InitLIB2 result: {}", result); + }, + SsvLibraryVersion::V1_40_14(library) => { + let result = unsafe { library.ssv_init_lib2(sesam_ini_path.as_ptr()) }?; + println!("SSV_InitLIB2 result: {}", result); + }, + } + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use std::env; + + use utils::config::load_config; + + use super::*; + + fn init() -> SSV { + load_config().unwrap(); + SSV::new(SUPPORTED_FSV_VERSIONS::V1_40_13).expect("SSV::new failed") + } + + #[test] + fn test_init_library() { + let lib = init(); + let sesam_ini_path = env::var("SESAM_INI_PATH").expect("SESAM_INI_PATH must be set"); + lib.init_library(&sesam_ini_path).expect("init_library failed"); + } + + #[test] + fn test_ssv() { + assert_eq!("ssv", "ssv"); + } +}