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.

LibNfcOperation.hxx 1006B

123456789101112131415161718192021222324252627282930
  1. //
  2. // Created by robin on 10/1/17.
  3. //
  4. #ifndef MIFARE_TOOLS_LIBNFCOPERATION_HXX
  5. #define MIFARE_TOOLS_LIBNFCOPERATION_HXX
  6. #include "LibNfcOperation.h"
  7. template<typename T>
  8. void LibNfcOperation::runOperation(QSharedPointer<LibNfc::Core::LibNfcContext> libNfc,
  9. std::function<LibNfc::Utils::Result<T>(QSharedPointer<LibNfc::Core::LibNfcContext>)> operation,
  10. std::function<void(LibNfc::Utils::Result<T>)> callback)
  11. {
  12. LibNfc::Utils::Result<T>* result = nullptr;
  13. auto nfcOperation = new LibNfcOperation(libNfc, [&result, operation](QSharedPointer<LibNfc::Core::LibNfcContext> libNfc)
  14. {
  15. auto res = operation(libNfc);
  16. result = new LibNfc::Utils::Result<T>(res);
  17. });
  18. connect(nfcOperation, &LibNfcOperation::finished, [&result, nfcOperation, callback]()
  19. {
  20. nfcOperation->deleteLater();
  21. callback(*result);
  22. delete result;
  23. });
  24. nfcOperation->start();
  25. }
  26. #endif //MIFARE_TOOLS_LIBNFCOPERATION_HXX