systemconfiguration/
network_protocol.rs1use 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 { bridge::OwnedHandle::from_raw(ffi::network_protocol::sc_network_protocol_copy_configuration(self.raw.as_ptr())) }
15 .map(PropertyList::from_owned_handle)
16 }
17
18 pub fn is_enabled(&self) -> bool {
19 unsafe { ffi::network_protocol::sc_network_protocol_get_enabled(self.raw.as_ptr()) != 0 }
20 }
21
22 pub fn protocol_type(&self) -> Option<String> {
23 bridge::take_optional_string(unsafe {
24 ffi::network_protocol::sc_network_protocol_copy_protocol_type(self.raw.as_ptr())
25 })
26 }
27
28 pub fn set_configuration(&self, value: &PropertyList) -> Result<()> {
29 let ok = unsafe { ffi::network_protocol::sc_network_protocol_set_configuration(self.raw.as_ptr(), value.as_ptr()) };
30 bridge::bool_result("sc_network_protocol_set_configuration", ok)
31 }
32
33 pub fn set_enabled(&self, enabled: bool) -> Result<()> {
34 let ok = unsafe { ffi::network_protocol::sc_network_protocol_set_enabled(self.raw.as_ptr(), u8::from(enabled)) };
35 bridge::bool_result("sc_network_protocol_set_enabled", ok)
36 }
37
38 pub(crate) fn from_owned_handle(raw: bridge::OwnedHandle) -> Self {
39 Self { raw }
40 }
41}