XCB
1.11.1
|
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 #if HAVE_SENDMSG 00083 #define XCB_MAX_PASS_FD 16 00084 00085 typedef struct _xcb_fd { 00086 int fd[XCB_MAX_PASS_FD]; 00087 int nfd; 00088 int ifd; 00089 } _xcb_fd; 00090 #endif 00091 00092 typedef struct _xcb_out { 00093 pthread_cond_t cond; 00094 int writing; 00095 00096 pthread_cond_t socket_cond; 00097 void (*return_socket)(void *closure); 00098 void *socket_closure; 00099 int socket_moving; 00100 00101 char queue[XCB_QUEUE_BUFFER_SIZE]; 00102 int queue_len; 00103 00104 uint64_t request; 00105 uint64_t request_written; 00106 00107 pthread_mutex_t reqlenlock; 00108 enum lazy_reply_tag maximum_request_length_tag; 00109 union { 00110 xcb_big_requests_enable_cookie_t cookie; 00111 uint32_t value; 00112 } maximum_request_length; 00113 #if HAVE_SENDMSG 00114 _xcb_fd out_fd; 00115 #endif 00116 } _xcb_out; 00117 00118 int _xcb_out_init(_xcb_out *out); 00119 void _xcb_out_destroy(_xcb_out *out); 00120 00121 int _xcb_out_send(xcb_connection_t *c, struct iovec *vector, int count); 00122 void _xcb_out_send_sync(xcb_connection_t *c); 00123 int _xcb_out_flush_to(xcb_connection_t *c, uint64_t request); 00124 00125 00126 /* xcb_in.c */ 00127 00128 typedef struct _xcb_in { 00129 pthread_cond_t event_cond; 00130 int reading; 00131 00132 char queue[4096]; 00133 int queue_len; 00134 00135 uint64_t request_expected; 00136 uint64_t request_read; 00137 uint64_t request_completed; 00138 struct reply_list *current_reply; 00139 struct reply_list **current_reply_tail; 00140 00141 _xcb_map *replies; 00142 struct event_list *events; 00143 struct event_list **events_tail; 00144 struct reader_list *readers; 00145 struct special_list *special_waiters; 00146 00147 struct pending_reply *pending_replies; 00148 struct pending_reply **pending_replies_tail; 00149 #if HAVE_SENDMSG 00150 _xcb_fd in_fd; 00151 #endif 00152 struct xcb_special_event *special_events; 00153 } _xcb_in; 00154 00155 int _xcb_in_init(_xcb_in *in); 00156 void _xcb_in_destroy(_xcb_in *in); 00157 00158 void _xcb_in_wake_up_next_reader(xcb_connection_t *c); 00159 00160 int _xcb_in_expect_reply(xcb_connection_t *c, uint64_t request, enum workarounds workaround, int flags); 00161 void _xcb_in_replies_done(xcb_connection_t *c); 00162 00163 int _xcb_in_read(xcb_connection_t *c); 00164 int _xcb_in_read_block(xcb_connection_t *c, void *buf, int nread); 00165 00166 00167 /* xcb_xid.c */ 00168 00169 typedef struct _xcb_xid { 00170 pthread_mutex_t lock; 00171 uint32_t last; 00172 uint32_t base; 00173 uint32_t max; 00174 uint32_t inc; 00175 } _xcb_xid; 00176 00177 int _xcb_xid_init(xcb_connection_t *c); 00178 void _xcb_xid_destroy(xcb_connection_t *c); 00179 00180 00181 /* xcb_ext.c */ 00182 00183 typedef struct _xcb_ext { 00184 pthread_mutex_t lock; 00185 struct lazyreply *extensions; 00186 int extensions_size; 00187 } _xcb_ext; 00188 00189 int _xcb_ext_init(xcb_connection_t *c); 00190 void _xcb_ext_destroy(xcb_connection_t *c); 00191 00192 00193 /* xcb_conn.c */ 00194 00195 struct xcb_connection_t { 00196 /* This must be the first field; see _xcb_conn_ret_error(). */ 00197 int has_error; 00198 00199 /* constant data */ 00200 xcb_setup_t *setup; 00201 int fd; 00202 00203 /* I/O data */ 00204 pthread_mutex_t iolock; 00205 _xcb_in in; 00206 _xcb_out out; 00207 00208 /* misc data */ 00209 _xcb_ext ext; 00210 _xcb_xid xid; 00211 }; 00212 00213 void _xcb_conn_shutdown(xcb_connection_t *c, int err); 00214 00215 xcb_connection_t *_xcb_conn_ret_error(int err); 00216 00217 int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count); 00218 00219 00220 /* xcb_auth.c */ 00221 00222 int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display); 00223 00224 #ifdef GCC_HAS_VISIBILITY 00225 #pragma GCC visibility pop 00226 #endif 00227 00228 #endif