ondestroy.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2000, 2001  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: ondestroy.h,v 1.14 2007/06/19 23:47:18 tbox Exp $ */
00019 
00020 #ifndef ISC_ONDESTROY_H
00021 #define ISC_ONDESTROY_H 1
00022 
00023 #include <isc/lang.h>
00024 #include <isc/types.h>
00025 
00026 ISC_LANG_BEGINDECLS
00027 
00028 /*! \file isc/ondestroy.h
00029  * ondestroy handling.
00030  *
00031  * Any class ``X'' of objects that wants to send out notifications
00032  * on its destruction should declare a field of type isc_ondestroy_t
00033  * (call it 'ondest').
00034  *
00035  * \code
00036  *      typedef struct {
00037  *              ...
00038  *              isc_ondestroy_t ondest;
00039  *              ...
00040  *      } X;
00041  * \endcode
00042  *
00043  * When an object ``A'' of type X is created
00044  * it must initialize the field ondest with a call to
00045  *
00046  * \code
00047  *      isc_ondestroy_init(&A->ondest).
00048  * \endcode
00049  *
00050  * X should also provide a registration function for third-party
00051  * objects to call to register their interest in being told about
00052  * the destruction of a particular instance of X.
00053  *
00054  * \code
00055  *      isc_result_t
00056  *      X_ondestroy(X *instance, isc_task_t *task,
00057  *                   isc_event_t **eventp) {
00058  *              return(isc_ondestroy_register(&instance->ondest, task,eventp));
00059  *      }
00060  * \endcode
00061  *
00062  *      Note: locking of the ondestory structure embedded inside of X, is
00063  *      X's responsibility.
00064  *
00065  * When an instance of X is destroyed, a call to  isc_ondestroy_notify()
00066  * sends the notifications:
00067  *
00068  * \code
00069  *      X *instance;
00070  *      isc_ondestroy_t ondest = instance->ondest;
00071  *
00072  *      ... completely cleanup 'instance' here...
00073  *
00074  *      isc_ondestroy_notify(&ondest, instance);
00075  * \endcode
00076  *
00077  *
00078  * see lib/dns/zone.c for an ifdef'd-out example.
00079  */
00080 
00081 struct isc_ondestroy {
00082         unsigned int magic;
00083         isc_eventlist_t events;
00084 };
00085 
00086 void
00087 isc_ondestroy_init(isc_ondestroy_t *ondest);
00088 /*%<
00089  * Initialize the on ondest structure. *must* be called before first call
00090  * to isc_ondestroy_register().
00091  */
00092 
00093 isc_result_t
00094 isc_ondestroy_register(isc_ondestroy_t *ondest, isc_task_t *task,
00095                        isc_event_t **eventp);
00096 
00097 /*%<
00098  * Stores task and *eventp away inside *ondest.  Ownership of **event is
00099  * taken from the caller (and *eventp is set to NULL). The task is attached
00100  * to.
00101  */
00102 
00103 void
00104 isc_ondestroy_notify(isc_ondestroy_t *ondest, void *sender);
00105 /*%<
00106  * Dispatches the event(s) to the task(s) that were given in
00107  * isc_ondestroy_register call(s) (done via calls to
00108  * isc_task_sendanddetach()).  Before dispatch, the sender value of each
00109  * event structure is set to the value of the sender paramater. The
00110  * internal structures of the ondest parameter are cleaned out, so no other
00111  * cleanup is needed.
00112  */
00113 
00114 ISC_LANG_ENDDECLS
00115 
00116 #endif /* ISC_ONDESTROY_H */

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