Struct pcsc::ReaderState
source · #[repr(C)]pub struct ReaderState { /* private fields */ }
Expand description
Implementations§
source§impl ReaderState
impl ReaderState
sourcepub fn new<T: Into<CString>>(name: T, current_state: State) -> ReaderState
pub fn new<T: Into<CString>>(name: T, current_state: State) -> ReaderState
Create a ReaderState for a card reader with a given presumed state.
Examples found in repository?
examples/cancel.rs (line 28)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn main() {
// Get a context.
let ctx = Context::establish(Scope::User).expect("failed to establish context");
// Spawn a thread which waits for a key-press then cancels the operation.
{
let ctx = ctx.clone();
std::thread::spawn(move || {
wait_for_enter_keypress();
ctx.cancel().expect("failed to cancel");
});
}
// Set up the blocking call, and wait for cancel or timeout.
println!("Entering blocking call; press Enter to cancel");
let mut reader_states = vec![ReaderState::new(PNP_NOTIFICATION(), State::UNAWARE)];
match ctx.get_status_change(Duration::from_secs(5), &mut reader_states) {
Ok(()) => {
println!("Blocking call exited normally");
}
Err(Error::Cancelled) => {
println!("Blocking call canceled");
}
Err(Error::Timeout) => {
println!("Blocking call timed out");
}
Err(error) => {
panic!("failed to get status changes: {:?}", error);
}
}
}
More examples
examples/monitor.rs (line 10)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
fn main() {
let ctx = Context::establish(Scope::User).expect("failed to establish context");
let mut readers_buf = [0; 2048];
let mut reader_states = vec![
// Listen for reader insertions/removals, if supported.
ReaderState::new(PNP_NOTIFICATION(), State::UNAWARE),
];
loop {
// Remove dead readers.
fn is_dead(rs: &ReaderState) -> bool {
rs.event_state().intersects(State::UNKNOWN | State::IGNORE)
}
for rs in &reader_states {
if is_dead(rs) {
println!("Removing {:?}", rs.name());
}
}
reader_states.retain(|rs| !is_dead(rs));
// Add new readers.
let names = ctx.list_readers(&mut readers_buf).expect("failed to list readers");
for name in names {
if !reader_states.iter().any(|rs| rs.name() == name) {
println!("Adding {:?}", name);
reader_states.push(ReaderState::new(name, State::UNAWARE));
}
}
// Update the view of the state to wait on.
for rs in &mut reader_states {
rs.sync_current_state();
}
// Wait until the state changes.
ctx.get_status_change(None, &mut reader_states)
.expect("failed to get status change");
// Print current state.
println!();
for rs in &reader_states {
if rs.name() != PNP_NOTIFICATION() {
println!("{:?} {:?} {:?}", rs.name(), rs.event_state(), rs.atr());
}
}
}
}
sourcepub fn name(&self) -> &CStr
pub fn name(&self) -> &CStr
The name of the card reader.
Examples found in repository?
examples/monitor.rs (line 19)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
fn main() {
let ctx = Context::establish(Scope::User).expect("failed to establish context");
let mut readers_buf = [0; 2048];
let mut reader_states = vec![
// Listen for reader insertions/removals, if supported.
ReaderState::new(PNP_NOTIFICATION(), State::UNAWARE),
];
loop {
// Remove dead readers.
fn is_dead(rs: &ReaderState) -> bool {
rs.event_state().intersects(State::UNKNOWN | State::IGNORE)
}
for rs in &reader_states {
if is_dead(rs) {
println!("Removing {:?}", rs.name());
}
}
reader_states.retain(|rs| !is_dead(rs));
// Add new readers.
let names = ctx.list_readers(&mut readers_buf).expect("failed to list readers");
for name in names {
if !reader_states.iter().any(|rs| rs.name() == name) {
println!("Adding {:?}", name);
reader_states.push(ReaderState::new(name, State::UNAWARE));
}
}
// Update the view of the state to wait on.
for rs in &mut reader_states {
rs.sync_current_state();
}
// Wait until the state changes.
ctx.get_status_change(None, &mut reader_states)
.expect("failed to get status change");
// Print current state.
println!();
for rs in &reader_states {
if rs.name() != PNP_NOTIFICATION() {
println!("{:?} {:?} {:?}", rs.name(), rs.event_state(), rs.atr());
}
}
}
}
sourcepub fn atr(&self) -> &[u8] ⓘ
pub fn atr(&self) -> &[u8] ⓘ
The ATR (Answer To Reset) of the card inserted to the reader.
Examples found in repository?
examples/monitor.rs (line 46)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
fn main() {
let ctx = Context::establish(Scope::User).expect("failed to establish context");
let mut readers_buf = [0; 2048];
let mut reader_states = vec![
// Listen for reader insertions/removals, if supported.
ReaderState::new(PNP_NOTIFICATION(), State::UNAWARE),
];
loop {
// Remove dead readers.
fn is_dead(rs: &ReaderState) -> bool {
rs.event_state().intersects(State::UNKNOWN | State::IGNORE)
}
for rs in &reader_states {
if is_dead(rs) {
println!("Removing {:?}", rs.name());
}
}
reader_states.retain(|rs| !is_dead(rs));
// Add new readers.
let names = ctx.list_readers(&mut readers_buf).expect("failed to list readers");
for name in names {
if !reader_states.iter().any(|rs| rs.name() == name) {
println!("Adding {:?}", name);
reader_states.push(ReaderState::new(name, State::UNAWARE));
}
}
// Update the view of the state to wait on.
for rs in &mut reader_states {
rs.sync_current_state();
}
// Wait until the state changes.
ctx.get_status_change(None, &mut reader_states)
.expect("failed to get status change");
// Print current state.
println!();
for rs in &reader_states {
if rs.name() != PNP_NOTIFICATION() {
println!("{:?} {:?} {:?}", rs.name(), rs.event_state(), rs.atr());
}
}
}
}
sourcepub fn current_state(&self) -> State
pub fn current_state(&self) -> State
The last current state that was set.
sourcepub fn event_state(&self) -> State
pub fn event_state(&self) -> State
The last reported state.
Examples found in repository?
examples/monitor.rs (line 15)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
fn main() {
let ctx = Context::establish(Scope::User).expect("failed to establish context");
let mut readers_buf = [0; 2048];
let mut reader_states = vec![
// Listen for reader insertions/removals, if supported.
ReaderState::new(PNP_NOTIFICATION(), State::UNAWARE),
];
loop {
// Remove dead readers.
fn is_dead(rs: &ReaderState) -> bool {
rs.event_state().intersects(State::UNKNOWN | State::IGNORE)
}
for rs in &reader_states {
if is_dead(rs) {
println!("Removing {:?}", rs.name());
}
}
reader_states.retain(|rs| !is_dead(rs));
// Add new readers.
let names = ctx.list_readers(&mut readers_buf).expect("failed to list readers");
for name in names {
if !reader_states.iter().any(|rs| rs.name() == name) {
println!("Adding {:?}", name);
reader_states.push(ReaderState::new(name, State::UNAWARE));
}
}
// Update the view of the state to wait on.
for rs in &mut reader_states {
rs.sync_current_state();
}
// Wait until the state changes.
ctx.get_status_change(None, &mut reader_states)
.expect("failed to get status change");
// Print current state.
println!();
for rs in &reader_states {
if rs.name() != PNP_NOTIFICATION() {
println!("{:?} {:?} {:?}", rs.name(), rs.event_state(), rs.atr());
}
}
}
}
sourcepub fn event_count(&self) -> u32
pub fn event_count(&self) -> u32
The card event count.
The count is incremented for each card insertion or removal in the
reader. This can be used to detect a card removal/insertion
between two calls to Context::get_status_change()
.
sourcepub fn sync_current_state(&mut self)
pub fn sync_current_state(&mut self)
Sync the currently-known state to the last reported state.
Examples found in repository?
examples/monitor.rs (line 35)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
fn main() {
let ctx = Context::establish(Scope::User).expect("failed to establish context");
let mut readers_buf = [0; 2048];
let mut reader_states = vec![
// Listen for reader insertions/removals, if supported.
ReaderState::new(PNP_NOTIFICATION(), State::UNAWARE),
];
loop {
// Remove dead readers.
fn is_dead(rs: &ReaderState) -> bool {
rs.event_state().intersects(State::UNKNOWN | State::IGNORE)
}
for rs in &reader_states {
if is_dead(rs) {
println!("Removing {:?}", rs.name());
}
}
reader_states.retain(|rs| !is_dead(rs));
// Add new readers.
let names = ctx.list_readers(&mut readers_buf).expect("failed to list readers");
for name in names {
if !reader_states.iter().any(|rs| rs.name() == name) {
println!("Adding {:?}", name);
reader_states.push(ReaderState::new(name, State::UNAWARE));
}
}
// Update the view of the state to wait on.
for rs in &mut reader_states {
rs.sync_current_state();
}
// Wait until the state changes.
ctx.get_status_change(None, &mut reader_states)
.expect("failed to get status change");
// Print current state.
println!();
for rs in &reader_states {
if rs.name() != PNP_NOTIFICATION() {
println!("{:?} {:?} {:?}", rs.name(), rs.event_state(), rs.atr());
}
}
}
}
Trait Implementations§
Auto Trait Implementations§
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