Merge branch 'master' of git://github.com/santigimeno/node-pcsclite into master

# Conflicts:
#	package.json
This commit is contained in:
Martin Endler
2017-01-26 19:16:06 +01:00
3 changed files with 36 additions and 28 deletions

View File

@@ -319,9 +319,9 @@ NAN_METHOD(CardReader::Close) {
} while ((ret != 0) && (++ times < 5)); } while ((ret != 0) && (++ times < 5));
} }
uv_mutex_unlock(&obj->m_mutex);
assert(uv_thread_join(&obj->m_status_thread) == 0); assert(uv_thread_join(&obj->m_status_thread) == 0);
obj->m_status_thread = 0; obj->m_status_thread = 0;
uv_mutex_unlock(&obj->m_mutex);
} }
info.GetReturnValue().Set(Nan::New<Number>(result)); info.GetReturnValue().Set(Nan::New<Number>(result));

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,9 +183,15 @@ 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 (result == SCARD_S_SUCCESS) {
if (pcsclite->m_pnp) { if (pcsclite->m_pnp) {
/* Set current status */ /* Set current status */
pcsclite->m_card_reader_state.dwCurrentState = pcsclite->m_card_reader_state.dwCurrentState =
@@ -200,20 +203,24 @@ void PCSCLite::HandlerFunction(void* arg) {
1); 1);
uv_mutex_lock(&pcsclite->m_mutex); uv_mutex_lock(&pcsclite->m_mutex);
async_baton->async_result->result = result;
if (pcsclite->m_state) { if (pcsclite->m_state) {
uv_cond_signal(&pcsclite->m_cond); uv_cond_signal(&pcsclite->m_cond);
} }
if (result != SCARD_S_SUCCESS) { if (result != SCARD_S_SUCCESS) {
pcsclite->m_state = 2; pcsclite->m_state = 2;
async_baton->async_result->err_msg =
error_msg("SCardGetStatusChange", result);
} }
uv_mutex_unlock(&pcsclite->m_mutex); uv_mutex_unlock(&pcsclite->m_mutex);
} else if (result == SCARD_S_SUCCESS) { } else {
/* If PnP is not supported, just wait for 1 second */ /* If PnP is not supported, just wait for 1 second */
Sleep(1000); 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 {