Explicit unload() 'destructor'

This commit is contained in:
Ondrej Mikle 2014-07-19 20:09:05 +02:00
parent 3717cb2563
commit bbec77f248
3 changed files with 31 additions and 4 deletions

View file

@ -1,4 +1,5 @@
#include <string>
#include <cassert>
#include <nfc/nfc.h>
#include <nfc/nfc-types.h>
@ -13,7 +14,8 @@ NFCDevice::NFCDevice() throw(NFCError):
pollPeriod(2),
_nfcContext(NULL),
_nfcDevice(NULL),
_opened(false)
_opened(false),
_unloaded(false)
{
nfc_init(&_nfcContext);
if (_nfcContext == NULL) {
@ -26,7 +28,7 @@ NFCDevice::NFCDevice() throw(NFCError):
NFCDevice::~NFCDevice()
{
close();
nfc_exit(_nfcContext);
unload();
}
void NFCDevice::open() throw(NFCError)
@ -55,11 +57,26 @@ void NFCDevice::close()
return;
}
assert(_nfcDevice);
nfc_close(_nfcDevice);
_nfcDevice = NULL;
_opened = false;
}
void NFCDevice::unload()
{
if (_unloaded) {
return;
}
assert(_nfcContext);
nfc_exit(_nfcContext);
_nfcContext = NULL;
_unloaded = true;
}
std::string NFCDevice::scanUID() throw(NFCError)
{
int res;