sz_rust_sdk/core/
product.rs

1//! Core implementation of SzProduct trait
2
3use crate::{error::SzResult, ffi_call_product, traits::SzProduct, types::JsonString};
4
5/// Core implementation of the SzProduct trait
6pub struct SzProductCore;
7
8impl SzProductCore {
9    pub fn new() -> SzResult<Self> {
10        // Use minimal settings - product module may not need full database settings
11        Self::new_with_params("SzRustSDK-Product", "{}", false)
12    }
13
14    pub fn new_with_params(
15        module_name: &str,
16        ini_params: &str,
17        verbose_logging: bool,
18    ) -> SzResult<Self> {
19        // Initialize the product module with parameters
20        let module_name_c = crate::ffi::helpers::str_to_c_string(module_name)?;
21        let ini_params_c = crate::ffi::helpers::str_to_c_string(ini_params)?;
22        let verbose = if verbose_logging { 1 } else { 0 };
23
24        ffi_call_product!(crate::ffi::bindings::SzProduct_init(
25            module_name_c.as_ptr(),
26            ini_params_c.as_ptr(),
27            verbose
28        ));
29        Ok(Self)
30    }
31}
32
33impl SzProduct for SzProductCore {
34    fn get_license(&self) -> SzResult<JsonString> {
35        let license_ptr = unsafe { crate::ffi::bindings::SzProduct_getLicense() };
36        if license_ptr.is_null() {
37            return Err(crate::error::SzError::unknown("Failed to get license"));
38        }
39        unsafe { crate::ffi::helpers::c_str_to_string_no_free(license_ptr) }
40    }
41
42    fn get_version(&self) -> SzResult<JsonString> {
43        let version_ptr = unsafe { crate::ffi::bindings::SzProduct_getVersion() };
44        if version_ptr.is_null() {
45            return Err(crate::error::SzError::unknown("Failed to get version"));
46        }
47        unsafe { crate::ffi::helpers::c_str_to_string_no_free(version_ptr) }
48    }
49}
50
51// Note: SzProductCore no longer needs Drop implementation
52// since it doesn't manage any resources directly