Home | History | Annotate | Line # | Download | only in isc
      1 /*	$NetBSD: event.h,v 1.1 2024/02/18 20:57:52 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5  *
      6  * SPDX-License-Identifier: MPL-2.0
      7  *
      8  * This Source Code Form is subject to the terms of the Mozilla Public
      9  * License, v. 2.0. If a copy of the MPL was not distributed with this
     10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
     11  *
     12  * See the COPYRIGHT file distributed with this work for additional
     13  * information regarding copyright ownership.
     14  */
     15 
     16 #ifndef ISC_EVENT_H
     17 #define ISC_EVENT_H 1
     18 
     19 /*! \file isc/event.h */
     20 
     21 #include <isc/lang.h>
     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, da) \
     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 		(event)->ev_destroy_arg = (da);                   \
     70 		ISC_LINK_INIT((event), ev_link);                  \
     71 		ISC_LINK_INIT((event), ev_ratelink);              \
     72 	} while (0)
     73 
     74 /*%
     75  * This structure is public because "subclassing" it may be useful when
     76  * defining new event types.
     77  */
     78 struct isc_event {
     79 	ISC_EVENT_COMMON(struct isc_event);
     80 };
     81 
     82 #define ISC_EVENTTYPE_FIRSTEVENT 0x00000000
     83 #define ISC_EVENTTYPE_LASTEVENT	 0xffffffff
     84 
     85 #define ISC_EVENT_PTR(p) ((isc_event_t **)(void *)(p))
     86 
     87 ISC_LANG_BEGINDECLS
     88 
     89 isc_event_t *
     90 isc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
     91 		   isc_taskaction_t action, void *arg, size_t size);
     92 isc_event_t *
     93 isc_event_constallocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
     94 			isc_taskaction_t action, const void *arg, size_t size);
     95 /*%<
     96  * Allocate an event structure.
     97  *
     98  * Allocate and initialize in a structure with initial elements
     99  * defined by:
    100  *
    101  * \code
    102  *	struct {
    103  *		ISC_EVENT_COMMON(struct isc_event);
    104  *		...
    105  *	};
    106  * \endcode
    107  *
    108  * Requires:
    109  *\li	'size' >= sizeof(struct isc_event)
    110  *\li	'action' to be non NULL
    111  *
    112  * Returns:
    113  *\li	a pointer to a initialized structure of the requested size.
    114  *\li	NULL if unable to allocate memory.
    115  */
    116 
    117 void
    118 isc_event_free(isc_event_t **);
    119 
    120 ISC_LANG_ENDDECLS
    121 
    122 #endif /* ISC_EVENT_H */
    123