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.4KB

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