Skip to main content

systemconfiguration/
network_protocol.rs

1use crate::{bridge, error::Result, ffi, PropertyList};
2
3#[derive(Clone, Debug)]
4pub struct NetworkProtocol {
5    raw: bridge::OwnedHandle,
6}
7
8impl NetworkProtocol {
9    pub fn type_id() -> u64 {
10        unsafe { ffi::network_protocol::sc_network_protocol_get_type_id() }
11    }
12
13    pub fn configuration(&self) -> Option<PropertyList> {
14        unsafe {
15            bridge::OwnedHandle::from_raw(
16                ffi::network_protocol::sc_network_protocol_copy_configuration(self.raw.as_ptr()),
17            )
18        }
19        .map(PropertyList::from_owned_handle)
20    }
21
22    pub fn is_enabled(&self) -> bool {
23        unsafe { ffi::network_protocol::sc_network_protocol_get_enabled(self.raw.as_ptr()) != 0 }
24    }
25
26    pub fn protocol_type(&self) -> Option<String> {
27        bridge::take_optional_string(unsafe {
28            ffi::network_protocol::sc_network_protocol_copy_protocol_type(self.raw.as_ptr())
29        })
30    }
31
32    pub fn set_configuration(&self, value: &PropertyList) -> Result<()> {
33        let ok = unsafe {
34            ffi::network_protocol::sc_network_protocol_set_configuration(
35                self.raw.as_ptr(),
36                value.as_ptr(),
37            )
38        };
39        bridge::bool_result("sc_network_protocol_set_configuration", ok)
40    }
41
42    pub fn set_enabled(&self, enabled: bool) -> Result<()> {
43        let ok = unsafe {
44            ffi::network_protocol::sc_network_protocol_set_enabled(
45                self.raw.as_ptr(),
46                u8::from(enabled),
47            )
48        };
49        bridge::bool_result("sc_network_protocol_set_enabled", ok)
50    }
51
52    pub(crate) fn from_owned_handle(raw: bridge::OwnedHandle) -> Self {
53        Self { raw }
54    }
55}