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