From: Adam Dickmeiss Date: Fri, 28 Jul 1995 10:28:36 +0000 (+0000) Subject: First work on request queue. X-Git-Tag: IRTCL.1.4~227 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=5139a081952de0c231f53bc4876655e0fcecd994;p=ir-tcl-moved-to-github.git First work on request queue. --- diff --git a/Makefile.in b/Makefile.in index d2a9138..b2ec7c1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2,7 +2,7 @@ # (c) Index Data 1995 # See the file LICENSE for details. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile.in,v 1.13 1995-06-29 14:06:24 adam Exp $ +# $Id: Makefile.in,v 1.14 1995-07-28 10:28:36 adam Exp $ SHELL=/bin/sh # IrTcl Version @@ -52,7 +52,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ RANLIB = @RANLIB@ -O=ir-tcl.o marc.o +O=ir-tcl.o marc.o queue.o all: ir-tk ir-tcl diff --git a/configure.in b/configure.in index 0fd822c..c05ad73 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ dnl IR toolkit for tcl/tk dnl (c) Index Data 1995 dnl See the file LICENSE for details. -dnl $Id: configure.in,v 1.6 1995-06-29 14:06:26 adam Exp $ +dnl $Id: configure.in,v 1.7 1995-07-28 10:28:37 adam Exp $ AC_INIT(ir-tcl.h) CC=${CC-cc} AC_SUBST(CC) @@ -36,7 +36,7 @@ if test "$YAZDIR" = "yes"; then YAZDIR="../yaz-1.0b" elif test "$YAZDIR" = ""; then YAZDIR="../yaz" - for i in ../yaz-1.0b3 ../yaz-1.0b2 ../yaz-1.0b1 ../yaz-1.0b ../yaz; do + for i in ../yaz-1.0b ../yaz-1.0b2 ../yaz-1.0b3 ../yaz-1.0b4 ../yaz-1.0 ../yaz; do if test -d $i; then YAZDIR=$i fi diff --git a/ir-tclp.h b/ir-tclp.h index 0898d3a..e5b03b6 100644 --- a/ir-tclp.h +++ b/ir-tclp.h @@ -5,7 +5,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: ir-tclp.h,v $ - * Revision 1.11 1995-06-20 08:07:35 adam + * Revision 1.12 1995-07-28 10:28:38 adam + * First work on request queue. + * + * Revision 1.11 1995/06/20 08:07:35 adam * New setting: failInfo. * Working on better cancel mechanism. * @@ -138,10 +141,26 @@ typedef struct { struct IrTcl_SetObj_ *set_child; struct IrTcl_ScanObj_ *scan_child; + struct IrTcl_Request_ *request_queue; IrTcl_SetCObj set_inher; } IrTcl_Obj; +typedef struct IrTcl_Request_ { + char *name_of_object; + struct IrTcl_Request_ *next; + + char *buf_out; + int len_out; + char *buf_in; + int len_in; + + char *callback; + char *failback; + + int state; +} IrTcl_Request; + typedef struct { int condition; char *addinfo; @@ -224,6 +243,8 @@ struct ir_named_entry { int ir_tcl_get_marc (Tcl_Interp *interp, const char *buf, int argc, char **argv); +int ir_tcl_send (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu, + const char *msg); char *ir_tcl_fread_marc (FILE *inf, size_t *size); #define IR_TCL_FAIL_CONNECT 1 @@ -231,4 +252,8 @@ char *ir_tcl_fread_marc (FILE *inf, size_t *size); #define IR_TCL_FAIL_WRITE 3 #define IR_TCL_FAIL_IN_APDU 4 #define IR_TCL_FAIL_UNKNOWN_APDU 5 + +#define IR_TCL_R_Queue 0 +#define IR_TCL_R_Writing 1 +#define IR_TCL_R_Waiting 2 #endif diff --git a/queue.c b/queue.c new file mode 100644 index 0000000..29c2b65 --- /dev/null +++ b/queue.c @@ -0,0 +1,78 @@ + +/* + * IR toolkit for tcl/tk + * (c) Index Data 1995 + * See the file LICENSE for details. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: queue.c,v $ + * Revision 1.1 1995-07-28 10:28:39 adam + * First work on request queue. + * + */ + +#include +#include +#include +#include + +#include "ir-tclp.h" + +void *ir_tcl_malloc (size_t size) +{ + void *p = malloc (size); + if (!p) + { + logf (LOG_FATAL, "Out of memory. %d bytes requested", size); + exit (1); + } + return p; +} + +int ir_tcl_send (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu, + const char *msg) +{ + IrTcl_Request **rp; + int empty; + + if (!z_APDU (p->odr_out, &apdu, 0)) + { + Tcl_AppendResult (interp, odr_errlist [odr_geterror (p->odr_out)], + NULL); + odr_reset (p->odr_out); + return TCL_ERROR; + } + rp = &p->request_queue; + empty = *rp ? 0 : 1; + while (*rp) + rp = &(*rp)->next; + *rp = ir_tcl_malloc (sizeof(**rp)); + (*rp)->next = NULL; + (*rp)->state = IR_TCL_R_Queue; + (*rp)->buf_out = odr_getbuf (p->odr_out, &(*rp)->len_out, NULL); + odr_reset (p->odr_out); + if (empty) + { + int r; + + r = cs_put (p->cs_link, (*rp)->buf_out, (*rp)->len_out); + if (r < 0) + { + sprintf (interp->result, "cs_put failed in %s", msg); + return TCL_ERROR; + } + else if (r == 1) + { + ir_select_add_write (cs_fileno (p->cs_link), p); + logf (LOG_DEBUG, "Send part of %s", msg); + (*rp)->state = IR_TCL_R_Writing; + } + else + { + logf (LOG_DEBUG, "Send %s (%d bytes)", msg, (*rp)->len_out); + (*rp)->state = IR_TCL_R_Waiting; + } + } + return TCL_OK; +} +