Skip to content

Commit 1477c9a

Browse files
author
luozijun
committed
Update .
1 parent eb2edac commit 1477c9a

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

system-configuration/examples/network_configuration.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1+
extern crate core_foundation;
12
extern crate system_configuration;
23

4+
use core_foundation::base::kCFAllocatorDefault;
5+
36
use system_configuration::dynamic_store::SCDynamicStoreBuilder;
47
use system_configuration::network_configuration::{global_router, SCNetworkInterface,
58
SCNetworkService};
9+
use system_configuration::preferences::SCPreferences;
610

711
// This example will output network-global-service, network-global-interface, network-global-router,
812
// network-service-order-list, network-services and network-interfaces to stdout.
913

1014
fn main() {
11-
let store = SCDynamicStoreBuilder::new("session_name").build();
15+
let session_name = "session_name";
16+
let prefs = SCPreferences::new(unsafe { kCFAllocatorDefault }, session_name, None);
17+
let store = SCDynamicStoreBuilder::new(session_name).build();
1218

13-
let service = SCNetworkService::global(&store).unwrap();
19+
let service = SCNetworkService::global(&prefs, &store).unwrap();
1420
println!("Global Service:\n{:?}\n", service);
1521
println!("Global Interface:\n{:?}\n", service.interface());
1622
println!("Global Service Router:\n{:?}\n", global_router(&store));
1723

1824
println!("\n-listnetworkserviceorder:");
19-
for service in SCNetworkService::list_order() {
25+
for service in SCNetworkService::list_order(&prefs) {
2026
println!("{:?}", service);
2127
}
2228

2329
println!("\n-listallnetworkservices:");
24-
for service in SCNetworkService::list() {
30+
for service in SCNetworkService::list(&prefs) {
2531
println!("{:?}", service);
2632
}
2733

system-configuration/src/network_configuration.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ impl SCNetworkService {
134134
.iter()
135135
.map(|item| item.downcast::<SCNetworkService>().unwrap())
136136
.collect::<Vec<SCNetworkService>>()
137+
138+
139+
// let array: CFArray<SCNetworkService> = unsafe {
140+
// CFArray::wrap_under_get_rule(SCNetworkServiceCopyAll(prefs.as_concrete_TypeRef()))
141+
// };
142+
143+
// array
144+
// .iter()
145+
// .map(|item| item.as_CFType().downcast::<SCNetworkService>().unwrap())
146+
// .collect::<Vec<SCNetworkService>>()
137147
}
138148

139149
/// Returns the user-specified ordering of network services within the specified
@@ -148,7 +158,6 @@ impl SCNetworkService {
148158

149159
for item in array.iter() {
150160
if let Some(id) = item.downcast::<CFString>() {
151-
println!("id: {:?}", id);
152161
if let Some(serv) = SCNetworkService::from_id(prefs, id.to_string().as_str()) {
153162
services.push(serv);
154163
}

0 commit comments

Comments
 (0)