~ubuntu-branches/ubuntu/wily/xcb-util/wily-proposed

« back to all changes in this revision

Viewing changes to reply/xcb_reply.h

  • Committer: Bazaar Package Importer
  • Author(s): Julien Danjou
  • Date: 2009-02-15 12:58:13 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090215125813-fvdfqrch1341t8bd
Tags: 0.3.3-2
Add versioned link to GPL.

Show diffs side-by-side

added added

removed removed

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