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