12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- //
- // Created by robin on 6/19/16.
- //
-
- #include <boost/shared_ptr.hpp>
- #include "LibNfcInternal.h"
-
- namespace LibNfc
- {
- namespace Core
- {
-
- LibNfcInternal::LibNfcInternal()
- : _context(0)
- {
- }
-
- LibNfcInternal::~LibNfcInternal()
- {
- clean();
- }
-
- LibNfc::Utils::ResultBool LibNfcInternal::init()
- {
- nfc_init(&_context);
- if (!_context) {
- return LibNfc::Utils::ResultBool::error("LibNfc could not be initialized");
- }
- return LibNfc::Utils::ResultBool::ok(true);
- }
-
- std::string LibNfcInternal::getVersion()
- {
- return nfc_version();
- }
-
- void LibNfcInternal::clean()
- {
- nfc_exit(_context);
- _context = 0;
- }
-
- LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDeviceInternal>>> LibNfcInternal::getDevices() const
- {
- nfc_connstring devices[16];
- ::memset((char*)devices, 0, sizeof(devices));
- size_t count = nfc_list_devices(_context, devices, 16);
- if (count < 0) {
- return LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDeviceInternal>>>::error("Failed to list NFC devices: " + count);
- }
- std::vector<std::shared_ptr<NfcDeviceInternal>> devicesList;
- for (size_t i = 0; i < count; ++i) {
- devicesList.push_back(std::make_shared<NfcDeviceInternal>(this, devices[i]));
- }
- return LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDeviceInternal>>>::ok(devicesList);
- }
-
- nfc_context *LibNfcInternal::getContext() const
- {
- return _context;
- }
-
- }; // Core
- }; // LibNfc
|