pub fn PNP_NOTIFICATION() -> &'static CStrExpand description
A special reader name for detecting card reader insertions and removals.
ยงNote
This function is a wrapper around a constant, and is intended to be used as such.
Examples found in repository?
examples/cancel.rs (line 28)
13fn main() {
14 // Get a context.
15 let ctx = Context::establish(Scope::User).expect("failed to establish context");
16
17 // Spawn a thread which waits for a key-press then cancels the operation.
18 {
19 let ctx = ctx.clone();
20 std::thread::spawn(move || {
21 wait_for_enter_keypress();
22 ctx.cancel().expect("failed to cancel");
23 });
24 }
25
26 // Set up the blocking call, and wait for cancel or timeout.
27 println!("Entering blocking call; press Enter to cancel");
28 let mut reader_states = vec![ReaderState::new(PNP_NOTIFICATION(), State::UNAWARE)];
29 match ctx.get_status_change(Duration::from_secs(5), &mut reader_states) {
30 Ok(()) => {
31 println!("Blocking call exited normally");
32 }
33 Err(Error::Cancelled) => {
34 println!("Blocking call canceled");
35 }
36 Err(Error::Timeout) => {
37 println!("Blocking call timed out");
38 }
39 Err(error) => {
40 panic!("failed to get status changes: {:?}", error);
41 }
42 }
43}More examples
examples/monitor.rs (line 10)
4fn main() {
5 let ctx = Context::establish(Scope::User).expect("failed to establish context");
6
7 let mut readers_buf = [0; 2048];
8 let mut reader_states = vec![
9 // Listen for reader insertions/removals, if supported.
10 ReaderState::new(PNP_NOTIFICATION(), State::UNAWARE),
11 ];
12 loop {
13 // Remove dead readers.
14 fn is_dead(rs: &ReaderState) -> bool {
15 rs.event_state().intersects(State::UNKNOWN | State::IGNORE)
16 }
17 for rs in &reader_states {
18 if is_dead(rs) {
19 println!("Removing {:?}", rs.name());
20 }
21 }
22 reader_states.retain(|rs| !is_dead(rs));
23
24 // Add new readers.
25 let names = ctx.list_readers(&mut readers_buf).expect("failed to list readers");
26 for name in names {
27 if !reader_states.iter().any(|rs| rs.name() == name) {
28 println!("Adding {:?}", name);
29 reader_states.push(ReaderState::new(name, State::UNAWARE));
30 }
31 }
32
33 // Update the view of the state to wait on.
34 for rs in &mut reader_states {
35 rs.sync_current_state();
36 }
37
38 // Wait until the state changes.
39 ctx.get_status_change(None, &mut reader_states)
40 .expect("failed to get status change");
41
42 // Print current state.
43 println!();
44 for rs in &reader_states {
45 if rs.name() != PNP_NOTIFICATION() {
46 println!("{:?} {:?} {:?}", rs.name(), rs.event_state(), rs.atr());
47 }
48 }
49 }
50}