1135446Strhodes/*
2193149Sdougb * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
3135446Strhodes * Copyright (C) 1998-2002  Internet Software Consortium.
4135446Strhodes *
5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any
6135446Strhodes * purpose with or without fee is hereby granted, provided that the above
7135446Strhodes * copyright notice and this permission notice appear in all copies.
8135446Strhodes *
9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11135446Strhodes * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15135446Strhodes * PERFORMANCE OF THIS SOFTWARE.
16135446Strhodes */
17135446Strhodes
18234010Sdougb/* $Id: event.h,v 1.34 2007/06/19 23:47:18 tbox Exp $ */
19135446Strhodes
20135446Strhodes#ifndef ISC_EVENT_H
21135446Strhodes#define ISC_EVENT_H 1
22135446Strhodes
23193149Sdougb/*! \file isc/event.h */
24170222Sdougb
25135446Strhodes#include <isc/lang.h>
26135446Strhodes#include <isc/types.h>
27135446Strhodes
28135446Strhodes/*****
29135446Strhodes ***** Events.
30135446Strhodes *****/
31135446Strhodes
32135446Strhodestypedef void (*isc_eventdestructor_t)(isc_event_t *);
33135446Strhodes
34135446Strhodes#define ISC_EVENT_COMMON(ltype)		\
35135446Strhodes	size_t				ev_size; \
36135446Strhodes	unsigned int			ev_attributes; \
37135446Strhodes	void *				ev_tag; \
38135446Strhodes	isc_eventtype_t			ev_type; \
39135446Strhodes	isc_taskaction_t		ev_action; \
40135446Strhodes	void *				ev_arg; \
41135446Strhodes	void *				ev_sender; \
42135446Strhodes	isc_eventdestructor_t		ev_destroy; \
43135446Strhodes	void *				ev_destroy_arg; \
44135446Strhodes	ISC_LINK(ltype)			ev_link
45135446Strhodes
46170222Sdougb/*%
47135446Strhodes * Attributes matching a mask of 0x000000ff are reserved for the task library's
48135446Strhodes * definition.  Attributes of 0xffffff00 may be used by the application
49135446Strhodes * or non-ISC libraries.
50135446Strhodes */
51135446Strhodes#define ISC_EVENTATTR_NOPURGE		0x00000001
52135446Strhodes
53170222Sdougb/*%
54135446Strhodes * The ISC_EVENTATTR_CANCELED attribute is intended to indicate
55135446Strhodes * that an event is delivered as a result of a canceled operation
56135446Strhodes * rather than successful completion, by mutual agreement
57135446Strhodes * between the sender and receiver.  It is not set or used by
58135446Strhodes * the task system.
59135446Strhodes */
60135446Strhodes#define ISC_EVENTATTR_CANCELED		0x00000002
61135446Strhodes
62135446Strhodes#define ISC_EVENT_INIT(event, sz, at, ta, ty, ac, ar, sn, df, da) \
63135446Strhodesdo { \
64135446Strhodes	(event)->ev_size = (sz); \
65135446Strhodes	(event)->ev_attributes = (at); \
66135446Strhodes	(event)->ev_tag = (ta); \
67135446Strhodes	(event)->ev_type = (ty); \
68135446Strhodes	(event)->ev_action = (ac); \
69135446Strhodes	(event)->ev_arg = (ar); \
70135446Strhodes	(event)->ev_sender = (sn); \
71135446Strhodes	(event)->ev_destroy = (df); \
72135446Strhodes	(event)->ev_destroy_arg = (da); \
73135446Strhodes	ISC_LINK_INIT((event), ev_link); \
74135446Strhodes} while (0)
75135446Strhodes
76170222Sdougb/*%
77135446Strhodes * This structure is public because "subclassing" it may be useful when
78135446Strhodes * defining new event types.
79135446Strhodes */
80135446Strhodesstruct isc_event {
81135446Strhodes	ISC_EVENT_COMMON(struct isc_event);
82135446Strhodes};
83135446Strhodes
84135446Strhodes#define ISC_EVENTTYPE_FIRSTEVENT	0x00000000
85135446Strhodes#define ISC_EVENTTYPE_LASTEVENT		0xffffffff
86135446Strhodes
87135446Strhodes#define ISC_EVENT_PTR(p) ((isc_event_t **)(void *)(p))
88135446Strhodes
89135446StrhodesISC_LANG_BEGINDECLS
90135446Strhodes
91135446Strhodesisc_event_t *
92135446Strhodesisc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
93135446Strhodes		   isc_taskaction_t action, const void *arg, size_t size);
94170222Sdougb/*%<
95170222Sdougb * Allocate an event structure.
96170222Sdougb *
97135446Strhodes * Allocate and initialize in a structure with initial elements
98135446Strhodes * defined by:
99135446Strhodes *
100170222Sdougb * \code
101135446Strhodes *	struct {
102135446Strhodes *		ISC_EVENT_COMMON(struct isc_event);
103135446Strhodes *		...
104135446Strhodes *	};
105170222Sdougb * \endcode
106135446Strhodes *
107135446Strhodes * Requires:
108170222Sdougb *\li	'size' >= sizeof(struct isc_event)
109170222Sdougb *\li	'action' to be non NULL
110135446Strhodes *
111135446Strhodes * Returns:
112170222Sdougb *\li	a pointer to a initialized structure of the requested size.
113170222Sdougb *\li	NULL if unable to allocate memory.
114135446Strhodes */
115135446Strhodes
116135446Strhodesvoid
117135446Strhodesisc_event_free(isc_event_t **);
118135446Strhodes
119135446StrhodesISC_LANG_ENDDECLS
120135446Strhodes
121135446Strhodes#endif /* ISC_EVENT_H */
122