3 The dhcpctl callback object. */
6 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1999-2003 by Internet Software Consortium
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.
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.
21 * Internet Systems Consortium, Inc.
23 * Redwood City, CA 94063
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 * ``http://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''.
36 static char copyright
[] =
37 "$Id$ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n";
40 #include <omapip/omapip_p.h>
43 /* dhcpctl_set_callback
45 synchronous, with asynchronous aftereffect
46 handle is some object upon which some kind of process has been
47 started - e.g., an open, an update or a refresh.
48 data is an anonymous pointer containing some information that
49 the callback will use to figure out what event completed.
50 return value of 0 means callback was successfully set, a nonzero
51 status code is returned otherwise.
52 Upon completion of whatever task is in process, the callback
53 will be passed the handle to the object, a status code
54 indicating what happened, and the anonymous pointer passed to */
56 dhcpctl_status
dhcpctl_set_callback (dhcpctl_handle h
, void *data
,
57 void (*func
) (dhcpctl_handle
,
58 dhcpctl_status
, void *))
60 dhcpctl_callback_object_t
*callback
;
61 omapi_object_t
*inner
;
64 callback
= dmalloc (sizeof *callback
, MDL
);
66 return ISC_R_NOMEMORY
;
68 /* Tie the callback object to the innermost object in the chain. */
69 for (inner
= h
; inner
-> inner
; inner
= inner
-> inner
)
71 omapi_object_reference (&inner
-> inner
,
72 (omapi_object_t
*)callback
, MDL
);
73 omapi_object_reference ((omapi_object_t
**)&callback
-> outer
,
76 /* Save the actual handle pointer we were passed for the callback. */
77 omapi_object_reference (&callback
-> object
, h
, MDL
);
78 callback
-> data
= data
;
79 callback
-> callback
= func
;
84 /* Callback methods (not meant to be called directly) */
86 isc_result_t
dhcpctl_callback_set_value (omapi_object_t
*h
,
88 omapi_data_string_t
*name
,
89 omapi_typed_data_t
*value
)
91 if (h
-> type
!= dhcpctl_callback_type
)
92 return ISC_R_INVALIDARG
;
94 if (h
-> inner
&& h
-> inner
-> type
-> set_value
)
95 return (*(h
-> inner
-> type
-> set_value
))
96 (h
-> inner
, id
, name
, value
);
97 return ISC_R_NOTFOUND
;
100 isc_result_t
dhcpctl_callback_get_value (omapi_object_t
*h
,
102 omapi_data_string_t
*name
,
103 omapi_value_t
**value
)
105 if (h
-> type
!= dhcpctl_callback_type
)
106 return ISC_R_INVALIDARG
;
108 if (h
-> inner
&& h
-> inner
-> type
-> get_value
)
109 return (*(h
-> inner
-> type
-> get_value
))
110 (h
-> inner
, id
, name
, value
);
111 return ISC_R_NOTFOUND
;
114 isc_result_t
dhcpctl_callback_signal_handler (omapi_object_t
*o
,
115 const char *name
, va_list ap
)
117 dhcpctl_callback_object_t
*p
;
118 isc_result_t waitstatus
;
120 if (o
-> type
!= dhcpctl_callback_type
)
121 return ISC_R_INVALIDARG
;
122 p
= (dhcpctl_callback_object_t
*)o
;
124 /* Not a signal we recognize? */
125 if (strcmp (name
, "ready")) {
126 if (p
-> inner
&& p
-> inner
-> type
-> signal_handler
)
127 return (*(p
-> inner
-> type
-> signal_handler
))
128 (p
-> inner
, name
, ap
);
129 return ISC_R_NOTFOUND
;
132 if (p
-> object
-> type
== dhcpctl_remote_type
) {
133 waitstatus
= (((dhcpctl_remote_object_t
*)
134 (p
-> object
)) -> waitstatus
);
136 waitstatus
= ISC_R_SUCCESS
;
138 /* Do the callback. */
140 (*(p
-> callback
)) (p
-> object
, waitstatus
, p
-> data
);
142 return ISC_R_SUCCESS
;
145 isc_result_t
dhcpctl_callback_destroy (omapi_object_t
*h
,
146 const char *file
, int line
)
148 dhcpctl_callback_object_t
*p
;
149 if (h
-> type
!= dhcpctl_callback_type
)
150 return ISC_R_INVALIDARG
;
151 p
= (dhcpctl_callback_object_t
*)h
;
153 omapi_object_dereference ((omapi_object_t
**)&p
-> handle
,
155 return ISC_R_SUCCESS
;
158 /* Write all the published values associated with the object through the
159 specified connection. */
161 isc_result_t
dhcpctl_callback_stuff_values (omapi_object_t
*c
,
167 if (p
-> type
!= dhcpctl_callback_type
)
168 return ISC_R_INVALIDARG
;
170 if (p
-> inner
&& p
-> inner
-> type
-> stuff_values
)
171 return (*(p
-> inner
-> type
-> stuff_values
)) (c
, id
,
173 return ISC_R_SUCCESS
;