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