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.

NfcDevice.cpp 925B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // Created by robin on 6/19/16.
  3. //
  4. #include "NfcDevice.h"
  5. NfcDevice::NfcDevice(LibNfc* libNfc, std::string str)
  6. : _connStr(str)
  7. , _device(0)
  8. , _libNfc(libNfc)
  9. {
  10. }
  11. NfcDevice::~NfcDevice()
  12. {
  13. close();
  14. }
  15. ResultBool NfcDevice::open()
  16. {
  17. if (isOpened()) {
  18. return ResultBool::error("NFC device is already opened");
  19. }
  20. _device = nfc_open(_libNfc->getContext(), _connStr.c_str());
  21. if (!_device) {
  22. return ResultBool::error("Failed to open NFC device");
  23. }
  24. return ResultBool::ok(true);
  25. }
  26. bool NfcDevice::isOpened()
  27. {
  28. return _device != 0;
  29. }
  30. void NfcDevice::close()
  31. {
  32. if (isOpened()) {
  33. nfc_close(_device);
  34. _device = 0;
  35. }
  36. }
  37. nfc_device *NfcDevice::getDevice() const
  38. {
  39. return _device;
  40. }
  41. void NfcDevice::setConnStr(const std::string &connStr)
  42. {
  43. _connStr = connStr;
  44. }
  45. const std::string &NfcDevice::getConnStr() const
  46. {
  47. return _connStr;
  48. }