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.

ScReader.h 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 <bits/stl_bvector.h>
  10. # include "ScCommand.h"
  11. # include "ScResult.h"
  12. class ScReader
  13. {
  14. public:
  15. inline ScReader(std::string name);
  16. virtual ~ScReader();
  17. static std::vector<std::shared_ptr<ScReader>> getReaders();
  18. static LONG getLastResult();
  19. static bool establishContext();
  20. static bool freeContext();
  21. bool connect(DWORD shareMode = SCARD_SHARE_SHARED, DWORD protocols =
  22. SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, DWORD disposition = SCARD_LEAVE_CARD);
  23. bool disconnect(DWORD disposition = SCARD_LEAVE_CARD);
  24. std::shared_ptr<ScResult> transmit(const ScCommand& command, DWORD size = 2048);
  25. inline const std::string getName() const;
  26. private:
  27. std::string _name;
  28. static thread_local LPSCARDCONTEXT _context;
  29. LPSCARDHANDLE _card;
  30. LPDWORD _proto;
  31. SCARD_IO_REQUEST _sendPci;
  32. static thread_local LONG _lastResult;
  33. };
  34. # include "ScReader.hxx"
  35. #endif //LIBPCSC_CPPTOOLS_SCREADER_H