home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / server / xinput / xsendexev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-18  |  4.4 KB  |  151 lines

  1. /* $XConsortium: xsendexev.c,v 1.7 90/05/18 11:32:30 rws Exp $ */
  2.  
  3. /************************************************************
  4. Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, California, and the 
  5. Massachusetts Institute of Technology, Cambridge, Massachusetts.
  6.  
  7.             All Rights Reserved
  8.  
  9. Permission to use, copy, modify, and distribute this software and its
  10. documentation for any purpose and without fee is hereby granted,
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in
  13. supporting documentation, and that the names of Hewlett-Packard or MIT not be
  14. used in advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.
  16.  
  17. HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  19. HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ********************************************************/
  26.  
  27. /***********************************************************************
  28.  *
  29.  * Request to send an extension event.
  30.  *
  31.  */
  32.  
  33. #define EXTENSION_EVENT_BASE  64
  34. #define     NEED_EVENTS
  35. #define     NEED_REPLIES
  36. #include "X.h"                /* for inputstr.h    */
  37. #include "Xproto.h"            /* Request macro     */
  38. #include "inputstr.h"            /* DeviceIntPtr         */
  39. #include "windowstr.h"            /* Window               */
  40. #include "XI.h"
  41. #include "XIproto.h"
  42.  
  43. extern    int         IReqCode;
  44. extern    int         BadDevice;
  45. extern    void        (* ReplySwapVector[256]) ();
  46. extern    void        (* EventSwapVector[128]) ();
  47. DeviceIntPtr        LookupDeviceIntRec();
  48.  
  49. /***********************************************************************
  50.  *
  51.  * Handle requests from clients with a different byte order than us.
  52.  *
  53.  */
  54.  
  55. int
  56. SProcXSendExtensionEvent(client)
  57.     register ClientPtr client;
  58.     {
  59.     register char n;
  60.     register long *p;
  61.     register int i;
  62.     xEvent eventT;
  63.     xEvent *eventP;
  64.     void (*proc)(), NotImplemented();
  65.  
  66.     REQUEST(xSendExtensionEventReq);
  67.     swaps(&stuff->length, n);
  68.     swapl(&stuff->destination, n);
  69.     swaps(&stuff->count, n);
  70.     eventP = (xEvent *) &stuff[1];
  71.     for (i=0; i<stuff->num_events; i++,eventP++)
  72.         {
  73.     proc = EventSwapVector[eventP->u.u.type & 0177];
  74.      if (proc == NotImplemented)   /* no swapping proc; invalid event type? */
  75.         return (BadValue);
  76.     (*proc)(eventP, &eventT);
  77.     *eventP = eventT;
  78.     }
  79.  
  80.     p = (long *) (((xEvent *) &stuff[1]) + stuff->num_events);
  81.     for (i=0; i<stuff->count; i++)
  82.         {
  83.         swapl(p, n);
  84.     p++;
  85.         }
  86.     return(ProcXSendExtensionEvent(client));
  87.     }
  88.  
  89. /***********************************************************************
  90.  *
  91.  * Send an event to some client, as if it had come from an extension input 
  92.  * device.
  93.  *
  94.  */
  95.  
  96. ProcXSendExtensionEvent (client)
  97.     register ClientPtr client;
  98.     {
  99.     int            ret;
  100.     extern int         lastEvent;         /* Defined in extension.c */
  101.     DeviceIntPtr    dev;
  102.     xEvent        *first;
  103.     XEventClass        *list;
  104.     struct tmask    tmp[EMASKSIZE];
  105.  
  106.     REQUEST(xSendExtensionEventReq);
  107.     REQUEST_AT_LEAST_SIZE(xSendExtensionEventReq);
  108.  
  109.     if (stuff->length !=(sizeof(xSendExtensionEventReq)>>2) + stuff->count +
  110.     (stuff->num_events * (sizeof (xEvent) >> 2)))
  111.     {
  112.     SendErrorToClient (client, IReqCode, X_SendExtensionEvent, 0, 
  113.         BadLength);
  114.     return Success;
  115.     }
  116.  
  117.     dev = LookupDeviceIntRec (stuff->deviceid);
  118.     if (dev == NULL)
  119.     {
  120.     SendErrorToClient(client, IReqCode, X_SendExtensionEvent, 0, 
  121.         BadDevice);
  122.     return Success;
  123.     }
  124.  
  125.     /* The client's event type must be one defined by an extension. */
  126.  
  127.     first = ((xEvent *) &stuff[1]);
  128.     if ( ! ((EXTENSION_EVENT_BASE  <= first->u.u.type) &&
  129.     (first->u.u.type < lastEvent)) )
  130.     {
  131.     client->errorValue = first->u.u.type;
  132.     SendErrorToClient(client, IReqCode, X_SendExtensionEvent, 0, 
  133.         BadValue);
  134.     return Success;
  135.     }
  136.  
  137.     list = (XEventClass *) (first + stuff->num_events);
  138.     if ((ret = CreateMaskFromList (client, list, stuff->count, tmp, dev, 
  139.     X_SendExtensionEvent)) != Success)
  140.     return Success;
  141.  
  142.     ret =  (SendEvent (client, dev, stuff->destination,
  143.     stuff->propagate, &stuff[1], tmp[stuff->deviceid].mask, 
  144.     stuff->num_events));
  145.  
  146.     if (ret != Success)
  147.     SendErrorToClient(client, IReqCode, X_SendExtensionEvent, 0, ret);
  148.  
  149.     return Success;
  150.     }
  151.