home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / server / xinput / xgetdctl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-24  |  5.3 KB  |  202 lines

  1. /* $XConsortium: xgetdctl.c,v 1.1 91/07/24 15:50:52 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.  *  Get Device control attributes for an extension device.
  30.  *
  31.  */
  32.  
  33. #define     NEED_EVENTS            /* for inputstr.h    */
  34. #define     NEED_REPLIES
  35. #include "X.h"                /* for inputstr.h    */
  36. #include "Xproto.h"            /* Request macro     */
  37. #include "inputstr.h"            /* DeviceIntPtr         */
  38. #include "XI.h"
  39. #include "XIproto.h"
  40.  
  41. extern    int     IReqCode;
  42. extern    int    BadDevice;
  43. extern    void    (* ReplySwapVector[256]) ();
  44. DeviceIntPtr    LookupDeviceIntRec();
  45. void        CopySwapDeviceResolution();
  46.  
  47. /***********************************************************************
  48.  *
  49.  * This procedure gets the control attributes for an extension device,
  50.  * for clients on machines with a different byte ordering than the server.
  51.  *
  52.  */
  53.  
  54. int
  55. SProcXGetDeviceControl(client)
  56.     register ClientPtr client;
  57.     {
  58.     register char n;
  59.  
  60.     REQUEST(xGetDeviceControlReq);
  61.     swaps(&stuff->length, n);
  62.     swaps(&stuff->control, n);
  63.     return(ProcXGetDeviceControl(client));
  64.     }
  65.  
  66. /***********************************************************************
  67.  *
  68.  * Get the state of the specified device control.
  69.  *
  70.  */
  71.  
  72. ProcXGetDeviceControl(client)
  73.     ClientPtr client;
  74.     {
  75.     int    total_length = 0;
  76.     char *buf, *savbuf;
  77.     register DeviceIntPtr dev;
  78.     xGetDeviceControlReply rep;
  79.  
  80.     REQUEST(xGetDeviceControlReq);
  81.     REQUEST_SIZE_MATCH(xGetDeviceControlReq);
  82.  
  83.     dev = LookupDeviceIntRec (stuff->deviceid);
  84.     if (dev == NULL)
  85.     {
  86.     SendErrorToClient (client, IReqCode, X_GetDeviceControl, 0, 
  87.         BadDevice);
  88.     return Success;
  89.     }
  90.  
  91.     rep.repType = X_Reply;
  92.     rep.RepType = X_GetDeviceControl;
  93.     rep.length = 0;
  94.     rep.sequenceNumber = client->sequence;
  95.  
  96.     switch (stuff->control)
  97.     {
  98.     case DEVICE_RESOLUTION:
  99.         if (!dev->valuator)
  100.         {
  101.         SendErrorToClient (client, IReqCode, X_GetDeviceControl, 0, 
  102.             BadMatch);
  103.         return Success;
  104.         }
  105.         total_length = sizeof (xDeviceResolutionState) +
  106.         (3 * sizeof(int) * dev->valuator->numAxes);
  107.         break;
  108.     default:
  109.         SendErrorToClient (client, IReqCode, X_GetDeviceControl, 0, 
  110.         BadValue);
  111.         return Success;
  112.     }
  113.  
  114.     buf = (char *) Xalloc (total_length);
  115.     if (!buf)
  116.     {
  117.     SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, 
  118.         BadAlloc);
  119.     return Success;
  120.     }
  121.     savbuf=buf;
  122.  
  123.     switch (stuff->control)
  124.     {
  125.     case DEVICE_RESOLUTION:
  126.         CopySwapDeviceResolution(client, dev->valuator, buf,
  127.         total_length);
  128.         break;
  129.     default:
  130.         break;
  131.     }
  132.  
  133.     rep.length = (total_length+3) >> 2;
  134.     WriteReplyToClient(client, sizeof(xGetDeviceControlReply), &rep);
  135.     WriteToClient(client, total_length, savbuf);
  136.     Xfree (savbuf);
  137.     return Success;
  138.     }
  139.  
  140. /***********************************************************************
  141.  *
  142.  * This procedure copies DeviceResolution data, swapping if necessary.
  143.  *
  144.  */
  145.  
  146. void
  147. CopySwapDeviceResolution (client, v, buf, length)
  148.     ClientPtr         client;
  149.     ValuatorClassPtr    v;
  150.     char         *buf;
  151.     int            length;
  152.     {
  153.     register char     n;
  154.     AxisInfoPtr    a;
  155.     xDeviceResolutionState *r;
  156.     int i, *iptr;
  157.  
  158.     r = (xDeviceResolutionState *) buf;
  159.     r->control = DEVICE_RESOLUTION;
  160.     r->length =  length;
  161.     r->num_valuators =  v->numAxes;
  162.     buf += sizeof (xDeviceResolutionState);
  163.     iptr = (int *) buf;
  164.     for (i=0,a=v->axes; i<v->numAxes; i++,a++)
  165.     *iptr++ = a->resolution;
  166.     for (i=0,a=v->axes; i<v->numAxes; i++,a++)
  167.     *iptr++ = a->min_resolution;
  168.     for (i=0,a=v->axes; i<v->numAxes; i++,a++)
  169.     *iptr++ = a->max_resolution;
  170.     if (client->swapped)
  171.     {
  172.     swaps (&r->control,n);
  173.     swaps (&r->length,n);
  174.     swapl (&r->num_valuators,n);
  175.     iptr = (int *) buf;
  176.     for (i=0; i < (3 * v->numAxes); i++,iptr++)
  177.         {
  178.         swapl (iptr,n);
  179.         }
  180.     }
  181.     }
  182.  
  183. /***********************************************************************
  184.  *
  185.  * This procedure writes the reply for the xGetDeviceControl function,
  186.  * if the client and server have a different byte ordering.
  187.  *
  188.  */
  189.  
  190. SRepXGetDeviceControl (client, size, rep)
  191.     ClientPtr    client;
  192.     int        size;
  193.     xGetDeviceControlReply    *rep;
  194.     {
  195.     register char n;
  196.  
  197.     swaps(&rep->sequenceNumber, n);
  198.     swapl(&rep->length, n);
  199.     WriteToClient(client, size, rep);
  200.     }
  201.  
  202.