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