Struct SCDynamicStoreBuilder

Source
pub struct SCDynamicStoreBuilder<T> { /* private fields */ }
Expand description

Builder for SCDynamicStore sessions.

Implementations§

Source§

impl SCDynamicStoreBuilder<()>

Source

pub fn new<S: Into<CFString>>(name: S) -> Self

Creates a new builder. name is used as the name parameter when creating the SCDynamicStore session.

Examples found in repository?
examples/set_dns.rs (line 17)
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}
More examples
Hide additional examples
examples/watch_dns.rs (line 23)
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}
Source§

impl<T> SCDynamicStoreBuilder<T>

Source

pub fn session_keys(self, session_keys: bool) -> Self

Set wether or not the created SCDynamicStore should have session keys or not. See SCDynamicStoreCreateWithOptions for details.

Defaults to false.

Source

pub fn callback_context<T2>( self, callback_context: SCDynamicStoreCallBackContext<T2>, ) -> SCDynamicStoreBuilder<T2>

Set a callback context (callback function and data to pass to each callback call).

Defaults to having callbacks disabled.

Examples found in repository?
examples/watch_dns.rs (line 24)
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}
Source

pub fn build(self) -> SCDynamicStore

Create the dynamic store session.

Examples found in repository?
examples/set_dns.rs (line 17)
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}
More examples
Hide additional examples
examples/watch_dns.rs (line 25)
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}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.