pcsclite: return SCardGetStatusChange errors

So it's possible to know when and why pcsc stops watching for events.
This commit is contained in:
Santiago Gimeno
2016-11-24 15:02:57 +01:00
parent 76a1c9a200
commit c311ea038c
2 changed files with 35 additions and 27 deletions

View File

@@ -144,11 +144,8 @@ void PCSCLite::HandleReaderStatusChange(uv_async_t *handle, int status) {
Nan::Callback(Nan::New(async_baton->callback)).Call(argc, argv); Nan::Callback(Nan::New(async_baton->callback)).Call(argc, argv);
} else { } else {
Local<Value> err = Nan::Error(error_msg("SCardListReaders", ar->result).c_str()); Local<Value> argv[1] = { Nan::Error(ar->err_msg.c_str()) };
// Prepare the parameters for the callback function. Nan::Callback(Nan::New(async_baton->callback)).Call(1, argv);
const unsigned argc = 1;
Local<Value> argv[argc] = { err };
Nan::Callback(Nan::New(async_baton->callback)).Call(argc, argv);
} }
// Do exit, after throwing last events // Do exit, after throwing last events
@@ -186,34 +183,44 @@ void PCSCLite::HandlerFunction(void* arg) {
/* Store the result in the baton */ /* Store the result in the baton */
async_baton->async_result->result = result; async_baton->async_result->result = result;
if (result != SCARD_S_SUCCESS) {
async_baton->async_result->err_msg = error_msg("SCardListReaders",
result);
}
/* Notify the nodejs thread */ /* Notify the nodejs thread */
uv_async_send(&async_baton->async); uv_async_send(&async_baton->async);
if (pcsclite->m_pnp) { if (result == SCARD_S_SUCCESS) {
/* Set current status */ if (pcsclite->m_pnp) {
pcsclite->m_card_reader_state.dwCurrentState = /* Set current status */
pcsclite->m_card_reader_state.dwEventState; pcsclite->m_card_reader_state.dwCurrentState =
/* Start checking for status change */ pcsclite->m_card_reader_state.dwEventState;
result = SCardGetStatusChange(pcsclite->m_card_context, /* Start checking for status change */
INFINITE, result = SCardGetStatusChange(pcsclite->m_card_context,
&pcsclite->m_card_reader_state, INFINITE,
1); &pcsclite->m_card_reader_state,
1);
uv_mutex_lock(&pcsclite->m_mutex); uv_mutex_lock(&pcsclite->m_mutex);
if (pcsclite->m_state) { async_baton->async_result->result = result;
uv_cond_signal(&pcsclite->m_cond); if (pcsclite->m_state) {
uv_cond_signal(&pcsclite->m_cond);
}
if (result != SCARD_S_SUCCESS) {
pcsclite->m_state = 2;
async_baton->async_result->err_msg =
error_msg("SCardGetStatusChange", result);
}
uv_mutex_unlock(&pcsclite->m_mutex);
} else {
/* If PnP is not supported, just wait for 1 second */
Sleep(1000);
} }
if (result != SCARD_S_SUCCESS) {
pcsclite->m_state = 2;
}
uv_mutex_unlock(&pcsclite->m_mutex);
} else if (result == SCARD_S_SUCCESS) {
/* If PnP is not supported, just wait for 1 second */
Sleep(1000);
} else { } else {
/* Error on last card access and no PnP, stop monitoring */ /* Error on last card access, stop monitoring */
pcsclite->m_state = 2; pcsclite->m_state = 2;
} }
} }

View File

@@ -16,6 +16,7 @@ class PCSCLite: public Nan::ObjectWrap {
LPSTR readers_name; LPSTR readers_name;
DWORD readers_name_length; DWORD readers_name_length;
bool do_exit; bool do_exit;
std::string err_msg;
}; };
struct AsyncBaton { struct AsyncBaton {