XCB 1.8.1

xcbint.h

00001 /*
00002  * Copyright (C) 2001-2004 Bart Massey and Jamey Sharp.
00003  * All Rights Reserved.
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a
00006  * copy of this software and associated documentation files (the "Software"),
00007  * to deal in the Software without restriction, including without limitation
00008  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00009  * and/or sell copies of the Software, and to permit persons to whom the
00010  * Software is furnished to do so, subject to the following conditions:
00011  * 
00012  * The above copyright notice and this permission notice shall be included in
00013  * all copies or substantial portions of the Software.
00014  * 
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018  * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00019  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00020  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00021  * 
00022  * Except as contained in this notice, the names of the authors or their
00023  * institutions shall not be used in advertising or otherwise to promote the
00024  * sale, use or other dealings in this Software without prior written
00025  * authorization from the authors.
00026  */
00027 
00028 #ifndef __XCBINT_H
00029 #define __XCBINT_H
00030 
00031 #include "bigreq.h"
00032 
00033 #ifdef HAVE_CONFIG_H
00034 #include "config.h"
00035 #endif
00036 
00037 #ifdef GCC_HAS_VISIBILITY
00038 #pragma GCC visibility push(hidden)
00039 #endif
00040 
00041 enum workarounds {
00042     WORKAROUND_NONE,
00043     WORKAROUND_GLX_GET_FB_CONFIGS_BUG,
00044     WORKAROUND_EXTERNAL_SOCKET_OWNER
00045 };
00046 
00047 enum lazy_reply_tag
00048 {
00049     LAZY_NONE = 0,
00050     LAZY_COOKIE,
00051     LAZY_FORCED
00052 };
00053 
00054 #define XCB_PAD(i) (-(i) & 3)
00055 
00056 #define XCB_SEQUENCE_COMPARE(a,op,b)    ((int64_t) ((a) - (b)) op 0)
00057 
00058 #ifndef offsetof
00059 #define offsetof(type,member) ((size_t) &((type *)0)->member)
00060 #endif
00061 
00062 #ifndef MIN
00063 #define MIN(x,y) ((x) < (y) ? (x) : (y))
00064 #endif
00065 
00066 #define container_of(pointer,type,member) ((type *)(((char *)(pointer)) - offsetof(type, member)))
00067 
00068 /* xcb_list.c */
00069 
00070 typedef void (*xcb_list_free_func_t)(void *);
00071 
00072 typedef struct _xcb_map _xcb_map;
00073 
00074 _xcb_map *_xcb_map_new(void);
00075 void _xcb_map_delete(_xcb_map *q, xcb_list_free_func_t do_free);
00076 int _xcb_map_put(_xcb_map *q, unsigned int key, void *data);
00077 void *_xcb_map_remove(_xcb_map *q, unsigned int key);
00078 
00079 
00080 /* xcb_out.c */
00081 
00082 typedef struct _xcb_out {
00083     pthread_cond_t cond;
00084     int writing;
00085 
00086     pthread_cond_t socket_cond;
00087     void (*return_socket)(void *closure);
00088     void *socket_closure;
00089     int socket_moving;
00090 
00091     char queue[XCB_QUEUE_BUFFER_SIZE];
00092     int queue_len;
00093 
00094     uint64_t request;
00095     uint64_t request_written;
00096 
00097     pthread_mutex_t reqlenlock;
00098     enum lazy_reply_tag maximum_request_length_tag;
00099     union {
00100         xcb_big_requests_enable_cookie_t cookie;
00101         uint32_t value;
00102     } maximum_request_length;
00103 } _xcb_out;
00104 
00105 int _xcb_out_init(_xcb_out *out);
00106 void _xcb_out_destroy(_xcb_out *out);
00107 
00108 int _xcb_out_send(xcb_connection_t *c, struct iovec *vector, int count);
00109 void _xcb_out_send_sync(xcb_connection_t *c);
00110 int _xcb_out_flush_to(xcb_connection_t *c, uint64_t request);
00111 
00112 
00113 /* xcb_in.c */
00114 
00115 typedef struct _xcb_in {
00116     pthread_cond_t event_cond;
00117     int reading;
00118 
00119     char queue[4096];
00120     int queue_len;
00121 
00122     uint64_t request_expected;
00123     uint64_t request_read;
00124     uint64_t request_completed;
00125     struct reply_list *current_reply;
00126     struct reply_list **current_reply_tail;
00127 
00128     _xcb_map *replies;
00129     struct event_list *events;
00130     struct event_list **events_tail;
00131     struct reader_list *readers;
00132 
00133     struct pending_reply *pending_replies;
00134     struct pending_reply **pending_replies_tail;
00135 } _xcb_in;
00136 
00137 int _xcb_in_init(_xcb_in *in);
00138 void _xcb_in_destroy(_xcb_in *in);
00139 
00140 void _xcb_in_wake_up_next_reader(xcb_connection_t *c);
00141 
00142 int _xcb_in_expect_reply(xcb_connection_t *c, uint64_t request, enum workarounds workaround, int flags);
00143 void _xcb_in_replies_done(xcb_connection_t *c);
00144 
00145 int _xcb_in_read(xcb_connection_t *c);
00146 int _xcb_in_read_block(xcb_connection_t *c, void *buf, int nread);
00147 
00148 
00149 /* xcb_xid.c */
00150 
00151 typedef struct _xcb_xid {
00152     pthread_mutex_t lock;
00153     uint32_t last;
00154     uint32_t base;
00155     uint32_t max;
00156     uint32_t inc;
00157 } _xcb_xid;
00158 
00159 int _xcb_xid_init(xcb_connection_t *c);
00160 void _xcb_xid_destroy(xcb_connection_t *c);
00161 
00162 
00163 /* xcb_ext.c */
00164 
00165 typedef struct _xcb_ext {
00166     pthread_mutex_t lock;
00167     struct lazyreply *extensions;
00168     int extensions_size;
00169 } _xcb_ext;
00170 
00171 int _xcb_ext_init(xcb_connection_t *c);
00172 void _xcb_ext_destroy(xcb_connection_t *c);
00173 
00174 
00175 /* xcb_conn.c */
00176 
00177 struct xcb_connection_t {
00178     int has_error;
00179 
00180     /* constant data */
00181     xcb_setup_t *setup;
00182     int fd;
00183 
00184     /* I/O data */
00185     pthread_mutex_t iolock;
00186     _xcb_in in;
00187     _xcb_out out;
00188 
00189     /* misc data */
00190     _xcb_ext ext;
00191     _xcb_xid xid;
00192 };
00193 
00194 void _xcb_conn_shutdown(xcb_connection_t *c, int err);
00195 
00196 xcb_connection_t *_xcb_conn_ret_error(int err);
00197 
00198 int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count);
00199 
00200 
00201 /* xcb_auth.c */
00202 
00203 int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display);
00204 
00205 #ifdef GCC_HAS_VISIBILITY
00206 #pragma GCC visibility pop
00207 #endif
00208 
00209 #endif