to be externally defined.
* 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
#define CS_BLOCK 0
+#define IRTCL_GENERIC_FILES 0
+
#include "ir-tclp.h"
typedef struct {
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)
/*
* 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;
/*
* 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;
}
}
+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);
+}
+
/* ------------------------------------------------------- */
/*
* 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.
*
#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
* 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
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);
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
* 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
/* 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
fprintf(stderr, "Tcl_AppInit failed: %s\n", interp->result);
}
for (i=0; i<MAX_CALLBACK; i++)
- {
- callback_table[i].r_handle = NULL;
- callback_table[i].w_handle = NULL;
- callback_table[i].x_handle = NULL;
- }
+ callback_table[i].handle = NULL;
if (fileName)
{
code = Tcl_EvalFile (interp, fileName);
FD_SET (0, &fdset_tcl_r);
for (res=0, i=min_fd; i<=max_fd; i++)
{
- if (callback_table[i].w_handle)
+ if (callback_table[i].handle && callback_table[i].w)
{
FD_SET (i, &fdset_tcl_w);
res++;
}
- if (callback_table[i].r_handle)
+ if (callback_table[i].handle && callback_table[i].r)
{
FD_SET (i, &fdset_tcl_r);
res++;
}
- if (callback_table[i].x_handle)
+ if (callback_table[i].handle && callback_table[i].e)
{
FD_SET (i, &fdset_tcl_x);
res++;
continue;
for (i=min_fd; i<=max_fd; i++)
{
- if (FD_ISSET (i, &fdset_tcl_r))
- {
- if (callback_table[i].r_handle)
- (*callback_table[i].r_handle) (callback_table[i].obj);
- }
- if (FD_ISSET (i, &fdset_tcl_w))
- {
- if (callback_table[i].w_handle)
- (*callback_table[i].w_handle) (callback_table[i].obj);
- }
- if (FD_ISSET (i, &fdset_tcl_x))
- {
- if (callback_table[i].x_handle)
- (*callback_table[i].x_handle) (callback_table[i].obj);
- }
+ int r_flag = 0;
+ int w_flag = 0;
+ int e_flag = 0;
+
+ if (!callback_table[i].handle)
+ continue;
+ if (FD_ISSET (i, &fdset_tcl_r) && callback_table[i].r)
+ r_flag = 1;
+ if (FD_ISSET (i, &fdset_tcl_w) && callback_table[i].w)
+ w_flag = 1;
+ if (FD_ISSET (i, &fdset_tcl_x) && callback_table[i].e)
+ e_flag = 1;
+ if (r_flag || w_flag || e_flag)
+ (*callback_table[i].handle)(callback_table[i].obj,
+ r_flag, w_flag, e_flag);
}
if (interactive && FD_ISSET(0, &fdset_tcl_r))
{
}
}
-#if IRTCL_GENERIC_FILES
-void ir_select_add (Tcl_File file, void *obj)
-{
- int fd = (int) Tcl_GetFileInfo (file, NULL);
-#else
-void ir_select_add (int fd, void *obj)
-{
-#endif
- callback_table[fd].obj = obj;
- callback_table[fd].r_handle = ir_select_read;
- callback_table[fd].w_handle = NULL;
- callback_table[fd].x_handle = NULL;
- if (fd > 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;
-}