XCB
1.7
|
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 #define XCB_SEQUENCE_COMPARE_32(a,op,b) (((int) (a) - (int) (b)) op 0) 00058 00059 #ifndef offsetof 00060 #define offsetof(type,member) ((size_t) &((type *)0)->member) 00061 #endif 00062 00063 #ifndef MIN 00064 #define MIN(x,y) ((x) < (y) ? (x) : (y)) 00065 #endif 00066 00067 #define container_of(pointer,type,member) ((type *)(((char *)(pointer)) - offsetof(type, member))) 00068 00069 /* xcb_list.c */ 00070 00071 typedef void (*xcb_list_free_func_t)(void *); 00072 00073 typedef struct _xcb_map _xcb_map; 00074 00075 _xcb_map *_xcb_map_new(void); 00076 void _xcb_map_delete(_xcb_map *q, xcb_list_free_func_t do_free); 00077 int _xcb_map_put(_xcb_map *q, unsigned int key, void *data); 00078 void *_xcb_map_remove(_xcb_map *q, unsigned int key); 00079 00080 00081 /* xcb_out.c */ 00082 00083 typedef struct _xcb_out { 00084 pthread_cond_t cond; 00085 int writing; 00086 00087 pthread_cond_t socket_cond; 00088 void (*return_socket)(void *closure); 00089 void *socket_closure; 00090 int socket_moving; 00091 00092 char queue[XCB_QUEUE_BUFFER_SIZE]; 00093 int queue_len; 00094 00095 uint64_t request; 00096 uint64_t request_written; 00097 00098 pthread_mutex_t reqlenlock; 00099 enum lazy_reply_tag maximum_request_length_tag; 00100 union { 00101 xcb_big_requests_enable_cookie_t cookie; 00102 uint32_t value; 00103 } maximum_request_length; 00104 } _xcb_out; 00105 00106 int _xcb_out_init(_xcb_out *out); 00107 void _xcb_out_destroy(_xcb_out *out); 00108 00109 int _xcb_out_send(xcb_connection_t *c, struct iovec *vector, int count); 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); 00195 int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count); 00196 00197 00198 /* xcb_auth.c */ 00199 00200 int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display); 00201 00202 #ifdef GCC_HAS_VISIBILITY 00203 #pragma GCC visibility pop 00204 #endif 00205 00206 #endif