1 /* 2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 7 * 8 * See the COPYRIGHT file distributed with this work for additional 9 * information regarding copyright ownership. 10 */ 11 12 #ifndef ISC_EVENT_H 13 #define ISC_EVENT_H 1 14 15 /*! \file isc/event.h */ 16 17 #include <isc/lang.h> 18 #include <isc/types.h> 19 20 /***** 21 ***** Events. 22 *****/ 23 24 typedef void (*isc_eventdestructor_t)(isc_event_t *); 25 26 #define ISC_EVENT_COMMON(ltype) \ 27 size_t ev_size; \ 28 unsigned int ev_attributes; \ 29 void * ev_tag; \ 30 isc_eventtype_t ev_type; \ 31 isc_taskaction_t ev_action; \ 32 void * ev_arg; \ 33 void * ev_sender; \ 34 isc_eventdestructor_t ev_destroy; \ 35 void * ev_destroy_arg; \ 36 ISC_LINK(ltype) ev_link; \ 37 ISC_LINK(ltype) ev_ratelink 38 39 /*% 40 * Attributes matching a mask of 0x000000ff are reserved for the task library's 41 * definition. Attributes of 0xffffff00 may be used by the application 42 * or non-ISC libraries. 43 */ 44 #define ISC_EVENTATTR_NOPURGE 0x00000001 45 46 /*% 47 * The ISC_EVENTATTR_CANCELED attribute is intended to indicate 48 * that an event is delivered as a result of a canceled operation 49 * rather than successful completion, by mutual agreement 50 * between the sender and receiver. It is not set or used by 51 * the task system. 52 */ 53 #define ISC_EVENTATTR_CANCELED 0x00000002 54 55 #define ISC_EVENT_INIT(event, sz, at, ta, ty, ac, ar, sn, df, da) \ 56 do { \ 57 (event)->ev_size = (sz); \ 58 (event)->ev_attributes = (at); \ 59 (event)->ev_tag = (ta); \ 60 (event)->ev_type = (ty); \ 61 (event)->ev_action = (ac); \ 62 (event)->ev_arg = (ar); \ 63 (event)->ev_sender = (sn); \ 64 (event)->ev_destroy = (df); \ 65 (event)->ev_destroy_arg = (da); \ 66 ISC_LINK_INIT((event), ev_link); \ 67 ISC_LINK_INIT((event), ev_ratelink); \ 68 } while (0) 69 70 /*% 71 * This structure is public because "subclassing" it may be useful when 72 * defining new event types. 73 */ 74 struct isc_event { 75 ISC_EVENT_COMMON(struct isc_event); 76 }; 77 78 #define ISC_EVENTTYPE_FIRSTEVENT 0x00000000 79 #define ISC_EVENTTYPE_LASTEVENT 0xffffffff 80 81 #define ISC_EVENT_PTR(p) ((isc_event_t **)(void *)(p)) 82 83 ISC_LANG_BEGINDECLS 84 85 isc_event_t * 86 isc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type, 87 isc_taskaction_t action, void *arg, size_t size); 88 isc_event_t * 89 isc_event_constallocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type, 90 isc_taskaction_t action, const void *arg, size_t size); 91 /*%< 92 * Allocate an event structure. 93 * 94 * Allocate and initialize in a structure with initial elements 95 * defined by: 96 * 97 * \code 98 * struct { 99 * ISC_EVENT_COMMON(struct isc_event); 100 * ... 101 * }; 102 * \endcode 103 * 104 * Requires: 105 *\li 'size' >= sizeof(struct isc_event) 106 *\li 'action' to be non NULL 107 * 108 * Returns: 109 *\li a pointer to a initialized structure of the requested size. 110 *\li NULL if unable to allocate memory. 111 */ 112 113 void 114 isc_event_free(isc_event_t **); 115 116 ISC_LANG_ENDDECLS 117 118 #endif /* ISC_EVENT_H */ 119