Merge from vendor branch OPENSSL:
[dragonfly.git] / contrib / bind-9.3 / lib / isc / include / isc / event.h
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1998-2002  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: event.h,v 1.24.2.2.8.2 2004/04/15 02:10:41 marka Exp $ */
19
20 #ifndef ISC_EVENT_H
21 #define ISC_EVENT_H 1
22
23 #include <isc/lang.h>
24 #include <isc/types.h>
25
26 /*****
27  ***** Events.
28  *****/
29
30 typedef void (*isc_eventdestructor_t)(isc_event_t *);
31
32 #define ISC_EVENT_COMMON(ltype)         \
33         size_t                          ev_size; \
34         unsigned int                    ev_attributes; \
35         void *                          ev_tag; \
36         isc_eventtype_t                 ev_type; \
37         isc_taskaction_t                ev_action; \
38         void *                          ev_arg; \
39         void *                          ev_sender; \
40         isc_eventdestructor_t           ev_destroy; \
41         void *                          ev_destroy_arg; \
42         ISC_LINK(ltype)                 ev_link
43
44 /*
45  * Attributes matching a mask of 0x000000ff are reserved for the task library's
46  * definition.  Attributes of 0xffffff00 may be used by the application
47  * or non-ISC libraries.
48  */
49 #define ISC_EVENTATTR_NOPURGE           0x00000001
50
51 /*
52  * The ISC_EVENTATTR_CANCELED attribute is intended to indicate
53  * that an event is delivered as a result of a canceled operation
54  * rather than successful completion, by mutual agreement
55  * between the sender and receiver.  It is not set or used by
56  * the task system.
57  */
58 #define ISC_EVENTATTR_CANCELED          0x00000002
59
60 #define ISC_EVENT_INIT(event, sz, at, ta, ty, ac, ar, sn, df, da) \
61 do { \
62         (event)->ev_size = (sz); \
63         (event)->ev_attributes = (at); \
64         (event)->ev_tag = (ta); \
65         (event)->ev_type = (ty); \
66         (event)->ev_action = (ac); \
67         (event)->ev_arg = (ar); \
68         (event)->ev_sender = (sn); \
69         (event)->ev_destroy = (df); \
70         (event)->ev_destroy_arg = (da); \
71         ISC_LINK_INIT((event), ev_link); \
72 } while (0)
73
74 /*
75  * This structure is public because "subclassing" it may be useful when
76  * defining new event types.
77  */
78 struct isc_event {
79         ISC_EVENT_COMMON(struct isc_event);
80 };
81
82 #define ISC_EVENTTYPE_FIRSTEVENT        0x00000000
83 #define ISC_EVENTTYPE_LASTEVENT         0xffffffff
84
85 #define ISC_EVENT_PTR(p) ((isc_event_t **)(void *)(p))
86
87 ISC_LANG_BEGINDECLS
88
89 isc_event_t *
90 isc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
91                    isc_taskaction_t action, const void *arg, size_t size);
92 /*
93  * Allocate and initialize in a structure with initial elements
94  * defined by:
95  *
96  *      struct {
97  *              ISC_EVENT_COMMON(struct isc_event);
98  *              ...
99  *      };
100  *      
101  * Requires:
102  *      'size' >= sizeof(struct isc_event)
103  *      'action' to be non NULL
104  *
105  * Returns:
106  *      a pointer to a initialized structure of the requested size.
107  *      NULL if unable to allocate memory.
108  */
109
110 void
111 isc_event_free(isc_event_t **);
112
113 ISC_LANG_ENDDECLS
114
115 #endif /* ISC_EVENT_H */