1 /* $NetBSD: event.h,v 1.6 2014/12/10 04:38:00 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2004-2007, 2014 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 34 typedef 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) \ 65 do { \ 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 (/*CONSTCOND*/0) 77 78 /*% 79 * This structure is public because "subclassing" it may be useful when 80 * defining new event types. 81 */ 82 struct 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 91 ISC_LANG_BEGINDECLS 92 93 isc_event_t * 94 isc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type, 95 isc_taskaction_t action, void *arg, size_t size); 96 isc_event_t * 97 isc_event_constallocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type, 98 isc_taskaction_t action, const void *arg, size_t size); 99 /*%< 100 * Allocate an event structure. 101 * 102 * Allocate and initialize in a structure with initial elements 103 * defined by: 104 * 105 * \code 106 * struct { 107 * ISC_EVENT_COMMON(struct isc_event); 108 * ... 109 * }; 110 * \endcode 111 * 112 * Requires: 113 *\li 'size' >= sizeof(struct isc_event) 114 *\li 'action' to be non NULL 115 * 116 * Returns: 117 *\li a pointer to a initialized structure of the requested size. 118 *\li NULL if unable to allocate memory. 119 */ 120 121 void 122 isc_event_free(isc_event_t **); 123 124 ISC_LANG_ENDDECLS 125 126 #endif /* ISC_EVENT_H */ 127