Skip to main content

systemconfiguration/
system_configuration.rs

1use serde::Deserialize;
2
3use crate::{bridge, error::Result, ffi, SystemConfigurationError};
4
5#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
6/// Wraps `SCCopyLastError` details.
7pub struct SystemConfigurationLastError {
8    /// Wraps the `SCCopyLastError` domain string.
9    pub domain: String,
10    /// Wraps the `SCCopyLastError` code.
11    pub code: i64,
12    /// Wraps the `SCCopyLastError` description.
13    pub description: String,
14    /// Wraps the `SCCopyLastError` failure reason.
15    pub failure_reason: Option<String>,
16    /// Wraps the `SCCopyLastError` recovery suggestion.
17    pub recovery_suggestion: Option<String>,
18}
19
20#[derive(Clone, Copy, Debug, Default)]
21/// Wraps top-level SystemConfiguration error helpers.
22pub struct SystemConfiguration;
23
24impl SystemConfiguration {
25    /// Wraps `SCCopyLastErrorJSON`.
26    pub fn copy_last_error() -> Result<Option<SystemConfigurationLastError>> {
27        let raw = unsafe { ffi::system_configuration::sc_copy_last_error_json() };
28        if raw.is_null() {
29            return Ok(None);
30        }
31        bridge::parse_json("sc_copy_last_error_json", raw).map(Some)
32    }
33
34    /// Wraps `SCSystemConfigurationErrorDomain`.
35    pub fn error_domain() -> Result<String> {
36        bridge::take_optional_string(unsafe {
37            ffi::system_configuration::sc_system_configuration_error_domain()
38        })
39        .ok_or_else(|| {
40            SystemConfigurationError::null(
41                "sc_system_configuration_error_domain",
42                "bridge returned null SystemConfiguration error domain",
43            )
44        })
45    }
46}