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 e870477..62d9748 100644 --- a/libvxi11client/perlbits/perlglue.c +++ b/libvxi11client/perlbits/perlglue.c @@ -1,23 +1,42 @@ -#include "EXTERN.h" -#include "perl.h" -#include "XSUB.h" - -#include "ppport.h" - -#include "perlglue.h" +#include <stdbool.h> +#include <glib.h> +#include "libvxi11client.h" #define INTERRUPTHANDLE "libvxi11client" -extern int vxi11_enable_srq(bool enable, char* handle, void (*callback)(void)); +GAsyncQueue* interruptqueue; -static SV* perlcallback = NULL; +typedef struct { + GTimeVal when; +} Event; static void interruptcallback(void) { - //PUSHMARK(SP); - call_sv(perlcallback, G_DISCARD | G_NOARGS); + Event* event = g_malloc(sizeof(Event)); + g_get_current_time(&event->when); + g_async_queue_push(interruptqueue, event); +} + +int glue_enable_srq(bool enable) { + if (enable) { + interruptqueue = g_async_queue_new(); + return vxi11_enable_srq(enable, INTERRUPTHANDLE, interruptcallback); + } + else { + int ret = vxi11_enable_srq(enable, NULL, NULL); + g_free(interruptqueue); + return ret; + } } -int glue_enable_srq(bool enable, SV* callback) { - perlcallback = callback; - return vxi11_enable_srq(enable, INTERRUPTHANDLE, interruptcallback); +int glue_wait_for_interrupt() { + GTimeVal timeout; + g_get_current_time(&timeout); + g_time_val_add(&timeout, 2500); + gpointer event = g_async_queue_timed_pop(interruptqueue, &timeout); + if (event != NULL) { + g_free(event); + return 1; + } + else + return 0; } |