home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / x11r6.1 / include / x11 / ice / icemsg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-17  |  8.2 KB  |  304 lines

  1. /* $XConsortium: ICEmsg.h,v 1.5 94/04/17 20:15:26 mor Exp $ */
  2. /******************************************************************************
  3.  
  4.  
  5. Copyright (c) 1993  X Consortium
  6.  
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13.  
  14. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16.  
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  20. X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  21. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23.  
  24. Except as contained in this notice, the name of the X Consortium shall not be
  25. used in advertising or otherwise to promote the sale, use or other dealings
  26. in this Software without prior written authorization from the X Consortium.
  27.  
  28. Author: Ralph Mor, X Consortium
  29. ******************************************************************************/
  30.  
  31. #ifndef _ICEMSG_H_
  32. #define _ICEMSG_H_
  33.  
  34. #include <X11/ICE/ICEconn.h>
  35.  
  36. /*
  37.  * Function prototypes for internal ICElib functions
  38.  */
  39.  
  40. extern Status _IceRead (
  41. #if NeedFunctionPrototypes
  42.     IceConn        /* iceConn */,
  43.     unsigned long    /* nbytes */,
  44.     char *        /* ptr */
  45. #endif
  46. );
  47.  
  48. extern void _IceReadSkip (
  49. #if NeedFunctionPrototypes
  50.     IceConn        /* iceConn */,
  51.     unsigned long    /* nbytes */
  52. #endif
  53. );
  54.  
  55. extern void _IceWrite (
  56. #if NeedFunctionPrototypes
  57.     IceConn        /* iceConn */,
  58.     unsigned long    /* nbytes */,
  59.     char *        /* ptr */
  60. #endif
  61. );
  62.  
  63.  
  64. extern void _IceErrorBadMinor (
  65. #if NeedFunctionPrototypes
  66.     IceConn        /* iceConn */,
  67.     int            /* majorOpcode */,
  68.     int            /* offendingMinor */,
  69.     int            /* severity */
  70. #endif
  71. );
  72.  
  73. extern void _IceErrorBadState (
  74. #if NeedFunctionPrototypes
  75.     IceConn        /* iceConn */,
  76.     int            /* majorOpcode */,
  77.     int            /* offendingMinor */,
  78.     int            /* severity */
  79. #endif
  80. );
  81.  
  82. extern void _IceErrorBadLength (
  83. #if NeedFunctionPrototypes
  84.     IceConn        /* iceConn */,
  85.     int            /* majorOpcode */,
  86.     int            /* offendingMinor */,
  87.     int            /* severity */
  88. #endif
  89. );
  90.  
  91. extern void _IceErrorBadValue (
  92. #if NeedFunctionPrototypes
  93.     IceConn        /* iceConn */,
  94.     int            /* majorOpcode */,
  95.     int            /* offendingMinor */,
  96.     int            /* offset */,
  97.     int            /* length */,
  98.     IcePointer        /* value */
  99. #endif
  100. );
  101.  
  102.  
  103. /*
  104.  * Macro to check if IO operations are valid on an ICE connection.
  105.  */
  106.  
  107. #define IceValidIO(_iceConn) _iceConn->io_ok
  108.  
  109.  
  110. /*
  111.  * Macros for writing messages.
  112.  */
  113.  
  114. #define IceGetHeader(_iceConn, _major, _minor, _headerSize, _msgType, _pMsg) \
  115.     if ((_iceConn->outbufptr + _headerSize) > _iceConn->outbufmax) \
  116.         IceFlush (_iceConn); \
  117.     _pMsg = (_msgType *) _iceConn->outbufptr; \
  118.     _pMsg->majorOpcode = _major; \
  119.     _pMsg->minorOpcode = _minor; \
  120.     _pMsg->length = (_headerSize - SIZEOF (iceMsg)) >> 3; \
  121.     _iceConn->outbufptr += _headerSize; \
  122.     _iceConn->send_sequence++
  123.  
  124. #define IceGetHeaderExtra(_iceConn, _major, _minor, _headerSize, _extra, _msgType, _pMsg, _pData) \
  125.     if ((_iceConn->outbufptr + \
  126.     _headerSize + ((_extra) << 3)) > _iceConn->outbufmax) \
  127.         IceFlush (_iceConn); \
  128.     _pMsg = (_msgType *) _iceConn->outbufptr; \
  129.     if ((_iceConn->outbufptr + \
  130.     _headerSize + ((_extra) << 3)) <= _iceConn->outbufmax) \
  131.         _pData = (char *) _pMsg + _headerSize; \
  132.     else \
  133.         _pData = NULL; \
  134.     _pMsg->majorOpcode = _major; \
  135.     _pMsg->minorOpcode = _minor; \
  136.     _pMsg->length = ((_headerSize - SIZEOF (iceMsg)) >> 3) + (_extra); \
  137.     _iceConn->outbufptr += (_headerSize + ((_extra) << 3)); \
  138.     _iceConn->send_sequence++
  139.  
  140. #define IceSimpleMessage(_iceConn, _major, _minor) \
  141. { \
  142.     iceMsg *_pMsg; \
  143.     IceGetHeader (_iceConn, _major, _minor, SIZEOF (iceMsg), iceMsg, _pMsg); \
  144. }
  145.  
  146. #define IceErrorHeader(_iceConn, _offendingMajorOpcode, _offendingMinorOpcode, _offendingSequenceNum, _severity, _errorClass, _dataLength) \
  147. { \
  148.     iceErrorMsg    *_pMsg; \
  149. \
  150.     IceGetHeader (_iceConn, _offendingMajorOpcode, ICE_Error, \
  151.     SIZEOF (iceErrorMsg), iceErrorMsg, _pMsg); \
  152.     _pMsg->length += (_dataLength); \
  153.     _pMsg->offendingMinorOpcode = _offendingMinorOpcode; \
  154.     _pMsg->severity = _severity; \
  155.     _pMsg->offendingSequenceNum = _offendingSequenceNum; \
  156.     _pMsg->errorClass = _errorClass; \
  157. }
  158.  
  159.  
  160. /*
  161.  * Write data into the ICE output buffer.
  162.  */
  163.  
  164. #define IceWriteData(_iceConn, _bytes, _data) \
  165. { \
  166.     if ((_iceConn->outbufptr + (_bytes)) > _iceConn->outbufmax) \
  167.     { \
  168.     IceFlush (_iceConn); \
  169.         _IceWrite (_iceConn, (unsigned long) (_bytes), _data); \
  170.     } \
  171.     else \
  172.     { \
  173.         memcpy (_iceConn->outbufptr, _data, _bytes); \
  174.         _iceConn->outbufptr += (_bytes); \
  175.     } \
  176. }
  177.  
  178. #ifndef WORD64
  179.  
  180. #define IceWriteData16(_iceConn, _bytes, _data) \
  181.     IceWriteData (_iceConn, _bytes, (char *) _data)
  182.  
  183. #define IceWriteData32(_iceConn, _bytes, _data) \
  184.     IceWriteData (_iceConn, _bytes, (char *) _data)
  185.  
  186. #else /* WORD64 */
  187.  
  188. /* IceWriteData16 and IceWriteData32 defined in misc.c for WORD64 */
  189.  
  190. #endif /* WORD64 */
  191.  
  192.  
  193. /*
  194.  * The IceSendData macro bypasses copying the data to the
  195.  * ICE connection buffer and sends the data directly.  If necessary,
  196.  * the ICE connection buffer is first flushed.
  197.  */
  198.  
  199. #define IceSendData(_iceConn, _bytes, _data) \
  200. { \
  201.     if (_iceConn->outbufptr > _iceConn->outbuf) \
  202.     IceFlush (_iceConn); \
  203.     _IceWrite (_iceConn, (unsigned long) (_bytes), _data); \
  204. }
  205.  
  206.  
  207. /*
  208.  * Write pad bytes.  Used to force 32 or 64 bit alignment.
  209.  * A maxium of 7 pad bytes can be specified.
  210.  */
  211.  
  212. #define IceWritePad(_iceConn, _bytes) \
  213. { \
  214.     if ((_iceConn->outbufptr + (_bytes)) > _iceConn->outbufmax) \
  215.     { \
  216.         char _dummy[7]; \
  217.     IceFlush (_iceConn); \
  218.         _IceWrite (_iceConn, (unsigned long) (_bytes), _dummy); \
  219.     } \
  220.     else \
  221.     { \
  222.         _iceConn->outbufptr += (_bytes); \
  223.     } \
  224. }
  225.  
  226.  
  227. /*
  228.  * Macros for reading messages.
  229.  */
  230.  
  231. #define IceReadCompleteMessage(_iceConn, _headerSize, _msgType, _pMsg, _pData)\
  232. { \
  233.     unsigned long _bytes; \
  234.     IceReadMessageHeader (_iceConn, _headerSize, _msgType, _pMsg); \
  235.     _bytes = (_pMsg->length << 3) - (_headerSize - SIZEOF (iceMsg)); \
  236.     if ((_iceConn->inbufmax - _iceConn->inbufptr) >= _bytes) \
  237.     { \
  238.     _IceRead (_iceConn, _bytes, _iceConn->inbufptr); \
  239.     _pData = _iceConn->inbufptr; \
  240.     _iceConn->inbufptr += _bytes; \
  241.     } \
  242.     else \
  243.     { \
  244.     _pData = (char *) malloc ((unsigned) _bytes); \
  245.         if (_pData) \
  246.         _IceRead (_iceConn, _bytes, _pData); \
  247.         else \
  248.         _IceReadSkip (_iceConn, _bytes); \
  249.     } \
  250. }
  251.  
  252. #define IceDisposeCompleteMessage(_iceConn, _pData) \
  253.     if ((char *) _pData < _iceConn->inbuf || \
  254.     (char *) _pData >= _iceConn->inbufmax) \
  255.         free ((char *) _pData);
  256.  
  257.  
  258. #define IceReadSimpleMessage(_iceConn, _msgType, _pMsg) \
  259.     _pMsg = (_msgType *) (_iceConn->inbuf);
  260.  
  261. #define IceReadMessageHeader(_iceConn, _headerSize, _msgType, _pMsg) \
  262. { \
  263.     _IceRead (_iceConn, \
  264.     (unsigned long) (_headerSize - SIZEOF (iceMsg)), \
  265.     _iceConn->inbufptr); \
  266.     _pMsg = (_msgType *) (_iceConn->inbuf); \
  267.     _iceConn->inbufptr += (_headerSize - SIZEOF (iceMsg)); \
  268. }
  269.  
  270. #define IceReadData(_iceConn, _bytes, _pData) \
  271.     _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
  272.  
  273. #ifndef WORD64
  274.  
  275. #define IceReadData16(_iceConn, _swap, _bytes, _pData) \
  276. { \
  277.     _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
  278. }
  279.  
  280. #define IceReadData32(_iceConn, _swap, _bytes, _pData) \
  281. { \
  282.     _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
  283. }
  284.  
  285. #else /* WORD64 */
  286.  
  287. /* IceReadData16 and IceReadData32 defined in misc.c for WORD64 */
  288.  
  289. #endif /* WORD64 */
  290.  
  291.  
  292. /*
  293.  * Read pad bytes (for 32 or 64 bit alignment).
  294.  * A maxium of 7 pad bytes can be specified.
  295.  */
  296.  
  297. #define IceReadPad(_iceConn, _bytes) \
  298. { \
  299.     char _dummy[7]; \
  300.     _IceRead (_iceConn, (unsigned long) (_bytes), _dummy); \
  301. }
  302.  
  303. #endif /* _ICEMSG_H_ */
  304.