mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-08 08:34:00 +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;
|
||||
|
||||
NFCDevice::NFCDevice():
|
||||
NFCDevice::NFCDevice() throw(NFCError):
|
||||
pollNr(20),
|
||||
pollPeriod(2),
|
||||
_nfcContext(NULL),
|
||||
|
@ -29,7 +29,7 @@ NFCDevice::~NFCDevice()
|
|||
nfc_exit(_nfcContext);
|
||||
}
|
||||
|
||||
void NFCDevice::open()
|
||||
void NFCDevice::open() throw(NFCError)
|
||||
{
|
||||
if (opened()) {
|
||||
return;
|
||||
|
@ -60,7 +60,7 @@ void NFCDevice::close()
|
|||
_opened = false;
|
||||
}
|
||||
|
||||
std::string NFCDevice::scanUID()
|
||||
std::string NFCDevice::scanUID() throw(NFCError)
|
||||
{
|
||||
int res;
|
||||
nfc_target nt;
|
||||
|
|
|
@ -7,18 +7,34 @@
|
|||
#include <nfc/nfc.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
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
NFCDevice();
|
||||
NFCDevice() throw(NFCError);
|
||||
|
||||
virtual ~NFCDevice();
|
||||
|
||||
std::string scanUID();
|
||||
std::string scanUID() throw(NFCError);
|
||||
|
||||
void open();
|
||||
void open() throw(NFCError);
|
||||
|
||||
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
|
||||
from brmdoor_nfc import NFCDevice
|
||||
from brmdoor_nfc import NFCDevice, NFCError
|
||||
from binascii import hexlify
|
||||
|
||||
try:
|
||||
nfc = NFCDevice()
|
||||
nfc.close()
|
||||
nfc.open()
|
||||
|
@ -10,3 +11,5 @@ print "Device is opened:", nfc.opened()
|
|||
print "Closing device"
|
||||
nfc.close()
|
||||
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