3 The dhcpctl callback object. */
6 * Copyright (c) 1999-2002 Internet Software Consortium.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of The Internet Software Consortium nor the names
19 * of its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * This software has been written for the Internet Software Consortium
37 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
38 * To learn more about the Internet Software Consortium, see
39 * ``http://www.isc.org/''. To learn more about Vixie Enterprises,
40 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
41 * ``http://www.nominum.com''.
44 #include <omapip/omapip_p.h>
47 /* dhcpctl_set_callback
49 synchronous, with asynchronous aftereffect
50 handle is some object upon which some kind of process has been
51 started - e.g., an open, an update or a refresh.
52 data is an anonymous pointer containing some information that
53 the callback will use to figure out what event completed.
54 return value of 0 means callback was successfully set, a nonzero
55 status code is returned otherwise.
56 Upon completion of whatever task is in process, the callback
57 will be passed the handle to the object, a status code
58 indicating what happened, and the anonymous pointer passed to */
60 dhcpctl_status dhcpctl_set_callback (dhcpctl_handle h, void *data,
61 void (*func) (dhcpctl_handle,
62 dhcpctl_status, void *))
64 dhcpctl_callback_object_t *callback;
65 omapi_object_t *inner;
68 callback = dmalloc (sizeof *callback, MDL);
70 return ISC_R_NOMEMORY;
72 /* Tie the callback object to the innermost object in the chain. */
73 for (inner = h; inner -> inner; inner = inner -> inner)
75 omapi_object_reference (&inner -> inner,
76 (omapi_object_t *)callback, MDL);
77 omapi_object_reference ((omapi_object_t **)&callback -> outer,
80 /* Save the actual handle pointer we were passed for the callback. */
81 omapi_object_reference (&callback -> object, h, MDL);
82 callback -> data = data;
83 callback -> callback = func;
88 /* Callback methods (not meant to be called directly) */
90 isc_result_t dhcpctl_callback_set_value (omapi_object_t *h,
92 omapi_data_string_t *name,
93 omapi_typed_data_t *value)
95 if (h -> type != dhcpctl_callback_type)
96 return ISC_R_INVALIDARG;
98 if (h -> inner && h -> inner -> type -> set_value)
99 return (*(h -> inner -> type -> set_value))
100 (h -> inner, id, name, value);
101 return ISC_R_NOTFOUND;
104 isc_result_t dhcpctl_callback_get_value (omapi_object_t *h,
106 omapi_data_string_t *name,
107 omapi_value_t **value)
109 if (h -> type != dhcpctl_callback_type)
110 return ISC_R_INVALIDARG;
112 if (h -> inner && h -> inner -> type -> get_value)
113 return (*(h -> inner -> type -> get_value))
114 (h -> inner, id, name, value);
115 return ISC_R_NOTFOUND;
118 isc_result_t dhcpctl_callback_signal_handler (omapi_object_t *o,
119 const char *name, va_list ap)
121 dhcpctl_callback_object_t *p;
122 isc_result_t waitstatus;
124 if (o -> type != dhcpctl_callback_type)
125 return ISC_R_INVALIDARG;
126 p = (dhcpctl_callback_object_t *)o;
128 /* Not a signal we recognize? */
129 if (strcmp (name, "ready")) {
130 if (p -> inner && p -> inner -> type -> signal_handler)
131 return (*(p -> inner -> type -> signal_handler))
132 (p -> inner, name, ap);
133 return ISC_R_NOTFOUND;
136 if (p -> object -> type == dhcpctl_remote_type) {
137 waitstatus = (((dhcpctl_remote_object_t *)
138 (p -> object)) -> waitstatus);
140 waitstatus = ISC_R_SUCCESS;
142 /* Do the callback. */
144 (*(p -> callback)) (p -> object, waitstatus, p -> data);
146 return ISC_R_SUCCESS;
149 isc_result_t dhcpctl_callback_destroy (omapi_object_t *h,
150 const char *file, int line)
152 dhcpctl_callback_object_t *p;
153 if (h -> type != dhcpctl_callback_type)
154 return ISC_R_INVALIDARG;
155 p = (dhcpctl_callback_object_t *)h;
157 omapi_object_dereference ((omapi_object_t **)&p -> handle,
159 return ISC_R_SUCCESS;
162 /* Write all the published values associated with the object through the
163 specified connection. */
165 isc_result_t dhcpctl_callback_stuff_values (omapi_object_t *c,
171 if (p -> type != dhcpctl_callback_type)
172 return ISC_R_INVALIDARG;
174 if (p -> inner && p -> inner -> type -> stuff_values)
175 return (*(p -> inner -> type -> stuff_values)) (c, id,
177 return ISC_R_SUCCESS;