From 63352c7277aa5760cca113b9a97d09716ba4e7f8 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 21 Feb 1996 10:16:08 +0000 Subject: [PATCH] Simplified select handling. Only one function ir_tcl_select_set has to be externally defined. --- ir-tcl.c | 42 ++++++++++++++++++++++-- ir-tcl.h | 30 +++++------------ ir-tclp.h | 12 +++++-- tclmain.c | 109 +++++++++++++++++++------------------------------------------ 4 files changed, 91 insertions(+), 102 deletions(-) diff --git a/ir-tcl.c b/ir-tcl.c index 8355899..d87d4d8 100644 --- a/ir-tcl.c +++ b/ir-tcl.c @@ -5,7 +5,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: ir-tcl.c,v $ - * Revision 1.77 1996-02-20 17:52:58 adam + * Revision 1.78 1996-02-21 10:16:08 adam + * Simplified select handling. Only one function ir_tcl_select_set has + * to be externally defined. + * + * Revision 1.77 1996/02/20 17:52:58 adam * Uses the YAZ oid system to name record syntax object identifiers. * * Revision 1.76 1996/02/20 16:09:51 adam @@ -281,6 +285,8 @@ #define CS_BLOCK 0 +#define IRTCL_GENERIC_FILES 0 + #include "ir-tclp.h" typedef struct { @@ -298,6 +304,28 @@ static void ir_deleteDiags (IrTcl_Diagnostic **dst_list, int *dst_num); static int do_disconnect (void *obj, Tcl_Interp *interp, int argc, char **argv); +static void ir_select_notify (ClientData clientData, int r, int w, int e); + +void ir_select_add (int fd, void *obj) +{ + ir_tcl_select_set (ir_select_notify, fd, obj, 1, 0, 0); +} + +void ir_select_add_write (int fd, void *obj) +{ + ir_tcl_select_set (ir_select_notify, fd, obj, 1, 1, 0); +} + +void ir_select_remove (int fd, void *obj) +{ + ir_tcl_select_set (NULL, fd, obj, 0, 0, 0); +} + +void ir_select_remove_write (int fd, void *obj) +{ + ir_tcl_select_set (ir_select_notify, fd, obj, 1, 0, 0); +} + static IrTcl_RecordList *new_IR_record (IrTcl_SetObj *setobj, int no, int which, const char *elements) @@ -3367,7 +3395,7 @@ static void ir_scanResponse (void *o, Z_ScanResponse *scanrs, /* * ir_select_read: handle incoming packages */ -void ir_select_read (ClientData clientData) +static void ir_select_read (ClientData clientData) { IrTcl_Obj *p = clientData; Z_APDU *apdu; @@ -3541,7 +3569,7 @@ void ir_select_read (ClientData clientData) /* * ir_select_write: handle outgoing packages - not yet written. */ -void ir_select_write (ClientData clientData) +static void ir_select_write (ClientData clientData) { IrTcl_Obj *p = clientData; int r; @@ -3610,6 +3638,14 @@ void ir_select_write (ClientData clientData) } } +static void ir_select_notify (ClientData clientData, int r, int w, int e) +{ + if (r) + ir_select_read (clientData); + if (w) + ir_select_write (clientData); +} + /* ------------------------------------------------------- */ /* diff --git a/ir-tcl.h b/ir-tcl.h index 36fdf3a..249197f 100644 --- a/ir-tcl.h +++ b/ir-tcl.h @@ -24,7 +24,11 @@ * OF THIS SOFTWARE. * * $Log: ir-tcl.h,v $ - * Revision 1.13 1996-02-19 15:41:54 adam + * Revision 1.14 1996-02-21 10:16:19 adam + * Simplified select handling. Only one function ir_tcl_select_set has + * to be externally defined. + * + * Revision 1.13 1996/02/19 15:41:54 adam * Better log messages. * Minor improvement of connect method. * @@ -67,27 +71,9 @@ #ifndef IR_TCL_H #define IR_TCL_H -#if 0 -#define IRTCL_GENERIC_FILES 1 -#else -#define IRTCL_GENERIC_FILES 0 -#endif - int Irtcl_Init (Tcl_Interp *interp); -#if IRTCL_GENERIC_FILES -void ir_select_add (Tcl_File file, void *obj); -void ir_select_add_write (Tcl_File file, void *obj); -void ir_select_remove (Tcl_File file, void *obj); -void ir_select_remove_write (Tcl_File file, void *obj); -#else -void ir_select_add (int fd, void *obj); -void ir_select_add_write (int fd, void *obj); -void ir_select_remove (int fd, void *obj); -void ir_select_remove_write (int fd, void *obj); -#endif - -void ir_select_read (ClientData clientData); -void ir_select_write (ClientData clientData); - +void *ir_tcl_malloc (size_t size); +void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e), + int fd, ClientData clientData, int r, int w, int e); #endif diff --git a/ir-tclp.h b/ir-tclp.h index 2959875..4813c41 100644 --- a/ir-tclp.h +++ b/ir-tclp.h @@ -5,7 +5,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: ir-tclp.h,v $ - * Revision 1.25 1996-02-05 17:58:04 adam + * Revision 1.26 1996-02-21 10:16:20 adam + * Simplified select handling. Only one function ir_tcl_select_set has + * to be externally defined. + * + * Revision 1.25 1996/02/05 17:58:04 adam * Ported ir-tcl to use the beta releases of tcl7.5/tk4.1. * * Revision 1.24 1996/01/29 11:35:27 adam @@ -329,7 +333,6 @@ int ir_tcl_send_APDU (Tcl_Interp *interp, IrTcl_Obj *p, Z_APDU *apdu, const char *msg, const char *object_name); int ir_tcl_send_q (IrTcl_Obj *p, IrTcl_Request *rq, const char *msg); void ir_tcl_del_q (IrTcl_Obj *p); -void *ir_tcl_malloc (size_t size); int ir_tcl_strdup (Tcl_Interp *interp, char** p, const char *s); int ir_tcl_strdel (Tcl_Interp *interp, char **p); @@ -338,6 +341,11 @@ void ir_tcl_read_grs (Z_GenericRecord *r, IrTcl_GRS_Record **grs_record); int ir_tcl_get_grs (Tcl_Interp *interp, IrTcl_GRS_Record *grs_record, int argc, char **argv); +void ir_select_add (int fd, void *obj); +void ir_select_add_write (int fd, void *obj); +void ir_select_remove (int fd, void *obj); +void ir_selcet_remove_write (int fd, void *obj); + #define IR_TCL_FAIL_CONNECT 1 #define IR_TCL_FAIL_READ 2 #define IR_TCL_FAIL_WRITE 3 diff --git a/tclmain.c b/tclmain.c index a238fba..72f3fd1 100644 --- a/tclmain.c +++ b/tclmain.c @@ -5,7 +5,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: tclmain.c,v $ - * Revision 1.16 1996-02-05 17:58:05 adam + * Revision 1.17 1996-02-21 10:16:21 adam + * Simplified select handling. Only one function ir_tcl_select_set has + * to be externally defined. + * + * Revision 1.16 1996/02/05 17:58:05 adam * Ported ir-tcl to use the beta releases of tcl7.5/tk4.1. * * Revision 1.15 1996/01/10 09:18:45 adam @@ -71,10 +75,9 @@ static char *fileName = NULL; /* select(2) callbacks */ struct callback { - void (*r_handle)(ClientData); - void (*w_handle)(ClientData); - void (*x_handle)(ClientData); - void *obj; + void (*handle)(ClientData, int, int, int); + int r, w, e; + ClientData obj; }; #define MAX_CALLBACK 200 @@ -107,11 +110,7 @@ int main (int argc, char **argv) fprintf(stderr, "Tcl_AppInit failed: %s\n", interp->result); } for (i=0; i max_fd) - max_fd = fd; -} - -#if IRTCL_GENERIC_FILES -void ir_select_add_write (Tcl_File file, void *obj) -{ - int fd = (int) Tcl_GetFileInfo (file, NULL); -#else -void ir_select_add_write (int fd, void *obj) +void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e), + int fd, ClientData clientData, int r, int w, int e) { -#endif - callback_table[fd].w_handle = ir_select_write; + callback_table[fd].handle = f; + callback_table[fd].obj = clientData; + callback_table[fd].r = r; + callback_table[fd].w = w; + callback_table[fd].e = e; if (fd > max_fd) max_fd = fd; } -#if IRTCL_GENERIC_FILES -void ir_select_remove_write (Tcl_File file, void *obj) -{ - int fd = (int) Tcl_GetFileInfo (file, NULL); -#else -void ir_select_remove_write (int fd, void *obj) -{ -#endif - callback_table[fd].w_handle = NULL; -} - -#if IRTCL_GENERIC_FILES -void ir_select_remove (Tcl_File file, void *obj) -{ - int fd = (int) Tcl_GetFileInfo (file, NULL); -#else -void ir_select_remove (int fd, void *obj) -{ -#endif - callback_table[fd].r_handle = NULL; - callback_table[fd].w_handle = NULL; - callback_table[fd].x_handle = NULL; -} -- 1.7.10.4