event.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2007, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1998-2002  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: event.h,v 1.34 2007/06/19 23:47:18 tbox Exp $ */
00019 
00020 #ifndef ISC_EVENT_H
00021 #define ISC_EVENT_H 1
00022 
00023 /*! \file isc/event.h */
00024 
00025 #include <isc/lang.h>
00026 #include <isc/types.h>
00027 
00028 /*****
00029  ***** Events.
00030  *****/
00031 
00032 typedef void (*isc_eventdestructor_t)(isc_event_t *);
00033 
00034 #define ISC_EVENT_COMMON(ltype)         \
00035         size_t                          ev_size; \
00036         unsigned int                    ev_attributes; \
00037         void *                          ev_tag; \
00038         isc_eventtype_t                 ev_type; \
00039         isc_taskaction_t                ev_action; \
00040         void *                          ev_arg; \
00041         void *                          ev_sender; \
00042         isc_eventdestructor_t           ev_destroy; \
00043         void *                          ev_destroy_arg; \
00044         ISC_LINK(ltype)                 ev_link
00045 
00046 /*%
00047  * Attributes matching a mask of 0x000000ff are reserved for the task library's
00048  * definition.  Attributes of 0xffffff00 may be used by the application
00049  * or non-ISC libraries.
00050  */
00051 #define ISC_EVENTATTR_NOPURGE           0x00000001
00052 
00053 /*%
00054  * The ISC_EVENTATTR_CANCELED attribute is intended to indicate
00055  * that an event is delivered as a result of a canceled operation
00056  * rather than successful completion, by mutual agreement
00057  * between the sender and receiver.  It is not set or used by
00058  * the task system.
00059  */
00060 #define ISC_EVENTATTR_CANCELED          0x00000002
00061 
00062 #define ISC_EVENT_INIT(event, sz, at, ta, ty, ac, ar, sn, df, da) \
00063 do { \
00064         (event)->ev_size = (sz); \
00065         (event)->ev_attributes = (at); \
00066         (event)->ev_tag = (ta); \
00067         (event)->ev_type = (ty); \
00068         (event)->ev_action = (ac); \
00069         (event)->ev_arg = (ar); \
00070         (event)->ev_sender = (sn); \
00071         (event)->ev_destroy = (df); \
00072         (event)->ev_destroy_arg = (da); \
00073         ISC_LINK_INIT((event), ev_link); \
00074 } while (0)
00075 
00076 /*%
00077  * This structure is public because "subclassing" it may be useful when
00078  * defining new event types.
00079  */
00080 struct isc_event {
00081         ISC_EVENT_COMMON(struct isc_event);
00082 };
00083 
00084 #define ISC_EVENTTYPE_FIRSTEVENT        0x00000000
00085 #define ISC_EVENTTYPE_LASTEVENT         0xffffffff
00086 
00087 #define ISC_EVENT_PTR(p) ((isc_event_t **)(void *)(p))
00088 
00089 ISC_LANG_BEGINDECLS
00090 
00091 isc_event_t *
00092 isc_event_allocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
00093                    isc_taskaction_t action, void *arg, size_t size);
00094 isc_event_t *
00095 isc_event_constallocate(isc_mem_t *mctx, void *sender, isc_eventtype_t type,
00096                         isc_taskaction_t action, const void *arg, size_t size);
00097 /*%<
00098  * Allocate an event structure.
00099  *
00100  * Allocate and initialize in a structure with initial elements
00101  * defined by:
00102  *
00103  * \code
00104  *      struct {
00105  *              ISC_EVENT_COMMON(struct isc_event);
00106  *              ...
00107  *      };
00108  * \endcode
00109  *
00110  * Requires:
00111  *\li   'size' >= sizeof(struct isc_event)
00112  *\li   'action' to be non NULL
00113  *
00114  * Returns:
00115  *\li   a pointer to a initialized structure of the requested size.
00116  *\li   NULL if unable to allocate memory.
00117  */
00118 
00119 void
00120 isc_event_free(isc_event_t **);
00121 
00122 ISC_LANG_ENDDECLS
00123 
00124 #endif /* ISC_EVENT_H */

Generated on Tue Apr 28 17:41:04 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha