1/*
2
3Copyright 1991, 1993, 1994, 1998  The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24
25*/
26
27/***********************************************************
28Copyright 1991,1993 by Digital Equipment Corporation, Maynard, Massachusetts,
29and Olivetti Research Limited, Cambridge, England.
30
31                        All Rights Reserved
32
33Permission to use, copy, modify, and distribute this software and its
34documentation for any purpose and without fee is hereby granted,
35provided that the above copyright notice appear in all copies and that
36both that copyright notice and this permission notice appear in
37supporting documentation, and that the names of Digital or Olivetti
38not be used in advertising or publicity pertaining to distribution of the
39software without specific, written prior permission.
40
41DIGITAL AND OLIVETTI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
42SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
43FITNESS, IN NO EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
44CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
45USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
46OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
47PERFORMANCE OF THIS SOFTWARE.
48
49******************************************************************/
50
51#ifndef _SYNC_H_
52#define _SYNC_H_
53
54#include <X11/Xfuncproto.h>
55#include <X11/extensions/syncconst.h>
56
57#ifdef _SYNC_SERVER
58#include <X11/extensions/syncproto.h>
59#else
60
61_XFUNCPROTOBEGIN
62/* get rid of macros so we can define corresponding functions */
63#undef XSyncIntToValue
64#undef XSyncIntsToValue
65#undef XSyncValueGreaterThan
66#undef XSyncValueLessThan
67#undef XSyncValueGreaterOrEqual
68#undef XSyncValueLessOrEqual
69#undef XSyncValueEqual
70#undef XSyncValueIsNegative
71#undef XSyncValueIsZero
72#undef XSyncValueIsPositive
73#undef XSyncValueLow32
74#undef XSyncValueHigh32
75#undef XSyncValueAdd
76#undef XSyncValueSubtract
77#undef XSyncMaxValue
78#undef XSyncMinValue
79
80extern void XSyncIntToValue(
81    XSyncValue* /*pv*/,
82    int /*i*/
83);
84
85extern void XSyncIntsToValue(
86    XSyncValue* /*pv*/,
87    unsigned int /*l*/,
88    int /*h*/
89);
90
91extern Bool XSyncValueGreaterThan(
92    XSyncValue /*a*/,
93    XSyncValue /*b*/
94);
95
96extern Bool XSyncValueLessThan(
97    XSyncValue /*a*/,
98    XSyncValue /*b*/
99);
100
101extern Bool XSyncValueGreaterOrEqual(
102    XSyncValue /*a*/,
103    XSyncValue /*b*/
104);
105
106extern Bool XSyncValueLessOrEqual(
107    XSyncValue /*a*/,
108    XSyncValue /*b*/
109);
110
111extern Bool XSyncValueEqual(
112    XSyncValue /*a*/,
113    XSyncValue /*b*/
114);
115
116extern Bool XSyncValueIsNegative(
117    XSyncValue /*v*/
118);
119
120extern Bool XSyncValueIsZero(
121    XSyncValue /*a*/
122);
123
124extern Bool XSyncValueIsPositive(
125    XSyncValue /*v*/
126);
127
128extern unsigned int XSyncValueLow32(
129    XSyncValue /*v*/
130);
131
132extern int XSyncValueHigh32(
133    XSyncValue /*v*/
134);
135
136extern void XSyncValueAdd(
137    XSyncValue* /*presult*/,
138    XSyncValue /*a*/,
139    XSyncValue /*b*/,
140    int* /*poverflow*/
141);
142
143extern void XSyncValueSubtract(
144    XSyncValue* /*presult*/,
145    XSyncValue /*a*/,
146    XSyncValue /*b*/,
147    int* /*poverflow*/
148);
149
150extern void XSyncMaxValue(
151    XSyncValue* /*pv*/
152);
153
154extern void XSyncMinValue(
155    XSyncValue* /*pv*/
156);
157
158_XFUNCPROTOEND
159
160
161typedef struct _XSyncSystemCounter {
162    char *name;			/* null-terminated name of system counter */
163    XSyncCounter counter;	/* counter id of this system counter */
164    XSyncValue resolution;	/* resolution of this system counter */
165} XSyncSystemCounter;
166
167
168typedef struct {
169    XSyncCounter counter;	/* counter to trigger on */
170    XSyncValueType value_type;	/* absolute/relative */
171    XSyncValue wait_value;	/* value to compare counter to */
172    XSyncTestType test_type;	/* pos/neg comparison/transition */
173} XSyncTrigger;
174
175typedef struct {
176    XSyncTrigger trigger;	/* trigger for await */
177    XSyncValue event_threshold; /* send event if past threshold */
178} XSyncWaitCondition;
179
180
181typedef struct {
182    XSyncTrigger trigger;
183    XSyncValue  delta;
184    Bool events;
185    XSyncAlarmState state;
186} XSyncAlarmAttributes;
187
188/*
189 *  Events
190 */
191
192typedef struct {
193    int type;			/* event base + XSyncCounterNotify */
194    unsigned long serial;	/* # of last request processed by server */
195    Bool send_event;		/* true if this came from a SendEvent request */
196    Display *display;		/* Display the event was read from */
197    XSyncCounter counter;	/* counter involved in await */
198    XSyncValue wait_value;	/* value being waited for */
199    XSyncValue counter_value;	/* counter value when this event was sent */
200    Time time;			/* milliseconds */
201    int count;			/* how many more events to come */
202    Bool destroyed;		/* True if counter was destroyed */
203} XSyncCounterNotifyEvent;
204
205typedef struct {
206    int type;			/* event base + XSyncAlarmNotify */
207    unsigned long serial;	/* # of last request processed by server */
208    Bool send_event;		/* true if this came from a SendEvent request */
209    Display *display;		/* Display the event was read from */
210    XSyncAlarm alarm;		/* alarm that triggered */
211    XSyncValue counter_value;	/* value that triggered the alarm */
212    XSyncValue alarm_value;	/* test  value of trigger in alarm */
213    Time time;			/* milliseconds */
214    XSyncAlarmState state;	/* new state of alarm */
215} XSyncAlarmNotifyEvent;
216
217/*
218 *  Errors
219 */
220
221typedef struct {
222    int type;
223    Display *display;		/* Display the event was read from */
224    XSyncAlarm alarm;		/* resource id */
225    unsigned long serial;	/* serial number of failed request */
226    unsigned char error_code;	/* error base + XSyncBadAlarm */
227    unsigned char request_code;	/* Major op-code of failed request */
228    unsigned char minor_code;	/* Minor op-code of failed request */
229} XSyncAlarmError;
230
231typedef struct {
232    int type;
233    Display *display;		/* Display the event was read from */
234    XSyncCounter counter;	/* resource id */
235    unsigned long serial;	/* serial number of failed request */
236    unsigned char error_code;	/* error base + XSyncBadCounter */
237    unsigned char request_code;	/* Major op-code of failed request */
238    unsigned char minor_code;	/* Minor op-code of failed request */
239} XSyncCounterError;
240
241/*
242 *  Prototypes
243 */
244
245_XFUNCPROTOBEGIN
246
247extern Status XSyncQueryExtension(
248    Display* /*dpy*/,
249    int* /*event_base_return*/,
250    int* /*error_base_return*/
251);
252
253extern Status XSyncInitialize(
254    Display* /*dpy*/,
255    int* /*major_version_return*/,
256    int* /*minor_version_return*/
257);
258
259extern XSyncSystemCounter *XSyncListSystemCounters(
260    Display* /*dpy*/,
261    int* /*n_counters_return*/
262);
263
264extern void XSyncFreeSystemCounterList(
265    XSyncSystemCounter* /*list*/
266);
267
268extern XSyncCounter XSyncCreateCounter(
269    Display* /*dpy*/,
270    XSyncValue /*initial_value*/
271);
272
273extern Status XSyncSetCounter(
274    Display* /*dpy*/,
275    XSyncCounter /*counter*/,
276    XSyncValue /*value*/
277);
278
279extern Status XSyncChangeCounter(
280    Display* /*dpy*/,
281    XSyncCounter /*counter*/,
282    XSyncValue /*value*/
283);
284
285extern Status XSyncDestroyCounter(
286    Display* /*dpy*/,
287    XSyncCounter /*counter*/
288);
289
290extern Status XSyncQueryCounter(
291    Display* /*dpy*/,
292    XSyncCounter /*counter*/,
293    XSyncValue* /*value_return*/
294);
295
296extern Status XSyncAwait(
297    Display* /*dpy*/,
298    XSyncWaitCondition* /*wait_list*/,
299    int /*n_conditions*/
300);
301
302extern XSyncAlarm XSyncCreateAlarm(
303    Display* /*dpy*/,
304    unsigned long /*values_mask*/,
305    XSyncAlarmAttributes* /*values*/
306);
307
308extern Status XSyncDestroyAlarm(
309    Display* /*dpy*/,
310    XSyncAlarm /*alarm*/
311);
312
313extern Status XSyncQueryAlarm(
314    Display* /*dpy*/,
315    XSyncAlarm /*alarm*/,
316    XSyncAlarmAttributes* /*values_return*/
317);
318
319extern Status XSyncChangeAlarm(
320    Display* /*dpy*/,
321    XSyncAlarm /*alarm*/,
322    unsigned long /*values_mask*/,
323    XSyncAlarmAttributes* /*values*/
324);
325
326extern Status XSyncSetPriority(
327    Display* /*dpy*/,
328    XID /*client_resource_id*/,
329    int /*priority*/
330);
331
332extern Status XSyncGetPriority(
333    Display* /*dpy*/,
334    XID /*client_resource_id*/,
335    int* /*return_priority*/
336);
337
338extern XSyncFence XSyncCreateFence(
339    Display* /*dpy*/,
340    Drawable /*d*/,
341    Bool /*initially_triggered*/
342);
343
344extern Bool XSyncTriggerFence(
345    Display* /*dpy*/,
346    XSyncFence /*fence*/
347);
348
349extern Bool XSyncResetFence(
350    Display* /*dpy*/,
351    XSyncFence /*fence*/
352);
353
354extern Bool XSyncDestroyFence(
355    Display* /*dpy*/,
356    XSyncFence /*fence*/
357);
358
359extern Bool XSyncQueryFence(
360    Display* /*dpy*/,
361    XSyncFence /*fence*/,
362    Bool* /*triggered*/
363);
364
365extern Bool XSyncAwaitFence(
366    Display* /*dpy*/,
367    const XSyncFence* /*fence_list*/,
368    int /*n_fences*/
369);
370
371_XFUNCPROTOEND
372
373#endif /* _SYNC_SERVER */
374
375#endif /* _SYNC_H_ */
376