home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / omron / omronIo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-29  |  5.7 KB  |  259 lines

  1. /*
  2.  * $XConsortium: omronIo.c,v 1.1 91/06/29 13:48:58 xguest Exp $
  3.  *
  4.  * Copyright 1991 by OMRON Corporation
  5.  * 
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of OMRON not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  OMRON makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * OMRON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL OMRON
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23.  
  24. #include "omron.h"
  25. #include "omronKbd.h"
  26. #include "omronMouse.h"
  27.  
  28. int lastEventTime = 0;
  29.  
  30. static void (* omronIoHandler)(); 
  31.  
  32. void
  33. omronSetIoHandler( ioHandler )
  34. void (* ioHandler)(); 
  35. {
  36.     omronIoHandler = ioHandler;
  37. }
  38.  
  39.  
  40. #ifdef UNUSE_SIGIO_SIGNAL
  41. void
  42. omronWakeupProc(blockData, result, pReadmask)
  43. pointer blockData;
  44. unsigned long   result;
  45. pointer pReadmask;
  46. {
  47.     long devicesReadable[mskcnt];
  48.  
  49.     if(result <= 0) return;
  50.  
  51.     MASKANDSETBITS(devicesReadable, LastSelectMask, EnabledDevices);
  52.  
  53.     if(ANYSET(devicesReadable)) {
  54.         (* omronIoHandler)();
  55.     }
  56. }
  57. #else
  58. void
  59. omronSigIOHandler(sig, code, scp)
  60. int     code;
  61. int     sig;
  62. struct sigcontext *scp;
  63. {
  64.     (* omronIoHandler)();
  65. }
  66. #endif
  67.  
  68. #ifndef UNUSE_DRV_TIME
  69. static struct _omronEventPrvRec {
  70.         DevicePtr   pMouse;
  71.         DevicePtr   pKeyboard;
  72.         Bool        mouseHasTime;
  73.         Bool        keyHasTime;
  74. }    omronEventPrv;
  75.  
  76. void
  77. omronInitEventPrvRec()
  78. {
  79.     omronEventPrv.pMouse        = NULL;
  80.     omronEventPrv.pKeyboard    = NULL;
  81.     omronEventPrv.mouseHasTime = FALSE;
  82.     omronEventPrv.keyHasTime   = FALSE;
  83. }
  84.  
  85. void
  86. omronSetDriverTimeMode(pMouse, pKeyboard)
  87. DevicePtr   pMouse;
  88. DevicePtr   pKeyboard;
  89. {
  90.     omronKeyPrvPtr kPrv;
  91.     omronMousePrvPtr  mPrv;
  92.  
  93.     if(pMouse) {
  94.         omronEventPrv.pMouse = pMouse;
  95.         mPrv = (omronMousePrvPtr)(pMouse->devicePrivate);
  96.         if(ioctl(mPrv->fd, MSTIME,1) < 0) {
  97.             if ( errno != EINVAL ) {
  98.                 Error("mouse ioctl MSTIME fault.");
  99.             }
  100.             if(omronEventPrv.pKeyboard != NULL) {
  101.                 kPrv = (omronKeyPrvPtr)(omronEventPrv.pKeyboard->devicePrivate);
  102.                 if(ioctl(kPrv->fd, KBTIME,0) < 0) {
  103.                     if ( errno != EINVAL ) {
  104.                         Error("kbd ioctl KBTIME fault.");
  105.                     }
  106.                 }
  107.             }
  108.             omronEventPrv.keyHasTime = FALSE;
  109.         } else {
  110.             omronEventPrv.mouseHasTime = TRUE;
  111.         }
  112.     } else if(pKeyboard) {
  113.         omronEventPrv.pKeyboard = pKeyboard;
  114.         kPrv = (omronKeyPrvPtr)(pKeyboard->devicePrivate);
  115.         if(ioctl(kPrv->fd, KBTIME,1) < 0) {
  116.             if ( errno != EINVAL ) {
  117.                 Error("mouse ioctl KBTIME fault.");
  118.             }
  119.             if(omronEventPrv.pMouse != NULL) {
  120.                 mPrv = (omronMousePrvPtr)(omronEventPrv.pMouse->devicePrivate);
  121.                 if(ioctl(mPrv->fd, MSTIME,0) < 0) {
  122.                     if ( errno == EINVAL ) {
  123.                         Error("kbd ioctl MSTIME fault.");
  124.                     }
  125.                 }
  126.             }
  127.             omronEventPrv.mouseHasTime = FALSE;
  128.         } else {
  129.             omronEventPrv.keyHasTime = TRUE;
  130.         }
  131.     }
  132.  
  133.     if((omronEventPrv.keyHasTime == TRUE) &&
  134.        (omronEventPrv.mouseHasTime == TRUE)) {
  135.         omronSetIoHandler(omronEnqueueTEvents); 
  136.     } else {
  137.         omronSetIoHandler(omronEnqueueEvents); 
  138.     }
  139. }
  140. #endif
  141.  
  142.  
  143. void
  144. ProcessInputEvents()
  145. {
  146.     mieqProcessInputEvents();
  147.     miPointerUpdate();
  148. }
  149.  
  150.  
  151. int
  152. TimeSinceLastInputEvent()
  153. {
  154.     long now;
  155.     
  156.     now = GetTimeInMillis();
  157.  
  158.     if (lastEventTime == 0) {
  159.         lastEventTime = now;
  160.     }
  161.     return(now - lastEventTime);
  162. }
  163.  
  164.  
  165. void
  166. omronSetLastEventTime()
  167. {
  168.     lastEventTime = GetTimeInMillis();
  169. }
  170.  
  171.  
  172. void
  173. omronEnqueueEvents()
  174. {
  175.     DevicePtr         pPtr;
  176.     DevicePtr         pKbd;
  177.     struct msdata     *ptrEvents;    
  178.     unsigned char     *KbdEvents;
  179.     int         nk, np;
  180.     Bool         ptrRetry, kbdRetry;            
  181.     
  182.     pPtr = LookupPointerDevice();
  183.     pKbd = LookupKeyboardDevice();
  184.  
  185.     if (!pPtr->on || !pKbd->on)
  186.         return;
  187.  
  188.     kbdRetry = TRUE;
  189.     while( kbdRetry ) {
  190.         KbdEvents = omronKbdGetEvents(pKbd, &nk, &kbdRetry);     
  191.         while(nk--) {
  192.             omronKbdEnqueueEvent(pKbd, KbdEvents++);
  193.         }
  194.     }
  195.  
  196.     ptrRetry = TRUE;
  197.     while( ptrRetry ) {
  198.         ptrEvents = omronMouseGetEvents(pPtr, &np, &ptrRetry);     
  199.         while(np--) {
  200.             omronMouseEnqueueEvent(pPtr, ptrEvents++);
  201.         }
  202.     }
  203. }
  204.  
  205.  
  206. #ifndef UNUSE_DRV_TIME
  207. void
  208. omronEnqueueTEvents()
  209. {
  210.     DevicePtr       pPtr;
  211.     DevicePtr       pKbd;
  212.     struct msdatat     *ptrEvents = (struct msdatat *) NULL;    
  213.     key_event     *kbdEvents = (key_event *) NULL;
  214.     register int    nPtrEvent, nKbdEvent;
  215.     int        np, nk;
  216.     Bool        ptrRetry, kbdRetry;            
  217.  
  218.     pKbd = LookupKeyboardDevice();
  219.     pPtr = LookupPointerDevice();
  220.     if(!pPtr->on || !pKbd->on)
  221.         return;
  222.  
  223.     nPtrEvent = nKbdEvent = 0;
  224.     ptrRetry = kbdRetry = TRUE;
  225.  
  226.     while (1) {
  227.         if((nPtrEvent == 0) && ptrRetry) {
  228.             ptrEvents = omronMouseGetTEvents(pPtr, &np, &ptrRetry);
  229.             nPtrEvent = np;
  230.         }
  231.         if((nKbdEvent == 0) && kbdRetry) {
  232.             kbdEvents = omronKbdGetTEvents(pKbd, &nk, &kbdRetry);     
  233.             nKbdEvent = nk;
  234.         }
  235.         if((nKbdEvent == 0) && (nPtrEvent == 0))
  236.             break;
  237.         if(nPtrEvent && nKbdEvent) {
  238.             if ( ptrEvents->time < kbdEvents->time )  {
  239.                 omronMouseEnqueueTEvent(pPtr, ptrEvents);
  240.                 lastEventTime = ptrEvents++->time;
  241.                 nPtrEvent--;
  242.             } else {
  243.                 omronKbdEnqueueTEvent(pKbd, kbdEvents);
  244.                 lastEventTime = kbdEvents++->time;
  245.                 nKbdEvent--;
  246.             }
  247.         } else if(nPtrEvent) {
  248.             omronMouseEnqueueTEvent(pPtr, ptrEvents);
  249.             lastEventTime = ptrEvents++->time;
  250.             nPtrEvent--;
  251.         } else {
  252.             omronKbdEnqueueTEvent(pKbd, kbdEvents);
  253.             lastEventTime = kbdEvents++->time;
  254.             nKbdEvent--;
  255.         }
  256.     }
  257. }
  258. #endif
  259.