summaryrefslogtreecommitdiff
path: root/libvxi11client
diff options
context:
space:
mode:
authordaniel <danieruru@gmail.com>2013-01-12 14:50:56 +0900
committerdaniel <danieruru@gmail.com>2013-01-12 14:50:56 +0900
commit7c6b1548f8e3c24565d45837bbde961ece718f41 (patch)
treeb91f22f45eea0c95bb1b69f11f1f1d8ee3f10b4d /libvxi11client
parent6b74097642353500f965bdc024c76051c090b4f4 (diff)
Add the ability to wait for interrupts
Diffstat (limited to 'libvxi11client')
-rw-r--r--libvxi11client/perlbits/Client.xs13
-rw-r--r--libvxi11client/perlbits/VXI11-Client.t7
-rw-r--r--libvxi11client/perlbits/perlglue.c47
-rw-r--r--libvxi11client/perlbits/perlglue.h3
4 files changed, 49 insertions, 21 deletions
diff --git a/libvxi11client/perlbits/Client.xs b/libvxi11client/perlbits/Client.xs
index b747707..ebfc037 100644
--- a/libvxi11client/perlbits/Client.xs
+++ b/libvxi11client/perlbits/Client.xs
@@ -52,15 +52,22 @@ docmd(cmd, waitforlock)
RETVAL
int
-enable_srq(enable, callback)
+enable_srq(enable)
bool enable
- SV * callback
CODE:
- RETVAL = glue_enable_srq(enable, callback);
+ RETVAL = glue_enable_srq(enable);
OUTPUT:
RETVAL
int
+wait_for_interrupt()
+ CODE:
+ RETVAL = glue_wait_for_interrupt();
+ OUTPUT:
+ RETVAL
+
+
+int
local(waitforlock)
bool waitforlock
CODE:
diff --git a/libvxi11client/perlbits/VXI11-Client.t b/libvxi11client/perlbits/VXI11-Client.t
index 5b7f35f..1c91965 100644
--- a/libvxi11client/perlbits/VXI11-Client.t
+++ b/libvxi11client/perlbits/VXI11-Client.t
@@ -8,7 +8,7 @@
use strict;
use warnings;
-use Test::More tests => 14;
+use Test::More tests => 17;
BEGIN { use_ok('VXI11::Client') };
#########################
@@ -21,8 +21,9 @@ is(&VXI11::Client::lock(0), 1, "Lock");
is(&VXI11::Client::write("*IDN?", 6, 0, 0), 6, "Write");
ok(&VXI11::Client::readstatusbyte(0) >= 0 , "Read status byte");
is(&VXI11::Client::create_intr_chan(), 1, "Create intr channel");
-#is(&VXI11::Client::enable_srq(1, sub { print "Interrupt fired\n" }), 1, "Enable interrupts");
-#is(&VXI11::Client::enable_srq(0), 1, "Disable interrupts");
+is(&VXI11::Client::enable_srq(1), 1, "Enable interrupts");
+is(&VXI11::Client::wait_for_interrupt, 1, "Wait for interrupt");
+is(&VXI11::Client::enable_srq(0), 1, "Disable interrupts");
is(&VXI11::Client::destroy_intr_chan(), 1, "Destroy intr channel");
is(&VXI11::Client::abort(), 1, "Abort");
is(&VXI11::Client::clear(0), 1, "Clear");
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;
}
diff --git a/libvxi11client/perlbits/perlglue.h b/libvxi11client/perlbits/perlglue.h
index 09e71aa..e2ded42 100644
--- a/libvxi11client/perlbits/perlglue.h
+++ b/libvxi11client/perlbits/perlglue.h
@@ -1,5 +1,6 @@
#include <EXTERN.h>
#include <perl.h>
-int glue_enable_srq(bool enable, SV* callback);
+int glue_enable_srq(bool enable);
+int glue_wait_for_interrupt(void);