summaryrefslogtreecommitdiff
path: root/libvxi11client/perlbits/perlglue.c
diff options
context:
space:
mode:
authordaniel <danieruru@gmail.com>2013-01-17 21:29:32 +0900
committerdaniel <danieruru@gmail.com>2013-01-17 21:29:32 +0900
commit3bcf349f108248fc3ca705ff1fc8b56923e8bfa4 (patch)
tree55b15edc1a4028dca4ddec488f2bf0d86fcab9a1 /libvxi11client/perlbits/perlglue.c
parent67b0ff47c3866059695617b30deb1d18c250073e (diff)
not sure what happens with strings once they get into perl, but this keeps the last event picked up from the interrupt queue around until polling again when should be good enough.
Diffstat (limited to 'libvxi11client/perlbits/perlglue.c')
-rw-r--r--libvxi11client/perlbits/perlglue.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/libvxi11client/perlbits/perlglue.c b/libvxi11client/perlbits/perlglue.c
index 551136e..3225ca0 100644
--- a/libvxi11client/perlbits/perlglue.c
+++ b/libvxi11client/perlbits/perlglue.c
@@ -6,13 +6,28 @@
static GAsyncQueue* interruptqueue;
typedef struct {
- GTimeVal when;
char* handle;
} Event;
+static Event* lastevent = NULL;
+
+static void freeevent(Event* event) {
+ g_free(event->handle);
+ g_free(event);
+}
+
+static void freelast() {
+ if (lastevent != NULL) {
+ freeevent(lastevent);
+ }
+ lastevent = NULL;
+}
+
static void interruptcallback(char* handle) {
Event* event = g_malloc(sizeof(Event));
- g_get_current_time(&event->when);
+ int handlelen = strlen(handle);
+ event->handle = g_malloc(handlelen + 1);
+ strcpy(event->handle, handle);
g_async_queue_push(interruptqueue, event);
}
@@ -33,19 +48,25 @@ int glue_start_interrupt_server() {
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) {
+ freeevent(event);
+ }
+ freelast();
g_free(interruptqueue);
return ret;
}
-int glue_wait_for_interrupt() {
+char* 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;
+ freelast();
+ lastevent = (Event*) g_async_queue_timed_pop(interruptqueue, &timeout);
+ if (lastevent != NULL) {
+ return lastevent->handle;
}
else
- return 0;
+ return NULL;
}