home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xtrapv33.zip / extensions / lib / xtrap / XEDsptch.c < prev    next >
C/C++ Source or Header  |  1992-09-14  |  4KB  |  126 lines

  1. /*****************************************************************************
  2. Copyright 1987, 1988, 1989, 1990, 1991 by Digital Equipment Corp., Maynard, MA
  3.  
  4. Permission to use, copy, modify, and distribute this software and its 
  5. documentation for any purpose and without fee is hereby granted, 
  6. provided that the above copyright notice appear in all copies and that
  7. both that copyright notice and this permission notice appear in 
  8. supporting documentation, and that the name of Digital not be
  9. used in advertising or publicity pertaining to distribution of the
  10. software without specific, written prior permission.  
  11.  
  12. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  13. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  14. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  15. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  16. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  17. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  18. SOFTWARE.
  19.  
  20. *****************************************************************************/
  21. /*
  22.  *
  23.  *  CONTRIBUTORS:
  24.  *
  25.  *      Dick Annicchiarico
  26.  *      Robert Chesler
  27.  *      Dan Coutu
  28.  *      Gene Durso
  29.  *      Marc Evans
  30.  *      Alan Jamison
  31.  *      Mark Henry
  32.  *      Ken Miller
  33.  *
  34.  */
  35. #ifndef lint
  36. static char SCCSID[] = "@(#)XETrapDispatch.c    1.18 - 90/11/12  ";
  37. static char RCSID[] = "$Header$";
  38. #endif
  39.  
  40. #include <stdio.h>
  41. #include <errno.h>
  42. #include "xtraplib.h"
  43. #include "xtraplibp.h"
  44.  
  45. #ifdef FUNCTION_PROTOS
  46. static void XETrapDispatchCB(XETC *tc, XETrapDatum *pdatum)
  47. #else
  48. static void XETrapDispatchCB(tc, pdatum)
  49.     XETC *tc;
  50.     XETrapDatum *pdatum;
  51. #endif
  52. {
  53.     void_function pfunc = NULL;
  54.     BYTE *userp = NULL;
  55.  
  56.     /* Need to deal with Delta Timestamps here before calling client CB */
  57.     if (XETrapGetTCFlagDeltaTimes(tc))
  58.     {
  59.         CARD32 last_time = XETrapGetTCTime(tc);
  60.         if (XETrapHeaderIsEvent(&pdatum->hdr))
  61.         {   /* then we can play with the timestamps */
  62.             pdatum->hdr.timestamp = 
  63.                 pdatum->u.event.u.keyButtonPointer.time;
  64.         }
  65.         else
  66.         {   /* 
  67.              * the current one from GetTimeInMillis is worthless
  68.              * as it's only updated during event instances (e.g. not
  69.              * wall clock).
  70.              */
  71.             pdatum->hdr.timestamp = last_time;
  72.         }
  73.         if (!pdatum->hdr.timestamp)
  74.         {   /* for dual monitor bug */
  75.             pdatum->hdr.timestamp = last_time;
  76.         }
  77.         if (!last_time)
  78.         {   /* first one!  Prime it! */
  79.             last_time = pdatum->hdr.timestamp;
  80.         }
  81.         tc->values.last_time = pdatum->hdr.timestamp;   /* no macro! */
  82.         if (pdatum->hdr.timestamp < last_time)
  83.         {   /* for clock rollover */
  84.             pdatum->hdr.timestamp = 0;
  85.         }
  86.         else
  87.         {   /* the real delta */
  88.             pdatum->hdr.timestamp = pdatum->hdr.timestamp - last_time;
  89.         }
  90.     }
  91.     /*  Get the user supplied callback function */
  92.     if (XETrapHeaderIsEvent(&pdatum->hdr))
  93.     {
  94.         pfunc = tc->values.evt_cb[pdatum->u.event.u.u.type].func;
  95.         userp = tc->values.evt_cb[pdatum->u.event.u.u.type].data;
  96.     }
  97.     else if (XETrapHeaderIsRequest(&pdatum->hdr) ||
  98.         XETrapHeaderIsReply(&pdatum->hdr))
  99.     {
  100.         pfunc = tc->values.req_cb[pdatum->u.req.reqType].func;
  101.         userp = tc->values.req_cb[pdatum->u.req.reqType].data;
  102.     }
  103.  
  104.     /* If there is a callback then call it with the data */
  105.     if (pfunc != NULL)
  106.     { 
  107.         (*pfunc)(tc,pdatum,userp); 
  108.     }
  109. }
  110.  
  111. #ifdef FUNCTION_PROTOS
  112. void XETrapDispatchXLib(XETrapDataEvent *event, XETC *tc)
  113. #else
  114. void XETrapDispatchXLib(event, tc)
  115.     XETrapDataEvent *event;
  116.     XETC   *tc;
  117. #endif
  118. {   
  119.     memcpy(&tc->xbuff[event->idx*sz_EventData], event->data, sz_EventData);
  120.  
  121.     if (event->detail == XETrapDataLast)
  122.     {
  123.         XETrapDispatchCB(tc, (XETrapDatum *)tc->xbuff);
  124.     }
  125. }
  126.