From 74d4fb6c3b452599e9fc40c2f7df683bb1cf16d6 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 17 Jan 2013 18:01:30 +0900 Subject: make module perlish (object methods) --- libvxi11client/perlbits/Client.xs | 98 +++++++++++++++++++++++----------- libvxi11client/perlbits/VXI11-Client.t | 38 +++++++------ libvxi11client/perlbits/perlglue.c | 39 ++++++++------ libvxi11client/perlbits/perlglue.h | 8 +-- libvxi11client/perlbits/typemap | 3 +- 5 files changed, 119 insertions(+), 67 deletions(-) (limited to 'libvxi11client/perlbits') 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 +#include +#include #include #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 #include +#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 -- cgit