You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // Created by robin on 6/28/15.
  3. //
  4. #ifndef LIBPCSC_CPPTOOLS_SCREADER_H
  5. # define LIBPCSC_CPPTOOLS_SCREADER_H
  6. # include <wintypes.h>
  7. # include <pcsclite.h>
  8. # include <memory>
  9. # include "ScCommand.h"
  10. # include "ScResult.h"
  11. class ScReader
  12. {
  13. public:
  14. inline ScReader(std::string name);
  15. virtual ~ScReader();
  16. static std::vector<std::shared_ptr<ScReader>> getReaders();
  17. static LONG getLastStaticResult();
  18. static inline std::string getLastStaticResultString();
  19. static inline std::string getResultString(const LONG& result);
  20. inline LONG getLastResult();
  21. inline std::string getLastResultString();
  22. static bool establishContext();
  23. static bool freeContext();
  24. bool connect(DWORD shareMode = SCARD_SHARE_SHARED, DWORD protocols =
  25. SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, DWORD disposition = SCARD_LEAVE_CARD);
  26. bool disconnect(DWORD disposition = SCARD_LEAVE_CARD);
  27. std::shared_ptr<ScResult> transmit(const ScCommand& command, DWORD size = 2048);
  28. inline const std::string getName() const;
  29. std::string getAttribute(DWORD attr);
  30. inline std::string getAtr();
  31. private:
  32. std::string _name;
  33. static /*thread_local*/ LPSCARDCONTEXT _context;
  34. static /*thread_local*/ LONG _lastStaticResult;
  35. LPSCARDHANDLE _card;
  36. LPDWORD _proto;
  37. SCARD_IO_REQUEST _sendPci;
  38. LONG _lastResult;
  39. };
  40. # include "ScReader.hxx"
  41. #endif //LIBPCSC_CPPTOOLS_SCREADER_H