home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / server / xinput / xgetfctl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-14  |  10.3 KB  |  400 lines

  1. /* $Header: xgetfctl.c,v 1.13 91/05/14 12:21:12 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 feedback 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        CopySwapKbdFeedback();
  46. void        CopySwapPtrFeedback();
  47. void        CopySwapIntegerFeedback();
  48. void        CopySwapStringFeedback();
  49. void        CopySwapLedFeedback();
  50. void        CopySwapBellFeedback();
  51.  
  52. /***********************************************************************
  53.  *
  54.  * This procedure gets the control attributes for an extension device,
  55.  * for clients on machines with a different byte ordering than the server.
  56.  *
  57.  */
  58.  
  59. int
  60. SProcXGetFeedbackControl(client)
  61.     register ClientPtr client;
  62.     {
  63.     register char n;
  64.  
  65.     REQUEST(xGetFeedbackControlReq);
  66.     swaps(&stuff->length, n);
  67.     return(ProcXGetFeedbackControl(client));
  68.     }
  69.  
  70. /***********************************************************************
  71.  *
  72.  * Get the feedback control state.
  73.  *
  74.  */
  75.  
  76. ProcXGetFeedbackControl(client)
  77.     ClientPtr client;
  78.     {
  79.     int    total_length = 0;
  80.     char *buf, *savbuf;
  81.     register DeviceIntPtr dev;
  82.     KbdFeedbackPtr k;
  83.     PtrFeedbackPtr p;
  84.     IntegerFeedbackPtr i;
  85.     StringFeedbackPtr s;
  86.     BellFeedbackPtr b;
  87.     LedFeedbackPtr l;
  88.     xGetFeedbackControlReply rep;
  89.  
  90.     REQUEST(xGetFeedbackControlReq);
  91.     REQUEST_SIZE_MATCH(xGetFeedbackControlReq);
  92.  
  93.     dev = LookupDeviceIntRec (stuff->deviceid);
  94.     if (dev == NULL)
  95.     {
  96.     SendErrorToClient (client, IReqCode, X_GetFeedbackControl, 0, 
  97.         BadDevice);
  98.     return Success;
  99.     }
  100.  
  101.     rep.repType = X_Reply;
  102.     rep.RepType = X_GetFeedbackControl;
  103.     rep.length = 0;
  104.     rep.sequenceNumber = client->sequence;
  105.     rep.num_feedbacks = 0;
  106.  
  107.     for (k=dev->kbdfeed; k; k=k->next)
  108.     {
  109.     rep.num_feedbacks++;
  110.     total_length += sizeof(xKbdFeedbackState);
  111.     }
  112.     for (p=dev->ptrfeed; p; p=p->next)
  113.     {
  114.     rep.num_feedbacks++;
  115.     total_length += sizeof(xPtrFeedbackState);
  116.     }
  117.     for (s=dev->stringfeed; s; s=s->next)
  118.     {
  119.     rep.num_feedbacks++;
  120.     total_length += sizeof(xStringFeedbackState) + 
  121.         (s->ctrl.num_symbols_supported * sizeof (KeySym));
  122.     }
  123.     for (i=dev->intfeed; i; i=i->next)
  124.     {
  125.     rep.num_feedbacks++;
  126.     total_length += sizeof(xIntegerFeedbackState);
  127.     }
  128.     for (l=dev->leds; l; l=l->next)
  129.     {
  130.     rep.num_feedbacks++;
  131.     total_length += sizeof(xLedFeedbackState);
  132.     }
  133.     for (b=dev->bell; b; b=b->next)
  134.     {
  135.     rep.num_feedbacks++;
  136.     total_length += sizeof(xBellFeedbackState);
  137.     }
  138.  
  139.     if (total_length == 0)
  140.     {
  141.     SendErrorToClient(client, IReqCode, X_GetFeedbackControl, 0, 
  142.         BadMatch);
  143.     return Success;
  144.     }
  145.  
  146.     buf = (char *) Xalloc (total_length);
  147.     if (!buf)
  148.     {
  149.     SendErrorToClient(client, IReqCode, X_GetFeedbackControl, 0, 
  150.         BadAlloc);
  151.     return Success;
  152.     }
  153.     savbuf=buf;
  154.  
  155.     for (k=dev->kbdfeed; k; k=k->next)
  156.     CopySwapKbdFeedback (client, k, &buf);
  157.     for (p=dev->ptrfeed; p; p=p->next)
  158.     CopySwapPtrFeedback (client, p, &buf);
  159.     for (s=dev->stringfeed; s; s=s->next)
  160.     CopySwapStringFeedback (client, s, &buf);
  161.     for (i=dev->intfeed; i; i=i->next)
  162.     CopySwapIntegerFeedback (client, i, &buf);
  163.     for (l=dev->leds; l; l=l->next)
  164.     CopySwapLedFeedback (client, l, &buf);
  165.     for (b=dev->bell; b; b=b->next)
  166.     CopySwapBellFeedback (client, b, &buf);
  167.  
  168.     rep.length = (total_length+3) >> 2;
  169.     WriteReplyToClient(client, sizeof(xGetFeedbackControlReply), &rep);
  170.     WriteToClient(client, total_length, savbuf);
  171.     Xfree (savbuf);
  172.     return Success;
  173.     }
  174.  
  175. /***********************************************************************
  176.  *
  177.  * This procedure copies KbdFeedbackClass data, swapping if necessary.
  178.  *
  179.  */
  180.  
  181. void
  182. CopySwapKbdFeedback (client, k, buf)
  183.     ClientPtr         client;
  184.     KbdFeedbackPtr     k;
  185.     char         **buf;
  186.     {
  187.     int    i;
  188.     register char     n;
  189.     xKbdFeedbackState    *k2;
  190.  
  191.     k2 = (xKbdFeedbackState *) *buf;
  192.     k2->class = KbdFeedbackClass;
  193.     k2->length = sizeof (xKbdFeedbackState);
  194.     k2->id = k->ctrl.id;
  195.     k2->click = k->ctrl.click;
  196.     k2->percent = k->ctrl.bell;
  197.     k2->pitch = k->ctrl.bell_pitch;
  198.     k2->duration = k->ctrl.bell_duration;
  199.     k2->led_mask = k->ctrl.leds;
  200.     k2->global_auto_repeat = k->ctrl.autoRepeat;
  201.     for (i=0; i<32; i++)
  202.     k2->auto_repeats[i] = k->ctrl.autoRepeats[i];
  203.     if (client->swapped)
  204.     {
  205.     swaps(&k2->length,n);
  206.     swaps(&k2->pitch,n);
  207.     swaps(&k2->duration,n);
  208.     swapl(&k2->led_mask,n);
  209.     swapl(&k2->led_values,n);
  210.     }
  211.     *buf += sizeof (xKbdFeedbackState);
  212.     }
  213.  
  214. /***********************************************************************
  215.  *
  216.  * This procedure copies PtrFeedbackClass data, swapping if necessary.
  217.  *
  218.  */
  219.  
  220. void
  221. CopySwapPtrFeedback (client, p, buf)
  222.     ClientPtr         client;
  223.     PtrFeedbackPtr     p;
  224.     char         **buf;
  225.     {
  226.     register char     n;
  227.     xPtrFeedbackState    *p2;
  228.  
  229.     p2 = (xPtrFeedbackState *) *buf;
  230.     p2->class = PtrFeedbackClass;
  231.     p2->length = sizeof (xPtrFeedbackState);
  232.     p2->id = p->ctrl.id;
  233.     p2->accelNum = p->ctrl.num;
  234.     p2->accelDenom = p->ctrl.den;
  235.     p2->threshold = p->ctrl.threshold;
  236.     if (client->swapped)
  237.     {
  238.     swaps(&p2->length,n);
  239.     swaps(&p2->accelNum,n);
  240.     swaps(&p2->accelDenom,n);
  241.     swaps(&p2->threshold,n);
  242.     }
  243.     *buf += sizeof (xPtrFeedbackState);
  244.     }
  245.  
  246. /***********************************************************************
  247.  *
  248.  * This procedure copies IntegerFeedbackClass data, swapping if necessary.
  249.  *
  250.  */
  251.  
  252. void
  253. CopySwapIntegerFeedback (client, i, buf)
  254.     ClientPtr         client;
  255.     IntegerFeedbackPtr     i;
  256.     char         **buf;
  257.     {
  258.     register char         n;
  259.     xIntegerFeedbackState    *i2;
  260.  
  261.     i2 = (xIntegerFeedbackState *) *buf;
  262.     i2->class = IntegerFeedbackClass;
  263.     i2->length = sizeof (xIntegerFeedbackState);
  264.     i2->id = i->ctrl.id;
  265.     i2->resolution = i->ctrl.resolution;
  266.     i2->min_value = i->ctrl.min_value;
  267.     i2->max_value = i->ctrl.max_value;
  268.     if (client->swapped)
  269.     {
  270.     swaps(&i2->length,n);
  271.     swapl(&i2->resolution,n);
  272.     swapl(&i2->min_value,n);
  273.     swapl(&i2->max_value,n);
  274.     }
  275.     *buf += sizeof (xIntegerFeedbackState);
  276.     }
  277.  
  278. /***********************************************************************
  279.  *
  280.  * This procedure copies StringFeedbackClass data, swapping if necessary.
  281.  *
  282.  */
  283.  
  284. void
  285. CopySwapStringFeedback (client, s, buf)
  286.     ClientPtr         client;
  287.     StringFeedbackPtr     s;
  288.     char         **buf;
  289.     {
  290.     int i;
  291.     register char         n;
  292.     xStringFeedbackState    *s2;
  293.     KeySym            *kptr;
  294.  
  295.     s2 = (xStringFeedbackState *) *buf;
  296.     s2->class = StringFeedbackClass;
  297.     s2->length = sizeof (xStringFeedbackState) + 
  298.         s->ctrl.num_symbols_supported * sizeof (KeySym);
  299.     s2->id = s->ctrl.id;
  300.     s2->max_symbols = s->ctrl.max_symbols;
  301.     s2->num_syms_supported = s->ctrl.num_symbols_supported;
  302.     *buf += sizeof (xStringFeedbackState);
  303.     kptr = (KeySym *) (*buf);
  304.     for (i=0; i<s->ctrl.num_symbols_supported; i++)
  305.     *kptr++ = *(s->ctrl.symbols_supported+i);
  306.     if (client->swapped)
  307.     {
  308.     swaps(&s2->length,n);
  309.     swaps(&s2->max_symbols,n);
  310.     swaps(&s2->num_syms_supported,n);
  311.         kptr = (KeySym *) (*buf);
  312.     for (i=0; i<s->ctrl.num_symbols_supported; i++,kptr++)
  313.         {
  314.         swapl(kptr,n);
  315.         }
  316.     }
  317.     *buf += (s->ctrl.num_symbols_supported * sizeof (KeySym));
  318.     }
  319.  
  320. /***********************************************************************
  321.  *
  322.  * This procedure copies LedFeedbackClass data, swapping if necessary.
  323.  *
  324.  */
  325.  
  326. void
  327. CopySwapLedFeedback (client, l, buf)
  328.     ClientPtr         client;
  329.     LedFeedbackPtr     l;
  330.     char         **buf;
  331.     {
  332.     register char     n;
  333.     xLedFeedbackState    *l2;
  334.  
  335.     l2 = (xLedFeedbackState *) *buf;
  336.     l2->class = LedFeedbackClass;
  337.     l2->length = sizeof (xLedFeedbackState);
  338.     l2->id = l->ctrl.id;
  339.     l2->led_values = l->ctrl.led_values;
  340.     l2->led_mask = l->ctrl.led_mask;
  341.     if (client->swapped)
  342.     {
  343.     swaps(&l2->length,n);
  344.     swapl(&l2->led_values,n);
  345.     swapl(&l2->led_mask,n);
  346.     }
  347.     *buf += sizeof (xLedFeedbackState);
  348.     }
  349.  
  350. /***********************************************************************
  351.  *
  352.  * This procedure copies BellFeedbackClass data, swapping if necessary.
  353.  *
  354.  */
  355.  
  356. void
  357. CopySwapBellFeedback (client, b, buf)
  358.     ClientPtr         client;
  359.     BellFeedbackPtr     b;
  360.     char         **buf;
  361.     {
  362.     register char     n;
  363.     xBellFeedbackState    *b2;
  364.  
  365.     b2 = (xBellFeedbackState *) *buf;
  366.     b2->class = BellFeedbackClass;
  367.     b2->length = sizeof (xBellFeedbackState);
  368.     b2->id = b->ctrl.id;
  369.     b2->percent = b->ctrl.percent;
  370.     b2->pitch = b->ctrl.pitch;
  371.     b2->duration = b->ctrl.duration;
  372.     if (client->swapped)
  373.     {
  374.     swaps(&b2->length,n);
  375.     swaps(&b2->pitch,n);
  376.     swaps(&b2->duration,n);
  377.     }
  378.     *buf += sizeof (xBellFeedbackState);
  379.     }
  380.  
  381. /***********************************************************************
  382.  *
  383.  * This procedure writes the reply for the xGetFeedbackControl function,
  384.  * if the client and server have a different byte ordering.
  385.  *
  386.  */
  387.  
  388. SRepXGetFeedbackControl (client, size, rep)
  389.     ClientPtr    client;
  390.     int        size;
  391.     xGetFeedbackControlReply    *rep;
  392.     {
  393.     register char n;
  394.  
  395.     swaps(&rep->sequenceNumber, n);
  396.     swapl(&rep->length, n);
  397.     swaps(&rep->num_feedbacks, n);
  398.     WriteToClient(client, size, rep);
  399.     }
  400.