sz_rust_sdk/core/
diagnostic.rs

1//! Core implementation of SzDiagnostic trait
2
3use crate::{
4    error::SzResult,
5    ffi_call,
6    traits::SzDiagnostic,
7    types::{FeatureId, JsonString},
8};
9use std::ptr;
10
11/// Core implementation of the SzDiagnostic trait
12pub struct SzDiagnosticCore {
13    #[allow(dead_code)]
14    handle: *mut std::ffi::c_void,
15}
16
17impl SzDiagnosticCore {
18    pub fn new() -> SzResult<Self> {
19        // Don't call SzDiagnostic_init - rely on the main environment initialization
20        // The diagnostic functions should work once the main Sz_init has been called
21        Ok(Self {
22            handle: ptr::null_mut(),
23        })
24    }
25
26    pub fn new_with_params(
27        _module_name: &str,
28        _ini_params: &str,
29        _verbose_logging: bool,
30    ) -> SzResult<Self> {
31        // For now, treat this the same as new() - the diagnostic component may not need
32        // separate initialization if the main environment is already initialized
33        Self::new()
34    }
35}
36
37impl SzDiagnostic for SzDiagnosticCore {
38    fn check_repository_performance(&self, seconds_to_run: i64) -> SzResult<JsonString> {
39        let result = unsafe {
40            crate::ffi::bindings::SzDiagnostic_checkRepositoryPerformance_helper(seconds_to_run)
41        };
42
43        unsafe { crate::ffi::helpers::process_pointer_result(result) }
44    }
45
46    fn get_feature(&self, feature_id: FeatureId) -> SzResult<JsonString> {
47        let result = unsafe { crate::ffi::bindings::SzDiagnostic_getFeature_helper(feature_id) };
48
49        unsafe { crate::ffi::helpers::process_pointer_result(result) }
50    }
51
52    fn get_repository_info(&self) -> SzResult<JsonString> {
53        let result = unsafe { crate::ffi::bindings::SzDiagnostic_getRepositoryInfo_helper() };
54
55        unsafe { crate::ffi::helpers::process_pointer_result(result) }
56    }
57
58    fn purge_repository(&self) -> SzResult<()> {
59        ffi_call!(crate::ffi::bindings::SzDiagnostic_purgeRepository());
60        Ok(())
61    }
62}
63
64impl Drop for SzDiagnosticCore {
65    fn drop(&mut self) {
66        // Diagnostic doesn't need cleanup in the new API
67    }
68}