Skip to content

Commit

Permalink
extend network properties
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMc86 committed Dec 4, 2024
1 parent 9ce1a73 commit e2c612f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ni-syscfg/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl ReadableParameter for String {
}

/// Marker trait for enums to be used as property values.
trait ValueEnum: FromPrimitive {}
pub(crate) trait ValueEnum: FromPrimitive {}

impl<T> ReadableParameter for T
where
Expand Down
7 changes: 6 additions & 1 deletion ni-syscfg/src/system/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Implements system parameters on the session.
mod real_time;
mod network;

use ni_syscfg_sys::{NISysCfgSystemProperty, NISysCfgSystemProperty_NISysCfgSystemPropertyHostname, NISysCfgSystemProperty_NISysCfgSystemPropertyIsLocked, NISysCfgSystemProperty_NISysCfgSystemPropertyIsLockingSupported, NISysCfgSystemProperty_NISysCfgSystemPropertyProductName, NISysCfgSystemProperty_NISysCfgSystemPropertySerialNumber};
use ni_syscfg_sys::{NISysCfgSystemProperty, NISysCfgSystemProperty_NISysCfgSystemPropertyHostname, NISysCfgSystemProperty_NISysCfgSystemPropertyIsLocked, NISysCfgSystemProperty_NISysCfgSystemPropertyIsLockingSupported, NISysCfgSystemProperty_NISysCfgSystemPropertyProductId, NISysCfgSystemProperty_NISysCfgSystemPropertyProductName, NISysCfgSystemProperty_NISysCfgSystemPropertySerialNumber};
use crate::Session;
use crate::parameters::{ApiBool, ReadableParameter};
use crate::error::Result;
Expand Down Expand Up @@ -30,5 +31,9 @@ impl Session {
String::read_system_parameter(self.handle(), NISysCfgSystemProperty_NISysCfgSystemPropertyProductName)
}

pub fn product_code(&self) -> Result<i32> {
i32::read_system_parameter(self.handle(), NISysCfgSystemProperty_NISysCfgSystemPropertyProductId)
}


}
43 changes: 43 additions & 0 deletions ni-syscfg/src/system/network.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use ni_syscfg_sys::{NISysCfgIpAddressMode_NISysCfgIpAddressModeDhcpOnly, NISysCfgIpAddressMode_NISysCfgIpAddressModeDhcpOrLinkLocal, NISysCfgIpAddressMode_NISysCfgIpAddressModeLinkLocalOnly, NISysCfgIpAddressMode_NISysCfgIpAddressModeStatic, NISysCfgSystemProperty_NISysCfgSystemPropertyDnsServer, NISysCfgSystemProperty_NISysCfgSystemPropertyGateway, NISysCfgSystemProperty_NISysCfgSystemPropertyIpAddress, NISysCfgSystemProperty_NISysCfgSystemPropertyIpAddressMode, NISysCfgSystemProperty_NISysCfgSystemPropertyMacAddress, NISysCfgSystemProperty_NISysCfgSystemPropertySubnetMask};
use crate::parameters::{ReadableParameter, ValueEnum};
use crate::Session;
use crate::error::Result;
use num_derive::FromPrimitive;

impl Session {

pub fn mac_address(&self) -> Result<String> {
String::read_system_parameter(self.handle(), NISysCfgSystemProperty_NISysCfgSystemPropertyMacAddress)
}

pub fn ip_address(&self) -> Result<String> {
String::read_system_parameter(self.handle(), NISysCfgSystemProperty_NISysCfgSystemPropertyIpAddress)
}

pub fn subnet_mask(&self) -> Result<String> {
String::read_system_parameter(self.handle(), NISysCfgSystemProperty_NISysCfgSystemPropertySubnetMask)
}

pub fn gateway(&self) -> Result<String> {
String::read_system_parameter(self.handle(), NISysCfgSystemProperty_NISysCfgSystemPropertyGateway)
}

pub fn dns_server(&self) -> Result<String> {
String::read_system_parameter(self.handle(), NISysCfgSystemProperty_NISysCfgSystemPropertyDnsServer)
}

pub fn address_mode(&self) -> Result<NetworkAddressMode> {
NetworkAddressMode::read_system_parameter(self.handle(), NISysCfgSystemProperty_NISysCfgSystemPropertyIpAddressMode)
}
}

#[repr(i32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive)]
pub enum NetworkAddressMode {
Static = NISysCfgIpAddressMode_NISysCfgIpAddressModeStatic,
LinkLocalOnly = NISysCfgIpAddressMode_NISysCfgIpAddressModeLinkLocalOnly,
DhcpOrLinkLocal = NISysCfgIpAddressMode_NISysCfgIpAddressModeDhcpOrLinkLocal,
DhcpOnly = NISysCfgIpAddressMode_NISysCfgIpAddressModeDhcpOnly,
}

impl ValueEnum for NetworkAddressMode {}
2 changes: 0 additions & 2 deletions ni-syscfg/src/system/real_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@ impl RealTimeSession {
pub fn status(&self) -> Result<String> {
String::read_system_parameter(self.handle, NISysCfgSystemProperty_NISysCfgSystemPropertySystemState)
}


}

0 comments on commit e2c612f

Please sign in to comment.