Quit using "-include config.h": use #ifdef HAVE_CONFIG_H etc. like everyone else.
[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 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 enum workarounds {
36     WORKAROUND_NONE,
37     WORKAROUND_GLX_GET_FB_CONFIGS_BUG
38 };
39
40 /* xcb_list.c */
41
42 typedef struct _xcb_list _xcb_list;
43 typedef void (*XCBListFreeFunc)(void *);
44
45 _xcb_list *_xcb_list_new(void);
46 void _xcb_list_delete(_xcb_list *list, XCBListFreeFunc do_free);
47 int _xcb_list_insert(_xcb_list *list, void *data);
48 int _xcb_list_append(_xcb_list *list, void *data);
49 void *_xcb_list_peek_head(_xcb_list *list);
50 void *_xcb_list_remove_head(_xcb_list *list);
51 void *_xcb_list_remove(_xcb_list *list, int (*cmp)(const void *, const void *), const void *data);
52 void *_xcb_list_find(_xcb_list *list, int (*cmp)(const void *, const void *), const void *data);
53
54 typedef _xcb_list _xcb_queue;
55
56 _xcb_queue *_xcb_queue_new(void);
57 void _xcb_queue_delete(_xcb_queue *q, XCBListFreeFunc do_free);
58 int _xcb_queue_enqueue(_xcb_queue *q, void *data);
59 void *_xcb_queue_dequeue(_xcb_queue *q);
60 int _xcb_queue_is_empty(_xcb_queue *q);
61
62 typedef _xcb_list _xcb_map;
63
64 _xcb_map *_xcb_map_new(void);
65 void _xcb_map_delete(_xcb_map *q, XCBListFreeFunc do_free);
66 int _xcb_map_put(_xcb_map *q, unsigned int key, void *data);
67 void *_xcb_map_get(_xcb_map *q, unsigned int key);
68 void *_xcb_map_remove(_xcb_map *q, unsigned int key);
69
70
71 /* xcb_util.c */
72
73 /* Index of nearest 4-byte boundary following E. */
74 #define XCB_CEIL(E) (((E)+3)&~3)
75
76 #define XCB_PAD(i) ((4 - (i & 3)) & 3)
77
78 int _xcb_set_fd_flags(const int fd);
79 int _xcb_read_block(const int fd, void *buf, const size_t len);
80
81
82 /* xcb_out.c */
83
84 typedef struct _xcb_out {
85     pthread_cond_t cond;
86     int writing;
87
88     char queue[4096];
89     int queue_len;
90     struct iovec *vec;
91     int vec_len;
92
93     unsigned int request;
94     unsigned int request_written;
95
96     pthread_mutex_t reqlenlock;
97     CARD32 maximum_request_length;
98 } _xcb_out;
99
100 int _xcb_out_init(_xcb_out *out);
101 void _xcb_out_destroy(_xcb_out *out);
102
103 int _xcb_out_write(XCBConnection *c);
104 int _xcb_out_write_block(XCBConnection *c, struct iovec *vector, size_t count);
105 int _xcb_out_flush(XCBConnection *c);
106
107
108 /* xcb_in.c */
109
110 typedef struct _xcb_in {
111     pthread_cond_t event_cond;
112     int reading;
113
114     char queue[4096];
115     int queue_len;
116
117     unsigned int request_read;
118     _xcb_queue *current_reply;
119
120     _xcb_map *replies;
121     _xcb_queue *events;
122     _xcb_list *readers;
123
124     _xcb_queue *pending_replies;
125 } _xcb_in;
126
127 int _xcb_in_init(_xcb_in *in);
128 void _xcb_in_destroy(_xcb_in *in);
129
130 int _xcb_in_expect_reply(XCBConnection *c, unsigned int request, enum workarounds workaround);
131
132 int _xcb_in_read(XCBConnection *c);
133 int _xcb_in_read_block(XCBConnection *c, void *buf, int nread);
134
135
136 /* xcb_xid.c */
137
138 typedef struct _xcb_xid {
139     pthread_mutex_t lock;
140     CARD32 last;
141     CARD32 base;
142     CARD32 max;
143     CARD32 inc;
144 } _xcb_xid;
145
146 int _xcb_xid_init(XCBConnection *c);
147 void _xcb_xid_destroy(XCBConnection *c);
148
149
150 /* xcb_ext.c */
151
152 typedef struct _xcb_ext {
153     pthread_mutex_t lock;
154     _xcb_map *extensions;
155 } _xcb_ext;
156
157 int _xcb_ext_init(XCBConnection *c);
158 void _xcb_ext_destroy(XCBConnection *c);
159
160
161 /* xcb_conn.c */
162
163 struct XCBConnection {
164     /* constant data */
165     XCBConnSetupSuccessRep *setup;
166     int fd;
167
168     /* I/O data */
169     pthread_mutex_t iolock;
170     _xcb_in in;
171     _xcb_out out;
172
173     /* misc data */
174     _xcb_ext ext;
175     _xcb_xid xid;
176 };
177
178 int _xcb_conn_wait(XCBConnection *c, const int should_write, pthread_cond_t *cond);
179 #endif