From c53ea096ab5a656f93ad2aed8d50f5dd346f91c3 Mon Sep 17 00:00:00 2001
From: daniel <danieruru@gmail.com>
Date: Wed, 23 Jan 2013 13:17:52 +0900
Subject: Update docs, add the "global" functions to the export list, add the
 reason from read to the stuff that gets returned.

---
 libvxi11client/Makefile                |  1 +
 libvxi11client/libvxi11client.c        |  4 +++-
 libvxi11client/libvxi11client.h        |  3 ++-
 libvxi11client/perlbits/Client.xs      |  5 +++--
 libvxi11client/perlbits/README         | 20 --------------------
 libvxi11client/perlbits/VXI11-Client.t |  2 +-
 libvxi11client/perlbits/testscript.pl  | 10 +++++-----
 libvxi11client/perlbits/typemap        |  1 +
 8 files changed, 16 insertions(+), 30 deletions(-)

diff --git a/libvxi11client/Makefile b/libvxi11client/Makefile
index ec74afe..4e15df9 100644
--- a/libvxi11client/Makefile
+++ b/libvxi11client/Makefile
@@ -34,6 +34,7 @@ perl:
 	cp perlbits/Makefile.PL VXI11-Client/
 	cp perlbits/VXI11-Client.t VXI11-Client/t/ 
 	cp perlbits/typemap VXI11-Client/
+	cp perlbits/Client.pm VXI11-Client/lib/VXI11/Client.pm
 	cd VXI11-Client/ && perl Makefile.PL
 	cd VXI11-Client/ && make
 	cd VXI11-Client/ && make test
diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c
index 2c6f3a8..ebd71ee 100644
--- a/libvxi11client/libvxi11client.c
+++ b/libvxi11client/libvxi11client.c
@@ -200,7 +200,7 @@ int vxi11_write(VXI11Context* context, char* data, int len, bool waitlock, bool
  */
 
 int vxi11_read(VXI11Context* context, char* buffer, unsigned int bufferlen, bool waitlock, bool termchrset,
-		char termchr) {
+		char termchr, unsigned int* reason) {
 	if (context->clnt == NULL)
 		return 0;
 
@@ -215,6 +215,8 @@ int vxi11_read(VXI11Context* context, char* buffer, unsigned int bufferlen, bool
 #endif
 		if (buffer != NULL)
 			strncpy(buffer, resp->data.data_val, (bufferlen < resp->data.data_len ? bufferlen : resp->data.data_len));
+		if (reason != NULL)
+			*reason = resp->reason;
 #ifdef DEBUG
 		else
 			printf("Supplied buffer is null!\n");
diff --git a/libvxi11client/libvxi11client.h b/libvxi11client/libvxi11client.h
index 26a383f..740e3d3 100644
--- a/libvxi11client/libvxi11client.h
+++ b/libvxi11client/libvxi11client.h
@@ -29,7 +29,8 @@ 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, int len, bool waitlock, bool end);
-int vxi11_read(VXI11Context* 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, unsigned int* reason);
 int vxi11_lock(VXI11Context* context, bool waitforlock);
 int vxi11_unlock(VXI11Context* context);
 int vxi11_local(VXI11Context* context, bool waitforlock);
diff --git a/libvxi11client/perlbits/Client.xs b/libvxi11client/perlbits/Client.xs
index d8008dd..d471fda 100644
--- a/libvxi11client/perlbits/Client.xs
+++ b/libvxi11client/perlbits/Client.xs
@@ -123,7 +123,7 @@ vxi_open(address, device)
 		RETVAL
 
 void
-vxi_read(context, OUTLIST bytesread, OUTLIST buffer, bufferlen, waitlock, termchrset, termchr)
+vxi_read(context, OUTLIST bytesread, OUTLIST buffer, bufferlen, waitlock, termchrset, termchr, OUTLIST reason)
 	VXI11::Client context
 	char *	buffer
 	int 	bytesread
@@ -131,9 +131,10 @@ vxi_read(context, OUTLIST bytesread, OUTLIST buffer, bufferlen, waitlock, termch
 	bool	waitlock
 	bool	termchrset
 	char	termchr
+	unsigned int*	reason
 	CODE:
 		buffer = malloc(bufferlen + 1);
-		bytesread = vxi11_read(context, buffer, bufferlen, waitlock, termchrset, termchr);
+		bytesread = vxi11_read(context, buffer, bufferlen, waitlock, termchrset, termchr, reason);
 
 int
 vxi_readstatusbyte(context, waitforlock)
diff --git a/libvxi11client/perlbits/README b/libvxi11client/perlbits/README
index ba3e278..d036787 100644
--- a/libvxi11client/perlbits/README
+++ b/libvxi11client/perlbits/README
@@ -4,26 +4,6 @@ VXI11-Client version 0.01
 This module is a wrapper around a C library that uses libc's built in
 Sun RPC support to talk to VXI11 networked instruments. 
 
-It supports only one instrument at a time.
-
-Interrupts work by creating the interrupt channel, enabling interrupts 
-and then using wait_for_interrupt() to wait for an interrupt to happen.
-wait_for_interrupt() blocks until a interrupt happens or a timeout occurs. 
-If an interrupt happens before it is called it returns immediately.
-If multiple interrupts happen before it is called it will return immediately
-until all the fired interrupts are cleared.
-
-Return codes work like this;
-1   - is a success
-0   - means the request failed locally, the state inside the client is
-incorrect, i.e. calling to enable interrupts before creating the channel
-or that the server couldn't be contacted
-< 0 - Any negative value is the negated VXI-11 error code from the server
-
-The only exceptions to this are the read and write methods
-0   - Error as above or zero bytes read/written
-> 0 - Number of bytes read/written
-
 INSTALLATION
 
 To install this module type the following:
diff --git a/libvxi11client/perlbits/VXI11-Client.t b/libvxi11client/perlbits/VXI11-Client.t
index 8ca167b..243d8d9 100644
--- a/libvxi11client/perlbits/VXI11-Client.t
+++ b/libvxi11client/perlbits/VXI11-Client.t
@@ -23,7 +23,7 @@ my $instr = &VXI11::Client::vxi_open("roi", 0);
 is($instr->vxi_lock(0), 1, "Lock");
 ok($instr->vxi_write("*IDN?", -1, 0, 0) > 0, "Write");
 
-my ($bytes, $buff) = $instr->vxi_read(256, 0, 0, 0);
+my ($bytes, $buff, $reason) = $instr->vxi_read(256, 0, 0, 0);
 print "got " . $bytes . ";" . $buff . "\n";
 ok($bytes > 0, "Read");
 
diff --git a/libvxi11client/perlbits/testscript.pl b/libvxi11client/perlbits/testscript.pl
index b487ab4..440035d 100644
--- a/libvxi11client/perlbits/testscript.pl
+++ b/libvxi11client/perlbits/testscript.pl
@@ -3,19 +3,19 @@ use warnings;
 
 use VXI11::Client;
 
-&VXI11::Client::vxi_startinterruptserver();
+vxi_startinterruptserver();
 
-my $instr = &VXI11::Client::vxi_open("roi", 0);
+my $instr = vxi_open("roi", 0);
 
 $instr->vxi_lock(0);
 $instr->vxi_write("*IDN?", -1, 0, 0);
-my ($bytes, $buff) = $instr->vxi_read(256, 0, 0, 0);
+my ($bytes, $buff, $reason) = $instr->vxi_read(256, 0, 0, 0);
 print "got " . $bytes . ";" . $buff . "\n";
 
 $instr->vxi_readstatusbyte(0);
 $instr->vxi_create_intr_chan();
 $instr->vxi_enable_srq(1, "myhandle");
-&VXI11::Client::vxi_wait_for_interrupt();
+vxi_wait_for_interrupt();
 $instr->vxi_enable_srq(0, "");
 $instr->vxi_destroy_intr_chan();
 $instr->vxi_abort();
@@ -27,4 +27,4 @@ $instr->vxi_unlock();
 
 $instr->vxi_close();
 
-&VXI11::Client::vxi_stopinterruptserver();
+vxi_stopinterruptserver();
diff --git a/libvxi11client/perlbits/typemap b/libvxi11client/perlbits/typemap
index 2434aaa..3b9a362 100644
--- a/libvxi11client/perlbits/typemap
+++ b/libvxi11client/perlbits/typemap
@@ -1,2 +1,3 @@
 VXI11Context *					T_PTROBJ
 VXI11::Client					T_PTROBJ
+unsigned int *					T_IV
-- 
cgit