summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libvxi11client/client.c2
-rw-r--r--libvxi11client/libvxi11client.c33
-rw-r--r--libvxi11client/libvxi11client.h34
-rw-r--r--libvxi11client/perlbits/Client.xs98
-rw-r--r--libvxi11client/perlbits/VXI11-Client.t38
-rw-r--r--libvxi11client/perlbits/perlglue.c39
-rw-r--r--libvxi11client/perlbits/perlglue.h8
-rw-r--r--libvxi11client/perlbits/typemap3
8 files changed, 154 insertions, 101 deletions
diff --git a/libvxi11client/client.c b/libvxi11client/client.c
index 3a79e52..e8c4905 100644
--- a/libvxi11client/client.c
+++ b/libvxi11client/client.c
@@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {
vxi11_start_interrupt_server(interruptcallback);
- Context ctx;
+ VXI11Context ctx;
int err = 0;
diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c
index 8936545..4b17532 100644
--- a/libvxi11client/libvxi11client.c
+++ b/libvxi11client/libvxi11client.c
@@ -99,7 +99,7 @@ static Device_Flags vxi11_generateflags(bool waitlock, bool end, bool termchrset
* $device is apparently used for VXI-11 -> GPIB gateways.. this is untested.
*/
-int vxi11_open(Context* context, char* address, char* device) {
+int vxi11_open(VXI11Context* context, char* address, char* device) {
context->clnt = clnt_create(address, DEVICE_CORE, DEVICE_CORE_VERSION, "tcp");
if (context->clnt == NULL)
@@ -154,7 +154,7 @@ int vxi11_open(Context* context, char* address, char* device) {
* read the status byte of the connected server
*/
-int vxi11_readstatusbyte(Context* context, bool waitforlock) {
+int vxi11_readstatusbyte(VXI11Context* context, bool waitforlock) {
if (context->clnt == NULL)
return 0;
@@ -174,7 +174,7 @@ int vxi11_readstatusbyte(Context* context, bool waitforlock) {
* write to the connected device
*/
-int vxi11_write(Context* context, char* data, unsigned int len, bool waitlock, bool end) {
+int vxi11_write(VXI11Context* context, char* data, unsigned int len, bool waitlock, bool end) {
if (context->clnt == NULL)
return 0;
@@ -196,7 +196,8 @@ int vxi11_write(Context* context, char* data, unsigned int len, bool waitlock, b
* read from the connected device
*/
-int vxi11_read(Context* context, char* buffer, unsigned int bufferlen, bool waitlock, bool termchrset, char termchr) {
+int vxi11_read(VXI11Context* context, char* buffer, unsigned int bufferlen, bool waitlock, bool termchrset,
+ char termchr) {
if (context->clnt == NULL)
return 0;
@@ -223,7 +224,7 @@ int vxi11_read(Context* context, char* buffer, unsigned int bufferlen, bool wait
*
*/
-int vxi11_docmd(Context* context, unsigned long cmd, bool waitforlock) {
+int vxi11_docmd(VXI11Context* context, unsigned long cmd, bool waitforlock) {
if (context->clnt == NULL)
return 0;
@@ -247,7 +248,7 @@ int vxi11_docmd(Context* context, unsigned long cmd, bool waitforlock) {
* trigger the connected device
*/
-int vxi11_trigger(Context* context, bool waitforlock) {
+int vxi11_trigger(VXI11Context* context, bool waitforlock) {
if (context->clnt == NULL)
return 0;
@@ -265,7 +266,7 @@ int vxi11_trigger(Context* context, bool waitforlock) {
* clear the connected device
*/
-int vxi11_clear(Context* context, bool waitforlock) {
+int vxi11_clear(VXI11Context* context, bool waitforlock) {
if (context->clnt == NULL)
return 0;
Device_GenericParms params = { .lid = context->devicelink, .flags = vxi11_generateflags(waitforlock, false, false),
@@ -283,7 +284,7 @@ int vxi11_clear(Context* context, bool waitforlock) {
* remote the connected device
*/
-int vxi11_remote(Context* context, bool waitforlock) {
+int vxi11_remote(VXI11Context* context, bool waitforlock) {
if (context->clnt == NULL)
return 0;
Device_GenericParms params = { .lid = context->devicelink, .flags = vxi11_generateflags(waitforlock, false, false),
@@ -301,7 +302,7 @@ int vxi11_remote(Context* context, bool waitforlock) {
* local the connected device
*/
-int vxi11_local(Context* context, bool waitforlock) {
+int vxi11_local(VXI11Context* context, bool waitforlock) {
if (context->clnt == NULL)
return 0;
Device_GenericParms params = { .lid = context->devicelink, .flags = vxi11_generateflags(waitforlock, false, false),
@@ -319,7 +320,7 @@ int vxi11_local(Context* context, bool waitforlock) {
* lock the connected device
*/
-int vxi11_lock(Context* context, bool waitforlock) {
+int vxi11_lock(VXI11Context* context, bool waitforlock) {
if (context->clnt == NULL)
return 0;
Device_LockParms params = { .lid = context->devicelink, .flags = vxi11_generateflags(waitforlock, false, false),
@@ -337,7 +338,7 @@ int vxi11_lock(Context* context, bool waitforlock) {
* unlock the connected device
*/
-int vxi11_unlock(Context* context) {
+int vxi11_unlock(VXI11Context* context) {
if (context->clnt == NULL)
return 0;
Device_Error* error = device_unlock_1(&(context->devicelink), context->clnt);
@@ -443,7 +444,7 @@ int vxi11_stop_interrupt_server() {
/**
* create an interrupt channel from the connected device
*/
-int vxi11_create_intr_chan(Context* context) {
+int vxi11_create_intr_chan(VXI11Context* context) {
if (context->clnt == NULL || context->interruptchannelopen)
return 0;
else if (interruptthread == NULL) {
@@ -473,7 +474,7 @@ int vxi11_create_intr_chan(Context* context) {
* destroy an interrupt channel from the connected device
*/
-int vxi11_destroy_intr_chan(Context* context) {
+int vxi11_destroy_intr_chan(VXI11Context* context) {
if (context->clnt == NULL || !(context->interruptchannelopen))
return 0;
else if (interruptthread == NULL)
@@ -494,7 +495,7 @@ int vxi11_destroy_intr_chan(Context* context) {
* enable interrupts
*/
-int vxi11_enable_srq(Context* context, bool enable, char* handle) {
+int vxi11_enable_srq(VXI11Context* context, bool enable, char* handle) {
if (context->clnt == NULL || !(context->interruptchannelopen))
return 0;
else if (interruptthread == NULL)
@@ -525,7 +526,7 @@ int vxi11_enable_srq(Context* context, bool enable, char* handle) {
* send an abort to the connected device
*/
-int vxi11_abort(Context* context) {
+int vxi11_abort(VXI11Context* context) {
if (context->abortclnt == NULL)
return 0;
Device_Error* error = device_abort_1(&(context->devicelink), context->abortclnt);
@@ -541,7 +542,7 @@ int vxi11_abort(Context* context) {
* close the current link and free the RPC client
*/
-int vxi11_close(Context* context) {
+int vxi11_close(VXI11Context* context) {
if (context->clnt == NULL)
return 0;
diff --git a/libvxi11client/libvxi11client.h b/libvxi11client/libvxi11client.h
index 27da46c..4620abe 100644
--- a/libvxi11client/libvxi11client.h
+++ b/libvxi11client/libvxi11client.h
@@ -22,23 +22,23 @@ typedef struct {
Device_Link devicelink;
bool interruptchannelopen;
bool interruptsenabled;
-} Context;
+} VXI11Context;
-int vxi11_open(Context* context, char* address, char* device);
-int vxi11_abort(Context* context);
-int vxi11_trigger(Context* context, bool waitforlock);
-int vxi11_clear(Context* context, bool waitforlock);
-int vxi11_write(Context* context, char* data, unsigned int len, bool waitlock, bool end);
-int vxi11_read(Context* context, char* buffer, unsigned int bufferlen, bool waitlock, bool termchrset, char termchr);
-int vxi11_lock(Context* context, bool waitforlock);
-int vxi11_unlock(Context* context);
-int vxi11_local(Context* context, bool waitforlock);
-int vxi11_remote(Context* context, bool waitforlock);
-int vxi11_readstatusbyte(Context* context, bool waitforlock);
-int vxi11_create_intr_chan(Context* context);
-int vxi11_destroy_intr_chan(Context* context);
-int vxi11_enable_srq(Context* context, bool enable, char* handle);
+int vxi11_open(VXI11Context* context, char* address, char* device);
+int vxi11_abort(VXI11Context* context);
+int vxi11_trigger(VXI11Context* context, bool waitforlock);
+int vxi11_clear(VXI11Context* context, bool waitforlock);
+int vxi11_write(VXI11Context* context, char* data, unsigned int len, bool waitlock, bool end);
+int vxi11_read(VXI11Context* context, char* buffer, unsigned int bufferlen, bool waitlock, bool termchrset, char termchr);
+int vxi11_lock(VXI11Context* context, bool waitforlock);
+int vxi11_unlock(VXI11Context* context);
+int vxi11_local(VXI11Context* context, bool waitforlock);
+int vxi11_remote(VXI11Context* context, bool waitforlock);
+int vxi11_readstatusbyte(VXI11Context* context, bool waitforlock);
+int vxi11_create_intr_chan(VXI11Context* context);
+int vxi11_destroy_intr_chan(VXI11Context* context);
+int vxi11_enable_srq(VXI11Context* context, bool enable, char* handle);
int vxi11_start_interrupt_server(void (*callback)(char* handle));
int vxi11_stop_interrupt_server();
-int vxi11_docmd(Context* context, unsigned long cmd, bool waitforlock);
-int vxi11_close(Context* context);
+int vxi11_docmd(VXI11Context* context, unsigned long cmd, bool waitforlock);
+int vxi11_close(VXI11Context* context);
diff --git a/libvxi11client/perlbits/Client.xs b/libvxi11client/perlbits/Client.xs
index 3bd831f..2da6581 100644
--- a/libvxi11client/perlbits/Client.xs
+++ b/libvxi11client/perlbits/Client.xs
@@ -4,60 +4,86 @@
#include "ppport.h"
+#include "perlglue.h"
+
+typedef VXI11Context* VXI11__Client;
+
MODULE = VXI11::Client PACKAGE = VXI11::Client
PROTOTYPES: ENABLE
int
-abort()
+startinterruptserver()
CODE:
- RETVAL = vxi11_abort();
+ RETVAL = glue_start_interrupt_server();
OUTPUT:
RETVAL
+int
+stopinterruptserver()
+ CODE:
+ RETVAL = glue_stop_interrupt_server();
+ OUTPUT:
+ RETVAL
+
int
-clear(waitforlock)
+abort(context)
+ VXI11::Client context
+ CODE:
+ RETVAL = vxi11_abort(context);
+ OUTPUT:
+ RETVAL
+
+int
+clear(context,waitforlock)
+ VXI11::Client context
bool waitforlock
CODE:
- RETVAL = vxi11_clear(waitforlock);
+ RETVAL = vxi11_clear(context, waitforlock);
OUTPUT:
RETVAL
int
-close()
+close(context)
+ VXI11::Client context
CODE:
- RETVAL = vxi11_close();
+ RETVAL = vxi11_close(context);
OUTPUT:
RETVAL
int
-create_intr_chan()
+create_intr_chan(context)
+ VXI11::Client context
CODE:
- RETVAL = vxi11_create_intr_chan();
+ RETVAL = vxi11_create_intr_chan(context);
OUTPUT:
RETVAL
int
-destroy_intr_chan()
+destroy_intr_chan(context)
+ VXI11::Client context
CODE:
- RETVAL = vxi11_destroy_intr_chan();
+ RETVAL = vxi11_destroy_intr_chan(context);
OUTPUT:
RETVAL
int
-docmd(cmd, waitforlock)
+docmd(context, cmd, waitforlock)
+ VXI11::Client context
unsigned long cmd
bool waitforlock
CODE:
- RETVAL = vxi11_docmd();
+ RETVAL = vxi11_docmd(context, cmd, waitforlock);
OUTPUT:
RETVAL
int
-enable_srq(enable)
+enable_srq(context, enable, handle)
+ VXI11::Client context
bool enable
+ char* handle
CODE:
- RETVAL = glue_enable_srq(enable);
+ RETVAL = vxi11_enable_srq(context,enable,handle);
OUTPUT:
RETVAL
@@ -70,80 +96,88 @@ wait_for_interrupt()
int
-local(waitforlock)
+local(context, waitforlock)
+ VXI11::Client context
bool waitforlock
CODE:
- RETVAL = vxi11_local(waitforlock);
+ RETVAL = vxi11_local(context, waitforlock);
OUTPUT:
RETVAL
int
-lock(waitforlock)
+lock(context, waitforlock)
+ VXI11::Client context
bool waitforlock
CODE:
- RETVAL = vxi11_lock(waitforlock);
+ RETVAL = vxi11_lock(context, waitforlock);
OUTPUT:
RETVAL
-int
+VXI11::Client
open(address, device)
char * address
char * device
CODE:
- RETVAL = vxi11_open(address, device);
+ RETVAL = glue_open(address, device);
OUTPUT:
RETVAL
int
-read(buffer, bufferlen, waitlock, termchrset, termchr)
+read(context, buffer, bufferlen, waitlock, termchrset, termchr)
+ VXI11::Client context
char * buffer
unsigned int bufferlen
bool waitlock
bool termchrset
char termchr
CODE:
- RETVAL = vxi11_read(buffer, bufferlen, waitlock, termchrset, termchr);
+ RETVAL = vxi11_read(context, buffer, bufferlen, waitlock, termchrset, termchr);
OUTPUT:
RETVAL
int
-readstatusbyte(waitforlock)
+readstatusbyte(context, waitforlock)
+ VXI11::Client context
bool waitforlock
CODE:
- RETVAL = vxi11_readstatusbyte();
+ RETVAL = vxi11_readstatusbyte(context, waitforlock);
OUTPUT:
RETVAL
int
-remote(waitforlock)
+remote(context, waitforlock)
+ VXI11::Client context
bool waitforlock
CODE:
- RETVAL = vxi11_remote();
+ RETVAL = vxi11_remote(context, waitforlock);
OUTPUT:
RETVAL
int
-trigger(waitforlock)
+trigger(context, waitforlock)
+ VXI11::Client context
bool waitforlock
CODE:
- RETVAL = vxi11_trigger();
+ RETVAL = vxi11_trigger(context, waitforlock);
OUTPUT:
RETVAL
int
-unlock()
+unlock(context)
+ VXI11::Client context
CODE:
- RETVAL = vxi11_unlock();
+ RETVAL = vxi11_unlock(context);
OUTPUT:
RETVAL
int
-write(data, len, waitlock, end)
+write(context,data, len, waitlock, end)
+ VXI11::Client context
char * data
unsigned int len
bool waitlock
bool end
CODE:
- RETVAL = vxi11_write(data, len, waitlock, end);
+ RETVAL = vxi11_write(context, data, len, waitlock, end);
OUTPUT:
RETVAL
diff --git a/libvxi11client/perlbits/VXI11-Client.t b/libvxi11client/perlbits/VXI11-Client.t
index 1c91965..ef2aae0 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 => 17;
+use Test::More tests => 16;
BEGIN { use_ok('VXI11::Client') };
#########################
@@ -16,19 +16,25 @@ BEGIN { use_ok('VXI11::Client') };
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.
-is(&VXI11::Client::open("roi", 0), 1, "Open");
-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), 1, "Enable interrupts");
+&VXI11::Client::startinterruptserver();
+
+my $instr = &VXI11::Client::open("roi", 0);
+
+is($instr->lock(0), 1, "Lock");
+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::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");
-is(&VXI11::Client::trigger(0), 1, "Trigger");
-is(&VXI11::Client::local(0), 1, "Local");
-is(&VXI11::Client::remote(0), 1, "Remote");
-is(&VXI11::Client::unlock(), 1, "Unlock");
-is(&VXI11::Client::close(), 1, "Close");
+is($instr->enable_srq(0, ""), 1, "Disable interrupts");
+is($instr->destroy_intr_chan(), 1, "Destroy intr channel");
+is($instr->abort(), 1, "Abort");
+is($instr->clear(0), 1, "Clear");
+is($instr->trigger(0), 1, "Trigger");
+is($instr->local(0), 1, "Local");
+is($instr->remote(0), 1, "Remote");
+is($instr->unlock(), 1, "Unlock");
+
+is($instr->close(), 1, "Close");
+
+&VXI11::Client::stopinterruptserver();
diff --git a/libvxi11client/perlbits/perlglue.c b/libvxi11client/perlbits/perlglue.c
index 62d9748..551136e 100644
--- a/libvxi11client/perlbits/perlglue.c
+++ b/libvxi11client/perlbits/perlglue.c
@@ -1,31 +1,40 @@
-#include <stdbool.h>
+#include <EXTERN.h>
+#include <perl.h>
#include <glib.h>
#include "libvxi11client.h"
-#define INTERRUPTHANDLE "libvxi11client"
-
-GAsyncQueue* interruptqueue;
+static GAsyncQueue* interruptqueue;
typedef struct {
GTimeVal when;
+ char* handle;
} Event;
-static void interruptcallback(void) {
+static void interruptcallback(char* handle) {
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;
- }
+VXI11Context* glue_open(char* address, char* device) {
+ VXI11Context* context = malloc(sizeof(VXI11Context));
+ if (context == NULL)
+ return NULL;
+
+ int err = vxi11_open(context, address, device);
+
+ return context;
+}
+
+int glue_start_interrupt_server() {
+ interruptqueue = g_async_queue_new();
+ return vxi11_start_interrupt_server(interruptcallback);
+}
+
+int glue_stop_interrupt_server() {
+ int ret = vxi11_stop_interrupt_server();
+ g_free(interruptqueue);
+ return ret;
}
int glue_wait_for_interrupt() {
diff --git a/libvxi11client/perlbits/perlglue.h b/libvxi11client/perlbits/perlglue.h
index e2ded42..8c33c7d 100644
--- a/libvxi11client/perlbits/perlglue.h
+++ b/libvxi11client/perlbits/perlglue.h
@@ -1,6 +1,8 @@
#include <EXTERN.h>
#include <perl.h>
+#include "libvxi11client.h"
-int glue_enable_srq(bool enable);
-int glue_wait_for_interrupt(void);
-
+int glue_wait_for_interrupt();
+VXI11Context* glue_open(char* address, char* device);
+int glue_start_interrupt_server();
+int glue_stop_interrupt_server();
diff --git a/libvxi11client/perlbits/typemap b/libvxi11client/perlbits/typemap
index 4391935..2434aaa 100644
--- a/libvxi11client/perlbits/typemap
+++ b/libvxi11client/perlbits/typemap
@@ -1 +1,2 @@
-_Bool T_IV
+VXI11Context * T_PTROBJ
+VXI11::Client T_PTROBJ