Changeset View
Changeset View
Standalone View
Standalone View
b/scd/pcsc-wrapper.c
Context not available. | |||||
#include <stdarg.h> | #include <stdarg.h> | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <dlfcn.h> | #include <dlfcn.h> | ||||
#include <pthread.h> | |||||
#define PGM "pcsc-wrapper" | #define PGM "pcsc-wrapper" | ||||
Context not available. | |||||
} | } | ||||
struct myArgs { | |||||
long pcsc_context; | |||||
struct pcsc_readerstate_s *rdrstates; | |||||
pthread_cond_t cond; | |||||
long err; | |||||
}; | |||||
// Helper Thread to have a timeout for pcsc_get_status_change. | |||||
void *get_status_change_thread (void *pointer) { | |||||
struct myArgs *args = pointer; | |||||
args->err = pcsc_get_status_change (args->pcsc_context, | |||||
0, | |||||
args->rdrstates, 1); | |||||
pthread_cond_signal(&args->cond); | |||||
return NULL; | |||||
} | |||||
/* Handle a status request. We expect no arguments. We may modifiy | /* Handle a status request. We expect no arguments. We may modifiy | ||||
ARGBUF. */ | ARGBUF. */ | ||||
Context not available. | |||||
memset (rdrstates, 0, sizeof *rdrstates); | memset (rdrstates, 0, sizeof *rdrstates); | ||||
rdrstates[0].reader = current_rdrname; | rdrstates[0].reader = current_rdrname; | ||||
rdrstates[0].current_state = PCSC_STATE_UNAWARE; | rdrstates[0].current_state = PCSC_STATE_UNAWARE; | ||||
err = pcsc_get_status_change (pcsc_context, | |||||
0, | pthread_t thread; | ||||
rdrstates, 1); | struct myArgs args; | ||||
args.rdrstates = rdrstates; | |||||
args.pcsc_context = pcsc_context; | |||||
pthread_cond_init(&args.cond, NULL); | |||||
pthread_create(&thread, NULL, get_status_change_thread, &args); | |||||
static struct timespec time_to_wait = {0, 0}; | |||||
time_to_wait.tv_sec = time(NULL) + 5; | |||||
pthread_mutex_t lock; | |||||
pthread_mutex_init(&lock, NULL); | |||||
pthread_mutex_lock(&lock); | |||||
err = pthread_cond_timedwait(&args.cond, &lock, &time_to_wait); | |||||
pthread_mutex_unlock(&lock); | |||||
if (err) { | |||||
pthread_cancel(thread); | |||||
err = 0x8010000a; | |||||
} else { | |||||
pthread_join (thread, NULL); | |||||
err = args.err; | |||||
} | |||||
if (err == 0x8010000a) /* Timeout. */ | if (err == 0x8010000a) /* Timeout. */ | ||||
err = 0; | err = 0; | ||||
if (err) | if (err) | ||||
Context not available. |