pub struct SCDynamicStore(/* private fields */);
Expand description
Access to the key-value pairs in the dynamic store of a running system.
Use the SCDynamicStoreBuilder
to create instances of this.
Implementations§
Source§impl SCDynamicStore
impl SCDynamicStore
Sourcepub fn get_keys<S: Into<CFString>>(
&self,
pattern: S,
) -> Option<CFArray<CFString>>
pub fn get_keys<S: Into<CFString>>( &self, pattern: S, ) -> Option<CFArray<CFString>>
Returns the keys that represent the current dynamic store entries that match the specified
pattern. Or None
if an error occured.
pattern
- A regular expression pattern used to match the dynamic store keys.
Sourcepub fn get_proxies(&self) -> Option<CFDictionary<CFString, CFType>>
pub fn get_proxies(&self) -> Option<CFDictionary<CFString, CFType>>
Returns the key-value pairs that represent the current internet proxy settings. Or None
if
no proxy settings have been defined or if an error occured.
Sourcepub fn get<S: Into<CFString>>(&self, key: S) -> Option<CFPropertyList>
pub fn get<S: Into<CFString>>(&self, key: S) -> Option<CFPropertyList>
If the given key exists in the store, the associated value is returned.
Use CFPropertyList::downcast_into
to cast the result into the correct type.
Examples found in repository?
More examples
66fn get_dns(store: &SCDynamicStore, path: CFString) -> Option<Vec<String>> {
67 let dns_settings = store
68 .get(path)
69 .and_then(CFPropertyList::downcast_into::<CFDictionary>)?;
70 let address_array = dns_settings
71 .find(unsafe { kSCPropNetDNSServerAddresses }.to_void())
72 .map(|ptr| unsafe { CFType::wrap_under_get_rule(*ptr) })
73 .and_then(CFType::downcast_into::<CFArray>)?;
74 let mut result = Vec::with_capacity(address_array.len() as usize);
75 for address_ptr in &address_array {
76 let address =
77 unsafe { CFType::wrap_under_get_rule(*address_ptr) }.downcast_into::<CFString>()?;
78 result.push(address.to_string())
79 }
80 Some(result)
81}
Sourcepub fn set<S: Into<CFString>, V: CFPropertyListSubClass>(
&self,
key: S,
value: V,
) -> bool
pub fn set<S: Into<CFString>, V: CFPropertyListSubClass>( &self, key: S, value: V, ) -> bool
Sets the value of the given key. Overwrites existing values.
Returns true
on success, false on failure.
Examples found in repository?
16fn main() {
17 let store = SCDynamicStoreBuilder::new("my-test-dyn-store").build();
18 let primary_service_uuid = get_primary_service_uuid(&store).expect("No PrimaryService active");
19 println!("PrimaryService UUID: {}", primary_service_uuid);
20
21 let primary_service_path = CFString::new(&format!(
22 "State:/Network/Service/{}/DNS",
23 primary_service_uuid
24 ));
25 println!("PrimaryService path: {}", primary_service_path);
26
27 let dns_dictionary = create_dns_dictionary(&[
28 CFString::from_static_string("8.8.8.8"),
29 CFString::from_static_string("8.8.4.4"),
30 ]);
31
32 let success = store.set(primary_service_path, dns_dictionary);
33 println!("success? {}", success);
34}
Sourcepub fn set_raw<S: Into<CFString>>(&self, key: S, value: &CFPropertyList) -> bool
pub fn set_raw<S: Into<CFString>>(&self, key: S, value: &CFPropertyList) -> bool
Sets the value of the given key. Overwrites existing values.
Returns true
on success, false on failure.
Sourcepub fn remove<S: Into<CFString>>(&self, key: S) -> bool
pub fn remove<S: Into<CFString>>(&self, key: S) -> bool
Removes the value of the specified key from the dynamic store.
Sourcepub fn set_notification_keys<T1, T2>(
&self,
keys: &CFArray<T1>,
patterns: &CFArray<T2>,
) -> bool
pub fn set_notification_keys<T1, T2>( &self, keys: &CFArray<T1>, patterns: &CFArray<T2>, ) -> bool
Specifies a set of keys and key patterns that should be monitored for changes.
Examples found in repository?
17fn main() {
18 let callback_context = SCDynamicStoreCallBackContext {
19 callout: my_callback,
20 info: Context { call_count: 0 },
21 };
22
23 let store = SCDynamicStoreBuilder::new("my-watch-dns-store")
24 .callback_context(callback_context)
25 .build();
26
27 let watch_keys: CFArray<CFString> = CFArray::from_CFTypes(&[]);
28 let watch_patterns =
29 CFArray::from_CFTypes(&[CFString::from("(State|Setup):/Network/Service/.*/DNS")]);
30
31 if store.set_notification_keys(&watch_keys, &watch_patterns) {
32 println!("Registered for notifications");
33 } else {
34 panic!("Unable to register notifications");
35 }
36
37 let run_loop_source = store.create_run_loop_source();
38 let run_loop = CFRunLoop::get_current();
39 run_loop.add_source(&run_loop_source, unsafe { kCFRunLoopCommonModes });
40
41 println!("Entering run loop");
42 CFRunLoop::run_current();
43}
Sourcepub fn create_run_loop_source(&self) -> CFRunLoopSource
pub fn create_run_loop_source(&self) -> CFRunLoopSource
Creates a run loop source object that can be added to the application’s run loop.
Examples found in repository?
17fn main() {
18 let callback_context = SCDynamicStoreCallBackContext {
19 callout: my_callback,
20 info: Context { call_count: 0 },
21 };
22
23 let store = SCDynamicStoreBuilder::new("my-watch-dns-store")
24 .callback_context(callback_context)
25 .build();
26
27 let watch_keys: CFArray<CFString> = CFArray::from_CFTypes(&[]);
28 let watch_patterns =
29 CFArray::from_CFTypes(&[CFString::from("(State|Setup):/Network/Service/.*/DNS")]);
30
31 if store.set_notification_keys(&watch_keys, &watch_patterns) {
32 println!("Registered for notifications");
33 } else {
34 panic!("Unable to register notifications");
35 }
36
37 let run_loop_source = store.create_run_loop_source();
38 let run_loop = CFRunLoop::get_current();
39 run_loop.add_source(&run_loop_source, unsafe { kCFRunLoopCommonModes });
40
41 println!("Entering run loop");
42 CFRunLoop::run_current();
43}
Trait Implementations§
Source§impl Clone for SCDynamicStore
impl Clone for SCDynamicStore
Source§fn clone(&self) -> SCDynamicStore
fn clone(&self) -> SCDynamicStore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Drop for SCDynamicStore
impl Drop for SCDynamicStore
Source§impl PartialEq for SCDynamicStore
impl PartialEq for SCDynamicStore
Source§impl TCFType for SCDynamicStore
impl TCFType for SCDynamicStore
Source§type Ref = *const __SCDynamicStore
type Ref = *const __SCDynamicStore
Source§fn as_concrete_TypeRef(&self) -> SCDynamicStoreRef
fn as_concrete_TypeRef(&self) -> SCDynamicStoreRef
TypeRef
.Source§unsafe fn wrap_under_get_rule(reference: SCDynamicStoreRef) -> Self
unsafe fn wrap_under_get_rule(reference: SCDynamicStoreRef) -> Self
CFTypeRef
subclass. Use this
when following Core Foundation’s “Get Rule”. The reference count is bumped.Source§fn as_CFTypeRef(&self) -> CFTypeRef
fn as_CFTypeRef(&self) -> CFTypeRef
CFTypeRef
. The reference count is not adjusted.Source§unsafe fn wrap_under_create_rule(reference: SCDynamicStoreRef) -> Self
unsafe fn wrap_under_create_rule(reference: SCDynamicStoreRef) -> Self
CFTypeRef
subclass. Use this
when following Core Foundation’s “Create Rule”. The reference count is not bumped.Source§fn as_CFType(&self) -> CFType
fn as_CFType(&self) -> CFType
CFType
. The reference count is incremented by one.Source§fn into_CFType(self) -> CFTypewhere
Self: Sized,
fn into_CFType(self) -> CFTypewhere
Self: Sized,
CFType
. Consumes self and avoids changing the reference
count.Source§fn retain_count(&self) -> isize
fn retain_count(&self) -> isize
Source§fn instance_of<OtherCFType>(&self) -> boolwhere
OtherCFType: TCFType,
fn instance_of<OtherCFType>(&self) -> boolwhere
OtherCFType: TCFType,
true
if this value is an instance of another type.