Modified to use ir_tcl_select_set.
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 21 Feb 1996 14:58:01 +0000 (14:58 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 21 Feb 1996 14:58:01 +0000 (14:58 +0000)
www/wirtcl.c

index f70cbcb..942abdc 100644 (file)
  * USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  * $Log: wirtcl.c,v $
- * Revision 1.14  1996/02/12 10:10:31  adam
+ * Revision 1.15  1996/02/21 14:58:01  adam
+ * Modified to use ir_tcl_select_set.
+ *
+ * Revision 1.14  1996/02/12  10:10:31  adam
  * Resource/config system used by the gateway.
  *
  * Revision 1.13  1996/01/24  08:26:54  adam
@@ -134,7 +137,6 @@ struct tcl_info {
     WCLIENT wcl;
 };
 
-
 static int events (struct tcl_info *p, char *waitVar, int tout);
 
 static int proc_zwait_invoke (ClientData clientData, Tcl_Interp *interp,
@@ -147,14 +149,11 @@ static int proc_zwait_invoke (ClientData clientData, Tcl_Interp *interp,
     return events (p, argv[1], (argc == 3) ? atoi(argv[2]) : 0);
 }
 
-
-
-/* select(2) callbacks */
+/* select 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
 
@@ -187,11 +186,7 @@ static void *do_create (WCLIENT wcl, void *args)
     /* initialize irtcl */
     Tcl_CreateCommand (p->interp, "egw_wait", proc_zwait_invoke, p, NULL);
     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;
     return p;
 }
 
@@ -260,17 +255,17 @@ static int events (struct tcl_info *p, char *waitVar, int tout)
         
         for (r=0, i=0; 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);
                 r++;
             }
-            if (callback_table[i].r_handle)
+            if (callback_table[i].handle && callback_table[i].r)
             {
                 FD_SET (i, &fdset_tcl_r);
                 r++;
             }
-            if (callback_table[i].x_handle)
+            if (callback_table[i].handle && callback_table[i].e)
             {
                 FD_SET (i, &fdset_tcl_x);
                 r++;
@@ -302,56 +297,39 @@ static int events (struct tcl_info *p, char *waitVar, int tout)
         }
         for (i=0; 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);
         }
     }
     free (waitVarVal);
     return TCL_OK;
 }
 
-void ir_select_add (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)
 {
-    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;
+    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;
 }
 
-void ir_select_add_write (int fd, void *obj)
-{
-    callback_table[fd].w_handle = ir_select_write;
-    if (fd > max_fd)
-        max_fd = fd;
-}
-
-void ir_select_remove_write (int fd, void *obj)
-{
-    callback_table[fd].w_handle = NULL;
-}
-
-void ir_select_remove (int fd, void *obj)
-{
-    callback_table[fd].r_handle = NULL;
-    callback_table[fd].w_handle = NULL;
-    callback_table[fd].x_handle = NULL;
-}
-
 static int do_load (char *parms, void *mydata)
 {
     struct tcl_info *p = mydata;