Remove xcl and CVSROOT.
[free-sw/xcb/libxcb] / src / xcbint.h
1 /*
2  * Copyright (C) 2001-2004 Bart Massey and Jamey Sharp.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  * 
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  * 
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  * 
22  * Except as contained in this notice, the names of the authors or their
23  * institutions shall not be used in advertising or otherwise to promote the
24  * sale, use or other dealings in this Software without prior written
25  * authorization from the authors.
26  */
27
28 #ifndef __XCBINT_H
29 #define __XCBINT_H
30
31 /* Not simply (a <= b) because eventually the 32-bit sequence number
32  * will wrap, causing earlier sequence numbers to be higher than later
33  * ones for a brief but fatal period. (a and b must be unsigned.) */
34 #define _xcb_assert_sequence_less(a,b) assert((b) - (a) < 65536)
35
36 #define _xcb_assert_valid_sequence(c) do { \
37     _xcb_assert_sequence_less((c)->in.request_read, (c)->out.request_written); \
38     _xcb_assert_sequence_less((c)->out.request_written, (c)->out.request); \
39 } while(0)
40
41 /* xcb_list.c */
42
43 typedef struct _xcb_list _xcb_list;
44 typedef void (*XCBListFreeFunc)(void *);
45
46 _xcb_list *_xcb_list_new(void);
47 void _xcb_list_delete(_xcb_list *list, XCBListFreeFunc do_free);
48 int _xcb_list_insert(_xcb_list *list, void *data);
49 int _xcb_list_append(_xcb_list *list, void *data);
50 void *_xcb_list_peek_head(_xcb_list *list);
51 void *_xcb_list_remove_head(_xcb_list *list);
52 void *_xcb_list_remove(_xcb_list *list, int (*cmp)(const void *, const void *), const void *data);
53 void *_xcb_list_find(_xcb_list *list, int (*cmp)(const void *, const void *), const void *data);
54
55 typedef _xcb_list _xcb_queue;
56
57 _xcb_queue *_xcb_queue_new(void);
58 void _xcb_queue_delete(_xcb_queue *q, XCBListFreeFunc do_free);
59 int _xcb_queue_enqueue(_xcb_queue *q, void *data);
60 void *_xcb_queue_dequeue(_xcb_queue *q);
61 int _xcb_queue_is_empty(_xcb_queue *q);
62
63 typedef _xcb_list _xcb_map;
64
65 _xcb_map *_xcb_map_new(void);
66 void _xcb_map_delete(_xcb_map *q, XCBListFreeFunc do_free);
67 int _xcb_map_put(_xcb_map *q, unsigned int key, void *data);
68 void *_xcb_map_get(_xcb_map *q, unsigned int key);
69 void *_xcb_map_remove(_xcb_map *q, unsigned int key);
70
71
72 /* xcb_util.c */
73
74 /* Index of nearest 4-byte boundary following E. */
75 #define XCB_CEIL(E) (((E)+3)&~3)
76
77 #define XCB_PAD(i) ((4 - (i & 3)) & 3)
78
79 int _xcb_set_fd_flags(const int fd);
80 int _xcb_readn(const int fd, void *buf, const int buflen, int *count);
81 int _xcb_read_block(const int fd, void *buf, const size_t len);
82 int _xcb_write(const int fd, char (*buf)[], int *count);
83 int _xcb_writev(const int fd, struct iovec *vec, int count);
84
85
86 /* xcb_out.c */
87
88 typedef struct _xcb_out {
89     pthread_cond_t cond;
90     int writing;
91
92     char queue[4096];
93     int queue_len;
94     struct iovec *vec;
95     int vec_len;
96
97     void *last_request;
98     unsigned int request;
99     unsigned int request_written;
100
101     pthread_mutex_t reqlenlock;
102     CARD32 maximum_request_length;
103 } _xcb_out;
104
105 int _xcb_out_init(_xcb_out *out);
106 void _xcb_out_destroy(_xcb_out *out);
107
108 int _xcb_out_write(XCBConnection *c);
109 int _xcb_out_write_block(XCBConnection *c, struct iovec *vector, size_t count);
110 int _xcb_out_flush(XCBConnection *c);
111
112
113 /* xcb_in.c */
114
115 typedef struct _xcb_in {
116     pthread_cond_t event_cond;
117     int reading;
118
119     char queue[4096];
120     int queue_len;
121
122     unsigned int request_read;
123     _xcb_queue *current_reply;
124
125     _xcb_map *replies;
126     _xcb_queue *events;
127     _xcb_list *readers;
128 } _xcb_in;
129
130 int _xcb_in_init(_xcb_in *in);
131 void _xcb_in_destroy(_xcb_in *in);
132
133 int _xcb_in_expect_reply(XCBConnection *c, unsigned int request);
134
135 int _xcb_in_read_packet(XCBConnection *c);
136 int _xcb_in_read(XCBConnection *c);
137 int _xcb_in_read_block(XCBConnection *c, void *buf, int nread);
138
139
140 /* xcb_xid.c */
141
142 typedef struct _xcb_xid {
143     pthread_mutex_t lock;
144     CARD32 last;
145     CARD32 base;
146     CARD32 max;
147     CARD32 inc;
148 } _xcb_xid;
149
150 int _xcb_xid_init(XCBConnection *c);
151 void _xcb_xid_destroy(XCBConnection *c);
152
153
154 /* xcb_ext.c */
155
156 typedef struct _xcb_ext {
157     pthread_mutex_t lock;
158     _xcb_map *extensions;
159 } _xcb_ext;
160
161 int _xcb_ext_init(XCBConnection *c);
162 void _xcb_ext_destroy(XCBConnection *c);
163
164
165 /* xcb_conn.c */
166
167 struct XCBConnection {
168     /* constant data */
169     XCBConnSetupSuccessRep *setup;
170     int fd;
171
172     /* I/O data */
173     pthread_mutex_t iolock;
174     _xcb_in in;
175     _xcb_out out;
176
177     /* misc data */
178     _xcb_ext ext;
179     _xcb_xid xid;
180 };
181
182 int _xcb_conn_wait(XCBConnection *c, const int should_write, pthread_cond_t *cond);
183 #endif