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.

LibNfcBusiness.cpp 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // Created by robin on 7/22/16.
  3. //
  4. #include <algorithm>
  5. #include "LibNfcBusiness.h"
  6. #define Q(x) #x
  7. #define QUOTE(x) Q(x)
  8. #ifndef GIT_SHA1
  9. #define GIT_SHA1 "unknown"
  10. #endif
  11. #ifndef GIT_REF_NAME
  12. #define GIT_REF_NAME "unknown"
  13. #endif
  14. LibNfcBusiness::LibNfcBusiness()
  15. {
  16. _libNfc = std::make_shared<LibNfc>();
  17. }
  18. LibNfcBusiness::~LibNfcBusiness()
  19. {
  20. _libNfc->clean();
  21. }
  22. ResultBool LibNfcBusiness::init()
  23. {
  24. if (isInitialized()) {
  25. return ResultBool::error("LibNfc is already initialized");
  26. }
  27. return _libNfc->init();
  28. }
  29. std::string LibNfcBusiness::getLibNfcVersion()
  30. {
  31. return LibNfc::getVersion();
  32. }
  33. void LibNfcBusiness::clean()
  34. {
  35. if (isInitialized()) {
  36. _libNfc->clean();
  37. }
  38. }
  39. bool LibNfcBusiness::isInitialized() const
  40. {
  41. return _libNfc->getContext() != 0;
  42. }
  43. Result<std::vector<std::shared_ptr<NfcDeviceBusiness>>> LibNfcBusiness::getDevices() const
  44. {
  45. if (!isInitialized()) {
  46. return Result<std::vector<std::shared_ptr<NfcDeviceBusiness>>>::error("LibNfc is not initialized");
  47. }
  48. auto devicesResult = _libNfc->getDevices();
  49. if (!devicesResult) {
  50. return Result<std::vector<std::shared_ptr<NfcDeviceBusiness>>>::error(devicesResult);
  51. }
  52. auto devices = devicesResult.getData();
  53. std::vector<std::shared_ptr<NfcDeviceBusiness>> devicesBusiness;
  54. for (auto device : devices) {
  55. devicesBusiness.push_back(std::make_shared<NfcDeviceBusiness>(device));
  56. }
  57. return Result<std::vector<std::shared_ptr<NfcDeviceBusiness>>>::ok(devicesBusiness);
  58. }
  59. std::shared_ptr<LibNfc> LibNfcBusiness::getLibNfc() const
  60. {
  61. return _libNfc;
  62. }
  63. std::string LibNfcBusiness::getMifareToolsVersion()
  64. {
  65. return QUOTE(GIT_REF_NAME) "-" QUOTE(GIT_SHA1);
  66. }