Debian Codegraph @

nx-X11/include/extensions/sync.h

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