mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-08 16:36:25 +02:00
C++ exceptions now propagate through python
This commit is contained in:
parent
a8149abeec
commit
821f394602
3 changed files with 34 additions and 31 deletions
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
NFCDevice::NFCDevice():
|
NFCDevice::NFCDevice() throw(NFCError):
|
||||||
pollNr(20),
|
pollNr(20),
|
||||||
pollPeriod(2),
|
pollPeriod(2),
|
||||||
_nfcContext(NULL),
|
_nfcContext(NULL),
|
||||||
|
@ -29,7 +29,7 @@ NFCDevice::~NFCDevice()
|
||||||
nfc_exit(_nfcContext);
|
nfc_exit(_nfcContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NFCDevice::open()
|
void NFCDevice::open() throw(NFCError)
|
||||||
{
|
{
|
||||||
if (opened()) {
|
if (opened()) {
|
||||||
return;
|
return;
|
||||||
|
@ -60,7 +60,7 @@ void NFCDevice::close()
|
||||||
_opened = false;
|
_opened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string NFCDevice::scanUID()
|
std::string NFCDevice::scanUID() throw(NFCError)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
nfc_target nt;
|
nfc_target nt;
|
||||||
|
|
|
@ -7,18 +7,34 @@
|
||||||
#include <nfc/nfc.h>
|
#include <nfc/nfc.h>
|
||||||
#include <nfc/nfc-types.h>
|
#include <nfc/nfc-types.h>
|
||||||
|
|
||||||
|
class NFCError: public std::exception
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
NFCError(const std::string& msg);
|
||||||
|
|
||||||
|
const char *what() const throw() {return _msg.c_str();}
|
||||||
|
|
||||||
|
~NFCError() throw() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
std::string _msg;
|
||||||
|
};
|
||||||
|
|
||||||
class NFCDevice
|
class NFCDevice
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
NFCDevice();
|
NFCDevice() throw(NFCError);
|
||||||
|
|
||||||
virtual ~NFCDevice();
|
virtual ~NFCDevice();
|
||||||
|
|
||||||
std::string scanUID();
|
std::string scanUID() throw(NFCError);
|
||||||
|
|
||||||
void open();
|
void open() throw(NFCError);
|
||||||
|
|
||||||
bool opened() const {return _opened;}
|
bool opened() const {return _opened;}
|
||||||
|
|
||||||
|
@ -43,19 +59,3 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class NFCError: public std::exception
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
NFCError(const std::string& msg);
|
|
||||||
|
|
||||||
const char *what() const throw() {return _msg.c_str();}
|
|
||||||
|
|
||||||
~NFCError() throw() {}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
std::string _msg;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
5
runme.py
5
runme.py
|
@ -1,7 +1,8 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from brmdoor_nfc import NFCDevice
|
from brmdoor_nfc import NFCDevice, NFCError
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
|
||||||
|
try:
|
||||||
nfc = NFCDevice()
|
nfc = NFCDevice()
|
||||||
nfc.close()
|
nfc.close()
|
||||||
nfc.open()
|
nfc.open()
|
||||||
|
@ -10,3 +11,5 @@ print "Device is opened:", nfc.opened()
|
||||||
print "Closing device"
|
print "Closing device"
|
||||||
nfc.close()
|
nfc.close()
|
||||||
print "Device is opened:", nfc.opened()
|
print "Device is opened:", nfc.opened()
|
||||||
|
except NFCError, e:
|
||||||
|
print "Reading UID failed:", e.what()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue