diff options
author | daniel <daniel@roi> | 2013-01-30 12:15:53 +0900 |
---|---|---|
committer | daniel <daniel@roi> | 2013-01-30 12:15:53 +0900 |
commit | c4957e4c650008698226c9b4b236222280f16396 (patch) | |
tree | 4e3f7498554f0e3d0ef916d684072a808ef02092 /libvxi11client/perlbits | |
parent | 0cda537acf1ac6652ca8d2f3d0bfa1bd2725b2bd (diff) |
Make interrupt timeout configurable
Diffstat (limited to 'libvxi11client/perlbits')
-rw-r--r-- | libvxi11client/perlbits/Client.xs | 7 | ||||
-rw-r--r-- | libvxi11client/perlbits/perlglue.c | 47 |
2 files changed, 37 insertions, 17 deletions
diff --git a/libvxi11client/perlbits/Client.xs b/libvxi11client/perlbits/Client.xs index d84482e..1ad34e9 100644 --- a/libvxi11client/perlbits/Client.xs +++ b/libvxi11client/perlbits/Client.xs @@ -93,9 +93,10 @@ vxi_enable_srq_long(context, enable, handle) RETVAL char* -vxi_wait_for_interrupt() - CODE: - RETVAL = glue_wait_for_interrupt(); +vxi_wait_for_interrupt(timeout = 0) + unsigned int timeout + CODE: + RETVAL = glue_wait_for_interrupt(timeout); OUTPUT: RETVAL 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 ; } |