summaryrefslogtreecommitdiff
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
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.
-rw-r--r--libvxi11client/perlbits/Client.xs2
-rw-r--r--libvxi11client/perlbits/VXI11-Client.t2
-rw-r--r--libvxi11client/perlbits/perlglue.c37
-rw-r--r--libvxi11client/perlbits/perlglue.h2
4 files changed, 32 insertions, 11 deletions
diff --git a/libvxi11client/perlbits/Client.xs b/libvxi11client/perlbits/Client.xs
index 2da6581..fc6194a 100644
--- a/libvxi11client/perlbits/Client.xs
+++ b/libvxi11client/perlbits/Client.xs
@@ -87,7 +87,7 @@ enable_srq(context, enable, handle)
OUTPUT:
RETVAL
-int
+char*
wait_for_interrupt()
CODE:
RETVAL = glue_wait_for_interrupt();
diff --git a/libvxi11client/perlbits/VXI11-Client.t b/libvxi11client/perlbits/VXI11-Client.t
index ef2aae0..691a6bb 100644
--- a/libvxi11client/perlbits/VXI11-Client.t
+++ b/libvxi11client/perlbits/VXI11-Client.t
@@ -25,7 +25,7 @@ is($instr->write("*IDN?", 6, 0, 0), 6, "Write");
ok($instr->readstatusbyte(0) >= 0 , "Read status byte");
is($instr->create_intr_chan(), 1, "Create intr channel");
is($instr->enable_srq(1, "myhandle"), 1, "Enable interrupts");
-is(&VXI11::Client::wait_for_interrupt, 1, "Wait for interrupt");
+is(&VXI11::Client::wait_for_interrupt, "myhandle", "Wait for interrupt");
is($instr->enable_srq(0, ""), 1, "Disable interrupts");
is($instr->destroy_intr_chan(), 1, "Destroy intr channel");
is($instr->abort(), 1, "Abort");
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;
}
diff --git a/libvxi11client/perlbits/perlglue.h b/libvxi11client/perlbits/perlglue.h
index 8c33c7d..1b29567 100644
--- a/libvxi11client/perlbits/perlglue.h
+++ b/libvxi11client/perlbits/perlglue.h
@@ -2,7 +2,7 @@
#include <perl.h>
#include "libvxi11client.h"
-int glue_wait_for_interrupt();
+char* glue_wait_for_interrupt();
VXI11Context* glue_open(char* address, char* device);
int glue_start_interrupt_server();
int glue_stop_interrupt_server();