1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- //
- // Created by robin on 7/22/16.
- //
-
- #include <algorithm>
- #include "libnfc_cpptools/LibNfc.h"
- #include "LibNfcInternal.h"
-
- #define Q(x) #x
- #define QUOTE(x) Q(x)
-
- #ifndef GIT_SHA1
- #define GIT_SHA1 "unknown"
- #endif
-
- #ifndef GIT_REF_NAME
- #define GIT_REF_NAME "unknown"
- #endif
-
- namespace LibNfc
- {
- namespace Core
- {
-
- LibNfcContext::LibNfcContext()
- {
- _libNfc = std::make_shared<LibNfcInternal>();
- }
-
- LibNfcContext::~LibNfcContext()
- {
- _libNfc->clean();
- }
-
- LibNfc::Utils::ResultBool LibNfcContext::init()
- {
- if (isInitialized()) {
- return LibNfc::Utils::ResultBool::error("LibNfc is already initialized");
- }
- return _libNfc->init();
- }
-
- std::string LibNfcContext::getLibNfcVersion()
- {
- return LibNfcInternal::getVersion();
- }
-
- void LibNfcContext::clean()
- {
- if (isInitialized()) {
- _libNfc->clean();
- }
- }
-
- bool LibNfcContext::isInitialized() const
- {
- return _libNfc->getContext() != 0;
- }
-
- LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDevice>>> LibNfcContext::getDevices() const
- {
- if (!isInitialized()) {
- return LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDevice>>>::error("LibNfc is not initialized");
- }
- auto devicesResult = _libNfc->getDevices();
- if (!devicesResult) {
- return LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDevice>>>::error(devicesResult);
- }
- auto devices = devicesResult.getData();
- std::vector<std::shared_ptr<NfcDevice>> devicesBusiness;
- for (auto device : devices) {
- devicesBusiness.push_back(std::make_shared<NfcDevice>(device));
- }
- return LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDevice>>>::ok(devicesBusiness);
- }
-
- std::string LibNfcContext::getMifareToolsVersion()
- {
- return QUOTE(GIT_REF_NAME) "-" QUOTE(GIT_SHA1);
- }
-
- }; // Core
- }; // LibNfc
|