diff options
Diffstat (limited to 'libvxi11client/perlbits/perlglue.c')
-rw-r--r-- | libvxi11client/perlbits/perlglue.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/libvxi11client/perlbits/perlglue.c b/libvxi11client/perlbits/perlglue.c index 7807895..259a652 100644 --- a/libvxi11client/perlbits/perlglue.c +++ b/libvxi11client/perlbits/perlglue.c @@ -3,6 +3,12 @@ #include <glib.h> #include "libvxi11client.h" +#define DEBUG + +#ifdef DEBUG +#include <stdio.h> +#endif + static GAsyncQueue* interruptqueue; typedef struct { @@ -17,7 +23,7 @@ static void freeevent(Event* event) { } static void freelast() { - if (lastevent != NULL) { + if (lastevent != NULL ) { freeevent(lastevent); lastevent = NULL; } @@ -33,8 +39,8 @@ static void interruptcallback(char* handle) { VXI11Context* glue_open(char* address, char* device) { VXI11Context* context = malloc(sizeof(VXI11Context)); - if (context == NULL) - return NULL; + if (context == NULL ) + return NULL ; int err = vxi11_open(context, address, device); @@ -51,7 +57,7 @@ int glue_stop_interrupt_server() { int ret = vxi11_stop_interrupt_server(); Event* event = NULL; // clear everything that is left over - while ((event = (Event*) g_async_queue_try_pop(interruptqueue)) != NULL) { + while ((event = (Event*) g_async_queue_try_pop(interruptqueue)) != NULL ) { freeevent(event); } freelast(); @@ -60,17 +66,30 @@ int glue_stop_interrupt_server() { return ret; } -char* glue_wait_for_interrupt() { - if (interruptqueue) - return NULL; - GTimeVal timeout; - g_get_current_time(&timeout); - g_time_val_add(&timeout, 2500); - freelast(); - lastevent = (Event*) g_async_queue_timed_pop(interruptqueue, &timeout); - if (lastevent != NULL) { +char* glue_wait_for_interrupt(unsigned int timeout) { + if (interruptqueue == NULL ) { +#ifdef DEBUG + printf("interrupt queue is null!\n"); +#endif + return NULL ; + } + + // if we have a timeout pop with a time out + // otherwise block until an interrupt happens + if (timeout > 0) { + GTimeVal whentotimeout; + g_get_current_time(&whentotimeout); + g_time_val_add(&whentotimeout, timeout * 1000); + freelast(); + lastevent = (Event*) g_async_queue_timed_pop(interruptqueue, &whentotimeout); + } + else { + lastevent = (Event*) g_async_queue_pop(interruptqueue); + } + + if (lastevent != NULL ) { return lastevent->handle; } else - return NULL; + return NULL ; } |