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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 bool establishContext();
  19. static bool freeContext();
  20. bool connect(DWORD shareMode = SCARD_SHARE_SHARED, DWORD protocols =
  21. SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, DWORD disposition = SCARD_LEAVE_CARD);
  22. bool disconnect(DWORD disposition = SCARD_LEAVE_CARD);
  23. std::shared_ptr<ScResult> transmit(const ScCommand& command, DWORD size = 2048);
  24. inline const std::string getName() const;
  25. private:
  26. std::string _name;
  27. static thread_local LPSCARDCONTEXT _context;
  28. LPSCARDHANDLE _card;
  29. LPDWORD _proto;
  30. LPSCARD_IO_REQUEST _sendPci;
  31. LONG _lastResult;
  32. };
  33. # include "ScReader.hxx"
  34. #endif //LIBPCSC_CPPTOOLS_SCREADER_H