Skip to content

Commit 677ba3f

Browse files
committed
Upgrade to core-foundation 0.5
1 parent cfda5c3 commit 677ba3f

File tree

6 files changed

+19
-38
lines changed

6 files changed

+19
-38
lines changed

system-configuration-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = "MIT/Apache-2.0"
1010
build = "build.rs"
1111

1212
[dependencies]
13-
core-foundation-sys = "0.4.6"
13+
core-foundation-sys = "0.5"
1414

1515
[build-dependencies]
1616
bindgen = "0.31"

system-configuration/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ repository = "https://github.com/mullvad/system-configuration-rs"
99
license = "MIT/Apache-2.0"
1010

1111
[dependencies]
12-
core-foundation = "0.4.6"
13-
core-foundation-sys = "0.4.6"
12+
core-foundation = "0.5"
1413

1514
system-configuration-sys = { path = "../system-configuration-sys", version = "0.1" }

system-configuration/src/bin/set_dns.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ extern crate system_configuration;
22
extern crate system_configuration_sys;
33

44
extern crate core_foundation;
5-
extern crate core_foundation_sys;
65

76
use core_foundation::array::CFArray;
87
use core_foundation::base::TCFType;
@@ -19,7 +18,7 @@ fn main() {
1918
let ipv4_dict = store
2019
.get("State:/Network/Global/IPv4")
2120
.expect("Unable to find global settings")
22-
.downcast::<_, CFDictionary>()
21+
.downcast_into::<CFDictionary>()
2322
.expect("Global IPv4 settings not a dictionary");
2423
println!("Got IPv4 global property list");
2524

@@ -40,7 +39,7 @@ fn main() {
4039
let dns_dictionary =
4140
CFDictionary::from_CFType_pairs(&[(server_addresses_key, server_addresses_value)]);
4241

43-
let success = store.set(pri_service_path, &dns_dictionary);
42+
let success = store.set(pri_service_path, dns_dictionary);
4443
println!("success? {}", success);
4544
}
4645
}

system-configuration/src/bin/watch_dns.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ extern crate system_configuration;
22
extern crate system_configuration_sys;
33

44
extern crate core_foundation;
5-
extern crate core_foundation_sys;
6-
75

86
use core_foundation::array::CFArray;
97
use core_foundation::dictionary::CFDictionary;
10-
use core_foundation::runloop::CFRunLoop;
8+
use core_foundation::runloop::{CFRunLoop, kCFRunLoopCommonModes};
119
use core_foundation::string::CFString;
12-
use core_foundation_sys::runloop::kCFRunLoopCommonModes;
1310

1411
use system_configuration::dynamic_store::{SCDynamicStore, SCDynamicStoreBuilder,
1512
SCDynamicStoreCallBackContext};
@@ -80,6 +77,6 @@ fn my_callback(store: SCDynamicStore, _changed_keys: CFArray<CFString>, payload:
8077
let dns_dictionary =
8178
CFDictionary::from_CFType_pairs(&[(server_addresses_key, server_addresses_value)]);
8279

83-
let success = store.set(payload.service_path.clone(), &dns_dictionary);
80+
let success = store.set(payload.service_path.clone(), dns_dictionary);
8481
println!("callback: {}", success);
8582
}

system-configuration/src/dynamic_store.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
// except according to those terms.
88

99
use core_foundation::array::{CFArray, CFArrayRef};
10-
use core_foundation::base::TCFType;
10+
use core_foundation::base::{TCFType, kCFAllocatorDefault};
1111
use core_foundation::boolean::CFBoolean;
1212
use core_foundation::dictionary::CFDictionary;
1313
use core_foundation::propertylist::{CFPropertyList, CFPropertyListSubClass};
1414
use core_foundation::runloop::CFRunLoopSource;
1515
use core_foundation::string::CFString;
16-
use core_foundation_sys::base::{CFRelease, kCFAllocatorDefault};
1716

1817
pub use system_configuration_sys::dynamic_store::*;
1918

@@ -36,11 +35,8 @@ pub struct SCDynamicStoreCallBackContext<T> {
3635
///
3736
/// This is the safe callback definition, abstracting over the lower level `SCDynamicStoreCallBack`
3837
/// from the `system-configuration-sys` crate.
39-
pub type SCDynamicStoreCallBackT<T> = fn(
40-
store: SCDynamicStore,
41-
changed_keys: CFArray<CFString>,
42-
info: &mut T,
43-
);
38+
pub type SCDynamicStoreCallBackT<T> =
39+
fn(store: SCDynamicStore, changed_keys: CFArray<CFString>, info: &mut T);
4440

4541
/// Builder for [`SCDynamicStore`] sessions.
4642
///
@@ -132,17 +128,13 @@ impl<T> SCDynamicStoreBuilder<T> {
132128
}
133129
}
134130

135-
/// Access to the key-value pairs in the dynamic store of a running system.
136-
///
137-
/// Use the [`SCDynamicStoreBuilder`] to create instances of this.
138-
///
139-
/// [`SCDynamicStoreBuilder`]: struct.SCDynamicStoreBuilder.html
140-
pub struct SCDynamicStore(SCDynamicStoreRef);
141-
142-
impl Drop for SCDynamicStore {
143-
fn drop(&mut self) {
144-
unsafe { CFRelease(self.as_CFTypeRef()) }
145-
}
131+
declare_TCFType!{
132+
/// Access to the key-value pairs in the dynamic store of a running system.
133+
///
134+
/// Use the [`SCDynamicStoreBuilder`] to create instances of this.
135+
///
136+
/// [`SCDynamicStoreBuilder`]: struct.SCDynamicStoreBuilder.html
137+
SCDynamicStore, SCDynamicStoreRef
146138
}
147139

148140
impl_TCFType!(SCDynamicStore, SCDynamicStoreRef, SCDynamicStoreGetTypeID);
@@ -189,7 +181,7 @@ impl SCDynamicStore {
189181

190182
/// If the given key exists in the store, the associated value is returned.
191183
///
192-
/// Use `CFPropertyList::downcast` to cast the result into the correct type.
184+
/// Use `CFPropertyList::downcast_into` to cast the result into the correct type.
193185
pub fn get<S: Into<CFString>>(&self, key: S) -> Option<CFPropertyList> {
194186
let cf_key = key.into();
195187
unsafe {
@@ -205,12 +197,8 @@ impl SCDynamicStore {
205197

206198
/// Sets the value of the given key. Overwrites existing values.
207199
/// Returns `true` on success, false on failure.
208-
pub fn set<S: Into<CFString>, R, V: CFPropertyListSubClass<R>>(
209-
&self,
210-
key: S,
211-
value: &V,
212-
) -> bool {
213-
self.set_raw(key, &value.to_CFPropertyList())
200+
pub fn set<S: Into<CFString>, V: CFPropertyListSubClass>(&self, key: S, value: V) -> bool {
201+
self.set_raw(key, &value.into_CFPropertyList())
214202
}
215203

216204
/// Sets the value of the given key. Overwrites existing values.
@@ -264,7 +252,6 @@ impl SCDynamicStore {
264252
}
265253
}
266254

267-
268255
/// The raw callback used by the safe `SCDynamicStore` to convert from the `SCDynamicStoreCallBack`
269256
/// to the `SCDynamicStoreCallBackT`
270257
unsafe extern "C" fn convert_callback<T>(

system-configuration/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#[macro_use]
22
extern crate core_foundation;
3-
extern crate core_foundation_sys;
43
extern crate system_configuration_sys;
54

65
pub mod dynamic_store;

0 commit comments

Comments
 (0)