]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libevent/include/event2/rpc_struct.h
libevent: Import libevent 2.1.12
[FreeBSD/FreeBSD.git] / contrib / libevent / include / event2 / rpc_struct.h
1 /*
2  * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
3  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef EVENT2_RPC_STRUCT_H_INCLUDED_
28 #define EVENT2_RPC_STRUCT_H_INCLUDED_
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /** @file event2/rpc_struct.h
35
36   Structures used by rpc.h.  Using these structures directly may harm
37   forward compatibility: be careful!
38
39  */
40
41 /* Fix so that people don't have to run with <sys/queue.h> */
42 #ifndef TAILQ_ENTRY
43 #define EVENT_DEFINED_TQENTRY_
44 #define TAILQ_ENTRY(type)                                               \
45 struct {                                                                \
46         struct type *tqe_next;  /* next element */                      \
47         struct type **tqe_prev; /* address of previous next element */  \
48 }
49 #endif /* !TAILQ_ENTRY */
50
51 /**
52  * provides information about the completed RPC request.
53  */
54 struct evrpc_status {
55 #define EVRPC_STATUS_ERR_NONE           0
56 #define EVRPC_STATUS_ERR_TIMEOUT        1
57 #define EVRPC_STATUS_ERR_BADPAYLOAD     2
58 #define EVRPC_STATUS_ERR_UNSTARTED      3
59 #define EVRPC_STATUS_ERR_HOOKABORTED    4
60         int error;
61
62         /* for looking at headers or other information */
63         struct evhttp_request *http_req;
64 };
65
66 /* the structure below needs to be synchronized with evrpc_req_generic */
67
68 /* Encapsulates a request */
69 struct evrpc {
70         TAILQ_ENTRY(evrpc) next;
71
72         /* the URI at which the request handler lives */
73         const char* uri;
74
75         /* creates a new request structure */
76         void *(*request_new)(void *);
77         void *request_new_arg;
78
79         /* frees the request structure */
80         void (*request_free)(void *);
81
82         /* unmarshals the buffer into the proper request structure */
83         int (*request_unmarshal)(void *, struct evbuffer *);
84
85         /* creates a new reply structure */
86         void *(*reply_new)(void *);
87         void *reply_new_arg;
88
89         /* frees the reply structure */
90         void (*reply_free)(void *);
91
92         /* verifies that the reply is valid */
93         int (*reply_complete)(void *);
94
95         /* marshals the reply into a buffer */
96         void (*reply_marshal)(struct evbuffer*, void *);
97
98         /* the callback invoked for each received rpc */
99         void (*cb)(struct evrpc_req_generic *, void *);
100         void *cb_arg;
101
102         /* reference for further configuration */
103         struct evrpc_base *base;
104 };
105
106 #ifdef EVENT_DEFINED_TQENTRY_
107 #undef TAILQ_ENTRY
108 #endif
109
110 #ifdef __cplusplus
111 }
112 #endif
113
114 #endif /* EVENT2_RPC_STRUCT_H_INCLUDED_ */