pub struct SCDynamicStoreBuilder<T> { /* private fields */ }
Expand description
Builder for SCDynamicStore
sessions.
Implementations§
Source§impl SCDynamicStoreBuilder<()>
impl SCDynamicStoreBuilder<()>
Sourcepub fn new<S: Into<CFString>>(name: S) -> Self
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
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>
impl<T> SCDynamicStoreBuilder<T>
Sourcepub fn session_keys(self, session_keys: bool) -> Self
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
.
Sourcepub fn callback_context<T2>(
self,
callback_context: SCDynamicStoreCallBackContext<T2>,
) -> SCDynamicStoreBuilder<T2>
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}
Sourcepub fn build(self) -> SCDynamicStore
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
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§
impl<T> Freeze for SCDynamicStoreBuilder<T>where
T: Freeze,
impl<T> RefUnwindSafe for SCDynamicStoreBuilder<T>where
T: RefUnwindSafe,
impl<T> !Send for SCDynamicStoreBuilder<T>
impl<T> !Sync for SCDynamicStoreBuilder<T>
impl<T> Unpin for SCDynamicStoreBuilder<T>where
T: Unpin,
impl<T> UnwindSafe for SCDynamicStoreBuilder<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more