Annotation of embedaddon/dhcp/dhcpctl/callback.c, revision 1.1
1.1 ! misho 1: /* callback.c
! 2:
! 3: The dhcpctl callback object. */
! 4:
! 5: /*
! 6: * Copyright (c) 2004,2007,2009 by Internet Systems Consortium, Inc. ("ISC")
! 7: * Copyright (c) 1999-2003 by Internet Software Consortium
! 8: *
! 9: * Permission to use, copy, modify, and distribute this software for any
! 10: * purpose with or without fee is hereby granted, provided that the above
! 11: * copyright notice and this permission notice appear in all copies.
! 12: *
! 13: * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
! 14: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
! 15: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
! 16: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
! 17: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
! 18: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
! 19: * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
! 20: *
! 21: * Internet Systems Consortium, Inc.
! 22: * 950 Charter Street
! 23: * Redwood City, CA 94063
! 24: * <info@isc.org>
! 25: * https://www.isc.org/
! 26: *
! 27: * This software has been written for Internet Systems Consortium
! 28: * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
! 29: * To learn more about Internet Systems Consortium, see
! 30: * ``https://www.isc.org/''. To learn more about Vixie Enterprises,
! 31: * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
! 32: * ``http://www.nominum.com''.
! 33: */
! 34:
! 35: #include "dhcpd.h"
! 36: #include <omapip/omapip_p.h>
! 37: #include "dhcpctl.h"
! 38:
! 39: /* dhcpctl_set_callback
! 40:
! 41: synchronous, with asynchronous aftereffect
! 42: handle is some object upon which some kind of process has been
! 43: started - e.g., an open, an update or a refresh.
! 44: data is an anonymous pointer containing some information that
! 45: the callback will use to figure out what event completed.
! 46: return value of 0 means callback was successfully set, a nonzero
! 47: status code is returned otherwise.
! 48: Upon completion of whatever task is in process, the callback
! 49: will be passed the handle to the object, a status code
! 50: indicating what happened, and the anonymous pointer passed to */
! 51:
! 52: dhcpctl_status dhcpctl_set_callback (dhcpctl_handle h, void *data,
! 53: void (*func) (dhcpctl_handle,
! 54: dhcpctl_status, void *))
! 55: {
! 56: dhcpctl_callback_object_t *callback;
! 57: omapi_object_t *inner;
! 58:
! 59: callback = dmalloc (sizeof *callback, MDL);
! 60: if (!callback)
! 61: return ISC_R_NOMEMORY;
! 62:
! 63: /* Tie the callback object to the innermost object in the chain. */
! 64: for (inner = h; inner -> inner; inner = inner -> inner)
! 65: ;
! 66: omapi_object_reference (&inner -> inner,
! 67: (omapi_object_t *)callback, MDL);
! 68: omapi_object_reference ((omapi_object_t **)&callback -> outer,
! 69: inner, MDL);
! 70:
! 71: /* Save the actual handle pointer we were passed for the callback. */
! 72: omapi_object_reference (&callback -> object, h, MDL);
! 73: callback -> data = data;
! 74: callback -> callback = func;
! 75:
! 76: return ISC_R_SUCCESS;
! 77: }
! 78:
! 79: /* Callback methods (not meant to be called directly) */
! 80:
! 81: isc_result_t dhcpctl_callback_set_value (omapi_object_t *h,
! 82: omapi_object_t *id,
! 83: omapi_data_string_t *name,
! 84: omapi_typed_data_t *value)
! 85: {
! 86: if (h -> type != dhcpctl_callback_type)
! 87: return ISC_R_INVALIDARG;
! 88:
! 89: if (h -> inner && h -> inner -> type -> set_value)
! 90: return (*(h -> inner -> type -> set_value))
! 91: (h -> inner, id, name, value);
! 92: return ISC_R_NOTFOUND;
! 93: }
! 94:
! 95: isc_result_t dhcpctl_callback_get_value (omapi_object_t *h,
! 96: omapi_object_t *id,
! 97: omapi_data_string_t *name,
! 98: omapi_value_t **value)
! 99: {
! 100: if (h -> type != dhcpctl_callback_type)
! 101: return ISC_R_INVALIDARG;
! 102:
! 103: if (h -> inner && h -> inner -> type -> get_value)
! 104: return (*(h -> inner -> type -> get_value))
! 105: (h -> inner, id, name, value);
! 106: return ISC_R_NOTFOUND;
! 107: }
! 108:
! 109: isc_result_t dhcpctl_callback_signal_handler (omapi_object_t *o,
! 110: const char *name, va_list ap)
! 111: {
! 112: dhcpctl_callback_object_t *p;
! 113: isc_result_t waitstatus;
! 114:
! 115: if (o -> type != dhcpctl_callback_type)
! 116: return ISC_R_INVALIDARG;
! 117: p = (dhcpctl_callback_object_t *)o;
! 118:
! 119: /* Not a signal we recognize? */
! 120: if (strcmp (name, "ready")) {
! 121: if (p -> inner && p -> inner -> type -> signal_handler)
! 122: return (*(p -> inner -> type -> signal_handler))
! 123: (p -> inner, name, ap);
! 124: return ISC_R_NOTFOUND;
! 125: }
! 126:
! 127: if (p -> object -> type == dhcpctl_remote_type) {
! 128: waitstatus = (((dhcpctl_remote_object_t *)
! 129: (p -> object)) -> waitstatus);
! 130: } else
! 131: waitstatus = ISC_R_SUCCESS;
! 132:
! 133: /* Do the callback. */
! 134: if (p -> callback)
! 135: (*(p -> callback)) (p -> object, waitstatus, p -> data);
! 136:
! 137: return ISC_R_SUCCESS;
! 138: }
! 139:
! 140: isc_result_t dhcpctl_callback_destroy (omapi_object_t *h,
! 141: const char *file, int line)
! 142: {
! 143: dhcpctl_callback_object_t *p;
! 144: if (h -> type != dhcpctl_callback_type)
! 145: return ISC_R_INVALIDARG;
! 146: p = (dhcpctl_callback_object_t *)h;
! 147: if (p -> handle)
! 148: omapi_object_dereference ((omapi_object_t **)&p -> handle,
! 149: file, line);
! 150: return ISC_R_SUCCESS;
! 151: }
! 152:
! 153: /* Write all the published values associated with the object through the
! 154: specified connection. */
! 155:
! 156: isc_result_t dhcpctl_callback_stuff_values (omapi_object_t *c,
! 157: omapi_object_t *id,
! 158: omapi_object_t *p)
! 159: {
! 160: if (p -> type != dhcpctl_callback_type)
! 161: return ISC_R_INVALIDARG;
! 162:
! 163: if (p -> inner && p -> inner -> type -> stuff_values)
! 164: return (*(p -> inner -> type -> stuff_values)) (c, id,
! 165: p -> inner);
! 166: return ISC_R_SUCCESS;
! 167: }
! 168:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>