Skip to main content

PcscMonitor

Struct PcscMonitor 

Source
pub struct PcscMonitor { /* private fields */ }
Expand description

Represents a PC/SC monitor that tracks reader and card state changes.

PcscMonitor is a singleton interface for monitoring smart card readers using PC/SC. It supports hotplug detection, card insertion/removal events, and thread-safe callback registration.

The monitor runs in a background thread once started.

Implementations§

Source§

impl PcscMonitor

Source

pub fn instance() -> MutexGuard<'static, PcscMonitor>

Gets a global instance of the PcscMonitor to register callbacks.

This method returns a locked [MutexGuard] to the global monitor instance. Use this to attach listeners and start monitoring.

§Example
let mut monitor = pcsc_mon::PcscMonitor::instance();
monitor.on_reader_added(|reader| {
    println!("Reader added: {}", reader);
});
monitor.start();
Source

pub fn on_reader_added<F>(&mut self, f: F)
where F: Fn(String) + Send + Sync + 'static,

Registers a callback for reader addition events.

The callback is called with the name of the reader when a new reader is connected.

Source

pub fn on_reader_removed<F>(&mut self, f: F)
where F: Fn(String) + Send + Sync + 'static,

Registers a callback for reader removal events.

The callback is called with the name of the reader when a reader is disconnected.

Note: Internally sets the reader state to State::IGNORE. When the same reader is reconnected, a card must be inserted and removed again to re-trigger on_card_inserted.

Source

pub fn on_card_inserted<F>(&mut self, f: F)
where F: Fn(&Context, &Card) + Send + Sync + 'static,

Registers a callback for card insertion events.

The callback receives a reference to the Context and Card for direct interaction with the smart card.

§Note

The context and card are already connected when the callback runs.

Source

pub fn on_card_removed<F>(&mut self, f: F)
where F: Fn(String) + Send + Sync + 'static,

Registers a callback for card removal events.

The callback is called with the name of the reader when the card is removed.

Source

pub fn on_error<F>(&mut self, f: F)
where F: Fn(Error) + Send + Sync + 'static,

Registers a callback to handle Errors during the pcsc events

The callback is called with the error thrown during reader or card state detection

Source

pub fn start(&mut self)

Starts the monitoring thread.

Begins polling for reader and card state changes. Should be called after all desired callbacks are registered.

This is non-blocking: the monitoring thread runs in the background.

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.