XCB
1.9.3
|
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 void (*xcb_return_socket_func_t)(void *closure); 00083 00084 #if HAVE_SENDMSG 00085 #define XCB_MAX_PASS_FD 16 00086 00087 typedef struct _xcb_fd { 00088 int fd[XCB_MAX_PASS_FD]; 00089 int nfd; 00090 int ifd; 00091 } _xcb_fd; 00092 #endif 00093 00094 typedef struct _xcb_out { 00095 pthread_cond_t cond; 00096 int writing; 00097 00098 pthread_cond_t socket_cond; 00099 void (*return_socket)(void *closure); 00100 void *socket_closure; 00101 int socket_moving; 00102 00103 char queue[XCB_QUEUE_BUFFER_SIZE]; 00104 int queue_len; 00105 00106 uint64_t request; 00107 uint64_t request_written; 00108 00109 pthread_mutex_t reqlenlock; 00110 enum lazy_reply_tag maximum_request_length_tag; 00111 union { 00112 xcb_big_requests_enable_cookie_t cookie; 00113 uint32_t value; 00114 } maximum_request_length; 00115 #if HAVE_SENDMSG 00116 _xcb_fd out_fd; 00117 #endif 00118 } _xcb_out; 00119 00120 int _xcb_out_init(_xcb_out *out); 00121 void _xcb_out_destroy(_xcb_out *out); 00122 00123 int _xcb_out_send(xcb_connection_t *c, struct iovec *vector, int count); 00124 void _xcb_out_send_sync(xcb_connection_t *c); 00125 int _xcb_out_flush_to(xcb_connection_t *c, uint64_t request); 00126 00127 00128 /* xcb_in.c */ 00129 00130 typedef struct _xcb_in { 00131 pthread_cond_t event_cond; 00132 int reading; 00133 00134 char queue[4096]; 00135 int queue_len; 00136 00137 uint64_t request_expected; 00138 uint64_t request_read; 00139 uint64_t request_completed; 00140 struct reply_list *current_reply; 00141 struct reply_list **current_reply_tail; 00142 00143 _xcb_map *replies; 00144 struct event_list *events; 00145 struct event_list **events_tail; 00146 struct reader_list *readers; 00147 00148 struct pending_reply *pending_replies; 00149 struct pending_reply **pending_replies_tail; 00150 #if HAVE_SENDMSG 00151 _xcb_fd in_fd; 00152 #endif 00153 struct xcb_special_event *special_events; 00154 } _xcb_in; 00155 00156 int _xcb_in_init(_xcb_in *in); 00157 void _xcb_in_destroy(_xcb_in *in); 00158 00159 void _xcb_in_wake_up_next_reader(xcb_connection_t *c); 00160 00161 int _xcb_in_expect_reply(xcb_connection_t *c, uint64_t request, enum workarounds workaround, int flags); 00162 void _xcb_in_replies_done(xcb_connection_t *c); 00163 00164 int _xcb_in_read(xcb_connection_t *c); 00165 int _xcb_in_read_block(xcb_connection_t *c, void *buf, int nread); 00166 00167 00168 /* xcb_xid.c */ 00169 00170 typedef struct _xcb_xid { 00171 pthread_mutex_t lock; 00172 uint32_t last; 00173 uint32_t base; 00174 uint32_t max; 00175 uint32_t inc; 00176 } _xcb_xid; 00177 00178 int _xcb_xid_init(xcb_connection_t *c); 00179 void _xcb_xid_destroy(xcb_connection_t *c); 00180 00181 00182 /* xcb_ext.c */ 00183 00184 typedef struct _xcb_ext { 00185 pthread_mutex_t lock; 00186 struct lazyreply *extensions; 00187 int extensions_size; 00188 } _xcb_ext; 00189 00190 int _xcb_ext_init(xcb_connection_t *c); 00191 void _xcb_ext_destroy(xcb_connection_t *c); 00192 00193 00194 /* xcb_conn.c */ 00195 00196 struct xcb_connection_t { 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