xcb_reply.h revision ecce36be
1ecce36beSmrg/* 2ecce36beSmrg * Copyright (C) 2008 Julien Danjou <julien@danjou.info> 3ecce36beSmrg * 4ecce36beSmrg * Permission is hereby granted, free of charge, to any person 5ecce36beSmrg * obtaining a copy of this software and associated documentation 6ecce36beSmrg * files (the "Software"), to deal in the Software without 7ecce36beSmrg * restriction, including without limitation the rights to use, copy, 8ecce36beSmrg * modify, merge, publish, distribute, sublicense, and/or sell copies 9ecce36beSmrg * of the Software, and to permit persons to whom the Software is 10ecce36beSmrg * furnished to do so, subject to the following conditions: 11ecce36beSmrg * 12ecce36beSmrg * The above copyright notice and this permission notice shall be 13ecce36beSmrg * included in all copies or substantial portions of the Software. 14ecce36beSmrg * 15ecce36beSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16ecce36beSmrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17ecce36beSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18ecce36beSmrg * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 19ecce36beSmrg * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 20ecce36beSmrg * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21ecce36beSmrg * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22ecce36beSmrg * 23ecce36beSmrg * Except as contained in this notice, the names of the authors or 24ecce36beSmrg * their institutions shall not be used in advertising or otherwise to 25ecce36beSmrg * promote the sale, use or other dealings in this Software without 26ecce36beSmrg * prior written authorization from the authors. 27ecce36beSmrg */ 28ecce36beSmrg 29ecce36beSmrg/** 30ecce36beSmrg * @defgroup xcb__reply_t XCB Reply Functions 31ecce36beSmrg * 32ecce36beSmrg * These functions ease the usage of asynchronous possibility of XCB about 33ecce36beSmrg * the reply retrieve of sent requests. 34ecce36beSmrg * 35ecce36beSmrg * @{ 36ecce36beSmrg */ 37ecce36beSmrg 38ecce36beSmrg#ifndef __XCB_REPLY_H__ 39ecce36beSmrg#define __XCB_REPLY_H__ 40ecce36beSmrg 41ecce36beSmrg#include <xcb/xcb.h> 42ecce36beSmrg#include <pthread.h> 43ecce36beSmrg 44ecce36beSmrg#ifdef __cplusplus 45ecce36beSmrgextern "C" { 46ecce36beSmrg#endif 47ecce36beSmrg 48ecce36beSmrgtypedef void (*xcb_generic_reply_handler_t)(void *data, xcb_connection_t *c, xcb_generic_reply_t *reply, xcb_generic_error_t *error); 49ecce36beSmrg 50ecce36beSmrgstruct xcb_reply_node 51ecce36beSmrg{ 52ecce36beSmrg struct xcb_reply_node *next; 53ecce36beSmrg unsigned int request; 54ecce36beSmrg xcb_generic_reply_handler_t handler; 55ecce36beSmrg void *data; 56ecce36beSmrg char handled; 57ecce36beSmrg}; 58ecce36beSmrg 59ecce36beSmrgstruct xcb_reply_handlers 60ecce36beSmrg{ 61ecce36beSmrg pthread_mutex_t lock; 62ecce36beSmrg pthread_cond_t cond; 63ecce36beSmrg struct xcb_reply_node *head; 64ecce36beSmrg xcb_connection_t *c; 65ecce36beSmrg pthread_t thread; 66ecce36beSmrg}; 67ecce36beSmrg 68ecce36beSmrgtypedef struct xcb_reply_handlers xcb_reply_handlers_t; 69ecce36beSmrg 70ecce36beSmrg/** 71ecce36beSmrg * @brief Initialize a reply handlers structure. 72ecce36beSmrg * @param c The connection to the X server. 73ecce36beSmrg * @param h The reply handlers. 74ecce36beSmrg */ 75ecce36beSmrgvoid xcb_reply_handlers_init(xcb_connection_t *c, xcb_reply_handlers_t *h); 76ecce36beSmrg 77ecce36beSmrg/** 78ecce36beSmrg * @brief Get the connection to the X server used in reply handlers. 79ecce36beSmrg * @param h The reply handlers data structure. 80ecce36beSmrg * @return The connection to the X server. 81ecce36beSmrg */ 82ecce36beSmrgxcb_connection_t *xcb_reply_get_xcb_connection(xcb_reply_handlers_t *h); 83ecce36beSmrg 84ecce36beSmrg/** 85ecce36beSmrg * @brief Poll for reply using reply handlers. 86ecce36beSmrg * @param h The reply handlers data structure. 87ecce36beSmrg * @return The value return by the handler callback function, or 0 if no 88ecce36beSmrg * handler was found. 89ecce36beSmrg */ 90ecce36beSmrgint xcb_reply_poll_for_reply(xcb_reply_handlers_t *h); 91ecce36beSmrg 92ecce36beSmrg/** 93ecce36beSmrg * @brief Start reply handling thread. 94ecce36beSmrg * This thread will run forever until it is stop with xcb_reply_stop_thread. 95ecce36beSmrg * @param h The reply handlers. 96ecce36beSmrg */ 97ecce36beSmrgvoid xcb_reply_start_thread(xcb_reply_handlers_t *h); 98ecce36beSmrg 99ecce36beSmrg/** 100ecce36beSmrg * @brief Stop reply handling thread. 101ecce36beSmrg * @param h The reply handlers. 102ecce36beSmrg */ 103ecce36beSmrgvoid xcb_reply_stop_thread(xcb_reply_handlers_t *h); 104ecce36beSmrg 105ecce36beSmrg/** 106ecce36beSmrg * @brief Add a reply handler. 107ecce36beSmrg * @param h The reply handlers data structure to fill. 108ecce36beSmrg * @param request The request identifier. 109ecce36beSmrg * @param handler The handler to call for this request. 110ecce36beSmrg * @param data Optional data passed to the callback function handling request. 111ecce36beSmrg */ 112ecce36beSmrgvoid xcb_reply_add_handler(xcb_reply_handlers_t *h, unsigned int request, xcb_generic_reply_handler_t handler, void *data); 113ecce36beSmrg 114ecce36beSmrg#ifdef __cplusplus 115ecce36beSmrg} 116ecce36beSmrg#endif 117ecce36beSmrg 118ecce36beSmrg/** 119ecce36beSmrg * @} 120ecce36beSmrg */ 121ecce36beSmrg 122ecce36beSmrg#endif /* __XCB_REPLY_H__ */ 123