Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
luozijun committed Mar 13, 2018
1 parent c070df9 commit 799ed30
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
3 changes: 3 additions & 0 deletions system-configuration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ readme = "../README.md"
[dependencies]
core-foundation = "0.5"
system-configuration-sys = { path = "../system-configuration-sys", version = "0.1" }

[features]
nightly = []
4 changes: 3 additions & 1 deletion system-configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
//!
//! [SystemConfiguration]: https://developer.apple.com/documentation/systemconfiguration?language=objc
//! [`system-configuration-sys`]: https://crates.io/crates/system-configuration-sys
#![feature(test)]
#![cfg_attr(all(feature = "nightly", test), feature(test))]
#![deny(missing_docs)]

#[macro_use]
extern crate core_foundation;
extern crate system_configuration_sys;
#[cfg(all(feature = "nightly", test))]
extern crate test;

pub mod dynamic_store;
pub mod preferences;
Expand Down
25 changes: 15 additions & 10 deletions system-configuration/src/network_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ impl SCNetworkService {
.iter()
.map(|item| item.downcast::<SCNetworkService>().unwrap())
.collect::<Vec<SCNetworkService>>()


// let array: CFArray<SCNetworkService> = unsafe {
// CFArray::wrap_under_get_rule(SCNetworkServiceCopyAll(prefs.as_concrete_TypeRef()))
// };

// array
// .iter()
// .map(|item| item.as_CFType().downcast::<SCNetworkService>().unwrap())
Expand All @@ -149,12 +149,17 @@ impl SCNetworkService {
/// Returns the user-specified ordering of network services within the specified
/// preferences.
pub fn list_order(prefs: &SCPreferences) -> Vec<SCNetworkService> {
let netset = unsafe { SCNetworkSetCopyCurrent(prefs.as_concrete_TypeRef()) };
let mut services = Vec::new();

let array: CFArray<CFType> =
unsafe { CFArray::wrap_under_get_rule(SCNetworkSetGetServiceOrder(netset)) };
let netset = unsafe { SCNetworkSetCopyCurrent(prefs.as_concrete_TypeRef()) };

let mut services = Vec::new();
let array: CFArray<CFType> = unsafe {
let arr_ref = SCNetworkSetGetServiceOrder(netset);
if arr_ref.is_null() {
return services;
}
CFArray::wrap_under_get_rule(arr_ref)
};

for item in array.iter() {
if let Some(id) = item.downcast::<CFString>() {
Expand Down Expand Up @@ -416,7 +421,7 @@ impl fmt::Debug for SCNetworkInterface {
}


#[test]
#[cfg(all(feature = "nightly", test))]
fn test_network_service() {
use core_foundation::base::kCFAllocatorDefault;

Expand All @@ -426,11 +431,11 @@ fn test_network_service() {
for network_service in list.iter() {
let network_service_id = network_service.id();
let res = SCNetworkService::from_id(&prefs, &network_service_id);

assert!(res.is_some());
let res = res.unwrap();

assert_eq!(res.id(), network_service.id());
assert_eq!(res.name(), network_service.name());
}
}
}

0 comments on commit 799ed30

Please sign in to comment.