new method reset for pcsc connections; refs #29

master
Marc Wäckerlin 10 years ago
parent 7d6d0fdae2
commit 2ea4dd4c0e
  1. 33
      src/pcsc.hxx

@ -551,6 +551,27 @@ namespace pcsc {
// void close(const std::string& s) {
// }
/// Reset and reestablish the connection.
/** @note You must remove all readers that have been returned by
@ref reader(), if you have assigned them to a variable
and stored them. Otherwise the connections will remain
open and next access should probably fail.
@begincode
{
mrw::Shared<Reader> r(c.reader(name));
// use r
c.reset(); // now r is invalid
// either reassign r:
r = c.reader(name);
// or simply reset it
r.reset();
}
// or clenaup by leaving the context of r
@endcode */
void reset() {
_connectionlifetime->reset();
}
//! Find all readers with a given ATR.
/*! @param atr full or partial ATR to match to the reader's ATR
@ -630,7 +651,7 @@ namespace pcsc {
public:
//! opens connection that is closed on destruction
ConnectionLifetime(Scope s, bool exc):
_exc(exc), _id(0),
_exc(exc), _id(0), _s(s),
_state(SCardEstablishContext(s, 0, 0, &_id)) {
CRYPTOLOG("Open Connection");
check("establish smartcard context");
@ -1064,10 +1085,20 @@ namespace pcsc {
return _readers.find(name)->second;
}
/// Cleans up the readers, resets the context.
void reset() {
_readers.clear();
_state = SCardReleaseContext(_id);
check("smartcard release context");
_state = SCardEstablishContext(_s, 0, 0, &_id);
check("establish smartcard context");
}
private:
bool _exc;
SCARDCONTEXT _id;
Scope _s;
long _state;
//! Readers are closed when the last shared object is destructed

Loading…
Cancel
Save