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

  1. /* $XConsortium: sync.h,v 1.6 94/04/17 20:11:26 dpw Exp $ */
  2. /*
  3.  
  4. Copyright (c) 1991, 1993, 1994  X Consortium
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  19. X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22.  
  23. Except as contained in this notice, the name of the X Consortium shall not be
  24. used in advertising or otherwise to promote the sale, use or other dealings
  25. in this Software without prior written authorization from the X Consortium.
  26.  
  27. */
  28.  
  29. /***********************************************************
  30. Copyright 1991,1993 by Digital Equipment Corporation, Maynard, Massachusetts,
  31. and Olivetti Research Limited, Cambridge, England.
  32.  
  33.                         All Rights Reserved
  34.  
  35. Permission to use, copy, modify, and distribute this software and its 
  36. documentation for any purpose and without fee is hereby granted, 
  37. provided that the above copyright notice appear in all copies and that
  38. both that copyright notice and this permission notice appear in 
  39. supporting documentation, and that the names of Digital or Olivetti
  40. not be used in advertising or publicity pertaining to distribution of the
  41. software without specific, written prior permission.  
  42.  
  43. DIGITAL AND OLIVETTI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  44. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  45. FITNESS, IN NO EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  46. CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  47. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  48. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  49. PERFORMANCE OF THIS SOFTWARE.
  50.  
  51. ******************************************************************/
  52.  
  53. #ifndef _SYNC_H_
  54. #define _SYNC_H_
  55.  
  56. #define SYNC_NAME "SYNC"
  57.  
  58. #define SYNC_MAJOR_VERSION    3
  59. #define SYNC_MINOR_VERSION    0
  60.  
  61. #define X_SyncInitialize        0
  62. #define X_SyncListSystemCounters    1
  63. #define X_SyncCreateCounter        2
  64. #define X_SyncSetCounter        3
  65. #define X_SyncChangeCounter        4
  66. #define X_SyncQueryCounter              5
  67. #define X_SyncDestroyCounter        6
  68. #define X_SyncAwait            7
  69. #define X_SyncCreateAlarm               8
  70. #define X_SyncChangeAlarm            9
  71. #define X_SyncQueryAlarm           10
  72. #define X_SyncDestroyAlarm           11
  73. #define X_SyncSetPriority              12
  74. #define X_SyncGetPriority              13
  75.  
  76. #define XSyncCounterNotify              0
  77. #define XSyncAlarmNotify        1
  78. #define XSyncAlarmNotifyMask         (1L << XSyncAlarmNotify)
  79.  
  80. #define XSyncNumberEvents        2L
  81.  
  82. #define XSyncBadCounter            0L
  83. #define XSyncBadAlarm            1L
  84. #define XSyncNumberErrors        (XSyncBadAlarm + 1)
  85.  
  86. /*
  87.  * Flags for Alarm Attributes
  88.  */
  89. #define XSyncCACounter            (1L<<0)
  90. #define XSyncCAValueType        (1L<<1)
  91. #define XSyncCAValue            (1L<<2)
  92. #define XSyncCATestType            (1L<<3)
  93. #define XSyncCADelta            (1L<<4)
  94. #define XSyncCAEvents            (1L<<5)
  95.  
  96. /*
  97.  * Constants for the value_type argument of various requests
  98.  */
  99. typedef enum {
  100.     XSyncAbsolute,
  101.     XSyncRelative
  102. } XSyncValueType;
  103.  
  104. /*
  105.  * Alarm Test types
  106.  */
  107. typedef enum {
  108.     XSyncPositiveTransition,
  109.     XSyncNegativeTransition,
  110.     XSyncPositiveComparison,
  111.     XSyncNegativeComparison
  112. } XSyncTestType;
  113.  
  114. /*
  115.  * Alarm state constants
  116.  */
  117. typedef enum {
  118.     XSyncAlarmActive,
  119.     XSyncAlarmInactive,
  120.     XSyncAlarmDestroyed
  121. } XSyncAlarmState;
  122.  
  123.  
  124. typedef XID XSyncCounter;
  125. typedef XID XSyncAlarm;
  126. typedef struct _XSyncValue {
  127.     int hi;
  128.     unsigned int lo;
  129. } XSyncValue;
  130.  
  131. /*
  132.  *   Macros/functions for manipulating 64 bit values
  133.  */
  134.  
  135. /* have to put these prototypes before the corresponding macro definitions */
  136.  
  137. extern void XSyncIntToValue(
  138. #if NeedFunctionPrototypes
  139.     XSyncValue* /*pv*/,
  140.     int /*i*/
  141. #endif
  142. );
  143.  
  144. extern void XSyncIntsToValue(
  145. #if NeedFunctionPrototypes
  146.     XSyncValue* /*pv*/,
  147.     unsigned int /*l*/,
  148.     int /*h*/
  149. #endif
  150. );
  151.  
  152. extern Bool XSyncValueGreaterThan(
  153. #if NeedFunctionPrototypes
  154.     XSyncValue /*a*/,
  155.     XSyncValue /*b*/
  156. #endif
  157. );
  158.  
  159. extern Bool XSyncValueLessThan(
  160. #if NeedFunctionPrototypes
  161.     XSyncValue /*a*/,
  162.     XSyncValue /*b*/
  163. #endif
  164. );
  165.  
  166. extern Bool XSyncValueGreaterOrEqual(
  167. #if NeedFunctionPrototypes
  168.     XSyncValue /*a*/,
  169.     XSyncValue /*b*/
  170. #endif
  171. );
  172.  
  173. extern Bool XSyncValueLessOrEqual(
  174. #if NeedFunctionPrototypes
  175.     XSyncValue /*a*/,
  176.     XSyncValue /*b*/
  177. #endif
  178. );
  179.  
  180. extern Bool XSyncValueEqual(
  181. #if NeedFunctionPrototypes
  182.     XSyncValue /*a*/,
  183.     XSyncValue /*b*/
  184. #endif
  185. );
  186.  
  187. extern Bool XSyncValueIsNegative(
  188. #if NeedFunctionPrototypes
  189.     XSyncValue /*v*/
  190. #endif
  191. );
  192.  
  193. extern Bool XSyncValueIsZero(
  194. #if NeedFunctionPrototypes
  195.     XSyncValue /*a*/
  196. #endif
  197. );
  198.  
  199. extern Bool XSyncValueIsPositive(
  200. #if NeedFunctionPrototypes
  201.     XSyncValue /*v*/
  202. #endif
  203. );
  204.  
  205. extern unsigned int XSyncValueLow32(
  206. #if NeedFunctionPrototypes
  207.     XSyncValue /*v*/
  208. #endif
  209. );
  210.  
  211. extern int XSyncValueHigh32(
  212. #if NeedFunctionPrototypes
  213.     XSyncValue /*v*/
  214. #endif
  215. );
  216.  
  217. extern void XSyncValueAdd(
  218. #if NeedFunctionPrototypes
  219.     XSyncValue* /*presult*/,
  220.     XSyncValue /*a*/,
  221.     XSyncValue /*b*/,
  222.     int* /*poverflow*/
  223. #endif
  224. );
  225.  
  226. extern void XSyncValueSubtract(
  227. #if NeedFunctionPrototypes
  228.     XSyncValue* /*presult*/,
  229.     XSyncValue /*a*/,
  230.     XSyncValue /*b*/,
  231.     int* /*poverflow*/
  232. #endif
  233. );
  234.  
  235. extern void XSyncMaxValue(
  236. #if NeedFunctionPrototypes
  237.     XSyncValue* /*pv*/
  238. #endif
  239. );
  240.  
  241. extern void XSyncMinValue(
  242. #if NeedFunctionPrototypes
  243.     XSyncValue* /*pv*/
  244. #endif
  245. );
  246.  
  247. /*  The _XSync macros below are for library internal use only.  They exist 
  248.  *  so that if we have to make a fix, we can change it in this one place
  249.  *  and have both the macro and function variants inherit the fix.
  250.  */
  251.  
  252. #define _XSyncIntToValue(pv, i)     ((pv)->hi=((i<0)?~0:0),(pv)->lo=(i))
  253. #define _XSyncIntsToValue(pv, l, h) ((pv)->lo = (l), (pv)->hi = (h))
  254. #define _XSyncValueGreaterThan(a, b)\
  255.     ((a).hi>(b).hi || ((a).hi==(b).hi && (a).lo>(b).lo))
  256. #define _XSyncValueLessThan(a, b)\
  257.     ((a).hi<(b).hi || ((a).hi==(b).hi && (a).lo<(b).lo))
  258. #define _XSyncValueGreaterOrEqual(a, b)\
  259.     ((a).hi>(b).hi || ((a).hi==(b).hi && (a).lo>=(b).lo))
  260. #define _XSyncValueLessOrEqual(a, b)\
  261.     ((a).hi<(b).hi || ((a).hi==(b).hi && (a).lo<=(b).lo))
  262. #define _XSyncValueEqual(a, b)    ((a).lo==(b).lo && (a).hi==(b).hi)
  263. #define _XSyncValueIsNegative(v) (((v).hi & 0x80000000) ? 1 : 0)
  264. #define _XSyncValueIsZero(a)    ((a).lo==0 && (a).hi==0)
  265. #define _XSyncValueIsPositive(v) (((v).hi & 0x80000000) ? 0 : 1)
  266. #define _XSyncValueLow32(v)    ((v).lo)
  267. #define _XSyncValueHigh32(v)    ((v).hi)
  268. #define _XSyncValueAdd(presult,a,b,poverflow) {\
  269.     int t = (a).lo;\
  270.     Bool signa = XSyncValueIsNegative(a);\
  271.     Bool signb = XSyncValueIsNegative(b);\
  272.     ((presult)->lo = (a).lo + (b).lo);\
  273.     ((presult)->hi = (a).hi + (b).hi);\
  274.     if (t>(presult)->lo) (presult)->hi++;\
  275.     *poverflow = ((signa == signb) && !(signa == XSyncValueIsNegative(*presult)));\
  276.      }
  277. #define _XSyncValueSubtract(presult,a,b,poverflow) {\
  278.     int t = (a).lo;\
  279.     Bool signa = XSyncValueIsNegative(a);\
  280.     Bool signb = XSyncValueIsNegative(b);\
  281.     ((presult)->lo = (a).lo - (b).lo);\
  282.     ((presult)->hi = (a).hi - (b).hi);\
  283.     if (t>(presult)->lo) (presult)->hi--;\
  284.     *poverflow = ((signa == signb) && !(signa == XSyncValueIsNegative(*presult)));\
  285.      }
  286. #define _XSyncMaxValue(pv) ((pv)->hi = 0x7fffffff, (pv)->lo = 0xffffffff)
  287. #define _XSyncMinValue(pv) ((pv)->hi = 0x80000000, (pv)->lo = 0)
  288.  
  289. /*
  290.  *  These are the publically usable macros.  If you want the function version
  291.  *  of one of these, just #undef the macro to uncover the function.
  292.  *  (This is the same convention that the ANSI C library uses.)
  293.  */
  294.  
  295. #define XSyncIntToValue(pv, i) _XSyncIntToValue(pv, i)
  296. #define XSyncIntsToValue(pv, l, h) _XSyncIntsToValue(pv, l, h)
  297. #define XSyncValueGreaterThan(a, b) _XSyncValueGreaterThan(a, b)
  298. #define XSyncValueLessThan(a, b) _XSyncValueLessThan(a, b)
  299. #define XSyncValueGreaterOrEqual(a, b) _XSyncValueGreaterOrEqual(a, b)
  300. #define XSyncValueLessOrEqual(a, b) _XSyncValueLessOrEqual(a, b)
  301. #define XSyncValueEqual(a, b) _XSyncValueEqual(a, b)
  302. #define XSyncValueIsNegative(v) _XSyncValueIsNegative(v)
  303. #define XSyncValueIsZero(a) _XSyncValueIsZero(a)
  304. #define XSyncValueIsPositive(v) _XSyncValueIsPositive(v)
  305. #define XSyncValueLow32(v) _XSyncValueLow32(v)
  306. #define XSyncValueHigh32(v) _XSyncValueHigh32(v)
  307. #define XSyncValueAdd(presult,a,b,poverflow) _XSyncValueAdd(presult,a,b,poverflow)
  308. #define XSyncValueSubtract(presult,a,b,poverflow) _XSyncValueSubtract(presult,a,b,poverflow)
  309. #define XSyncMaxValue(pv) _XSyncMaxValue(pv)
  310. #define XSyncMinValue(pv) _XSyncMinValue(pv)
  311.  
  312. #ifndef _SYNC_SERVER
  313.  
  314. typedef struct _XSyncSystemCounter {
  315.     char *name;            /* null-terminated name of system counter */
  316.     XSyncCounter counter;    /* counter id of this system counter */
  317.     XSyncValue resolution;    /* resolution of this system counter */
  318. } XSyncSystemCounter;
  319.  
  320.  
  321. typedef struct {
  322.     XSyncCounter counter;    /* counter to trigger on */
  323.     XSyncValueType value_type;    /* absolute/relative */
  324.     XSyncValue wait_value;    /* value to compare counter to */
  325.     XSyncTestType test_type;    /* pos/neg comparison/transtion */
  326. } XSyncTrigger;
  327.  
  328. typedef struct {
  329.     XSyncTrigger trigger;    /* trigger for await */
  330.     XSyncValue event_threshold; /* send event if past threshold */
  331. } XSyncWaitCondition;
  332.  
  333.  
  334. typedef struct {
  335.     XSyncTrigger trigger;
  336.     XSyncValue  delta;
  337.     Bool events;
  338.     XSyncAlarmState state;
  339. } XSyncAlarmAttributes;
  340.  
  341. /*
  342.  *  Events
  343.  */
  344.  
  345. typedef struct {
  346.     int type;            /* event base + XSyncCounterNotify */
  347.     unsigned long serial;    /* # of last request processed by server */
  348.     Bool send_event;        /* true if this came from a SendEvent request */
  349.     Display *display;        /* Display the event was read from */
  350.     XSyncCounter counter;    /* counter involved in await */
  351.     XSyncValue wait_value;    /* value being waited for */
  352.     XSyncValue counter_value;    /* counter value when this event was sent */
  353.     Time time;            /* milliseconds */
  354.     int count;            /* how many more events to come */
  355.     Bool destroyed;        /* True if counter was destroyed */
  356. } XSyncCounterNotifyEvent;
  357.  
  358. typedef struct {
  359.     int type;            /* event base + XSyncCounterNotify */
  360.     unsigned long serial;    /* # of last request processed by server */
  361.     Bool send_event;        /* true if this came from a SendEvent request */
  362.     Display *display;        /* Display the event was read from */
  363.     XSyncAlarm alarm;        /* alarm that triggered */
  364.     XSyncValue counter_value;    /* value that triggered the alarm */
  365.     XSyncValue alarm_value;    /* test  value of trigger in alarm */
  366.     Time time;            /* milliseconds */
  367.     XSyncAlarmState state;    /* new state of alarm */
  368. } XSyncAlarmNotifyEvent;
  369.  
  370. /*
  371.  *  Errors 
  372.  */
  373.  
  374. typedef struct {
  375.     int type;            
  376.     Display *display;        /* Display the event was read from */
  377.     XSyncAlarm alarm;        /* resource id */
  378.     unsigned long serial;    /* serial number of failed request */
  379.     unsigned char error_code;    /* error base + XSyncBadAlarm */
  380.     unsigned char request_code;    /* Major op-code of failed request */
  381.     unsigned char minor_code;    /* Minor op-code of failed request */
  382. } XSyncAlarmError;
  383.  
  384. typedef struct {
  385.     int type;            
  386.     Display *display;        /* Display the event was read from */
  387.     XSyncCounter counter;    /* resource id */
  388.     unsigned long serial;    /* serial number of failed request */
  389.     unsigned char error_code;    /* error base + XSyncBadCounter */
  390.     unsigned char request_code;    /* Major op-code of failed request */
  391.     unsigned char minor_code;    /* Minor op-code of failed request */
  392. } XSyncCounterError;
  393.  
  394. /* 
  395.  *  Prototypes
  396.  */
  397.  
  398. extern Status XSyncQueryExtension(
  399. #if NeedFunctionPrototypes
  400.     Display* /*dpy*/,
  401.     int* /*event_base_return*/,
  402.     int* /*error_base_return*/
  403. #endif
  404. );
  405.  
  406. extern Status XSyncInitialize(
  407. #if NeedFunctionPrototypes
  408.     Display* /*dpy*/,
  409.     int* /*major_version_return*/,
  410.     int* /*minor_version_return*/
  411. #endif
  412. );
  413.  
  414. extern XSyncSystemCounter *XSyncListSystemCounters(
  415. #if NeedFunctionPrototypes
  416.     Display* /*dpy*/,
  417.     int* /*n_counters_return*/
  418. #endif
  419. );
  420.  
  421. extern void XSyncFreeSystemCounterList(
  422. #if NeedFunctionPrototypes
  423.     XSyncSystemCounter* /*list*/
  424. #endif
  425. );
  426.  
  427. extern XSyncCounter XSyncCreateCounter(
  428. #if NeedFunctionPrototypes
  429.     Display* /*dpy*/,
  430.     XSyncValue /*initial_value*/
  431. #endif
  432. );
  433.  
  434. extern Status XSyncSetCounter(
  435. #if NeedFunctionPrototypes
  436.     Display* /*dpy*/,
  437.     XSyncCounter /*counter*/,
  438.     XSyncValue /*value*/
  439. #endif
  440. );
  441.  
  442. extern Status XSyncChangeCounter(
  443. #if NeedFunctionPrototypes
  444.     Display* /*dpy*/,
  445.     XSyncCounter /*counter*/,
  446.     XSyncValue /*value*/
  447. #endif
  448. );
  449.  
  450. extern Status XSyncDestroyCounter(
  451. #if NeedFunctionPrototypes
  452.     Display* /*dpy*/,
  453.     XSyncCounter /*counter*/
  454. #endif
  455. );
  456.  
  457. extern Status XSyncQueryCounter(
  458. #if NeedFunctionPrototypes
  459.     Display* /*dpy*/,
  460.     XSyncCounter /*counter*/,
  461.     XSyncValue* /*value_return*/
  462. #endif
  463. );
  464.  
  465. extern Status XSyncAwait(
  466. #if NeedFunctionPrototypes
  467.     Display* /*dpy*/,
  468.     XSyncWaitCondition* /*wait_list*/,
  469.     int /*n_conditions*/
  470. #endif
  471. );
  472.  
  473. extern XSyncAlarm XSyncCreateAlarm(
  474. #if NeedFunctionPrototypes
  475.     Display* /*dpy*/,
  476.     unsigned long /*values_mask*/,
  477.     XSyncAlarmAttributes* /*values*/
  478. #endif
  479. );
  480.  
  481. extern Status XSyncDestroyAlarm(
  482. #if NeedFunctionPrototypes
  483.     Display* /*dpy*/,
  484.     XSyncAlarm /*alarm*/
  485. #endif
  486. );
  487.  
  488. extern Status XSyncQueryAlarm(
  489. #if NeedFunctionPrototypes
  490.     Display* /*dpy*/,
  491.     XSyncAlarm /*alarm*/,
  492.     XSyncAlarmAttributes* /*values_return*/
  493. #endif
  494. );
  495.  
  496. extern Status XSyncChangeAlarm(
  497. #if NeedFunctionPrototypes
  498.     Display* /*dpy*/,
  499.     XSyncAlarm /*alarm*/,
  500.     unsigned long /*values_mask*/,
  501.     XSyncAlarmAttributes* /*values*/
  502. #endif
  503. );
  504.  
  505. extern Status XSyncSetPriority(
  506. #if NeedFunctionPrototypes
  507.     Display* /*dpy*/,
  508.     XID /*client_resource_id*/,
  509.     int /*priority*/
  510. #endif
  511. );
  512.  
  513. extern Status XSyncGetPriority(
  514. #if NeedFunctionPrototypes
  515.     Display* /*dpy*/,
  516.     XID /*client_resource_id*/,
  517.     int* /*return_priority*/
  518. #endif
  519. );
  520.  
  521. #endif /* _SYNC_SERVER */
  522.  
  523. #endif /* _SYNC_H_ */
  524.