new method reset for pcsc connections; refs #29

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

@ -552,6 +552,27 @@ namespace pcsc {
// } // }
/// 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. //! Find all readers with a given ATR.
/*! @param atr full or partial ATR to match to the reader's ATR /*! @param atr full or partial ATR to match to the reader's ATR
@returns list of readers that contain @c atr in their ATR */ @returns list of readers that contain @c atr in their ATR */
@ -630,7 +651,7 @@ namespace pcsc {
public: public:
//! opens connection that is closed on destruction //! opens connection that is closed on destruction
ConnectionLifetime(Scope s, bool exc): ConnectionLifetime(Scope s, bool exc):
_exc(exc), _id(0), _exc(exc), _id(0), _s(s),
_state(SCardEstablishContext(s, 0, 0, &_id)) { _state(SCardEstablishContext(s, 0, 0, &_id)) {
CRYPTOLOG("Open Connection"); CRYPTOLOG("Open Connection");
check("establish smartcard context"); check("establish smartcard context");
@ -1064,10 +1085,20 @@ namespace pcsc {
return _readers.find(name)->second; 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: private:
bool _exc; bool _exc;
SCARDCONTEXT _id; SCARDCONTEXT _id;
Scope _s;
long _state; long _state;
//! Readers are closed when the last shared object is destructed //! Readers are closed when the last shared object is destructed

Loading…
Cancel
Save