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: callback.c,v 1.4 2005/08/11 17:13:21 drochner Exp $ 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
;
63 callback
= dmalloc (sizeof *callback
, MDL
);
65 return ISC_R_NOMEMORY
;
67 /* Tie the callback object to the innermost object in the chain. */
68 for (inner
= h
; inner
-> inner
; inner
= inner
-> inner
)
70 omapi_object_reference (&inner
-> inner
,
71 (omapi_object_t
*)callback
, MDL
);
72 omapi_object_reference ((omapi_object_t
**)&callback
-> outer
,
75 /* Save the actual handle pointer we were passed for the callback. */
76 omapi_object_reference (&callback
-> object
, h
, MDL
);
77 callback
-> data
= data
;
78 callback
-> callback
= func
;
83 /* Callback methods (not meant to be called directly) */
85 isc_result_t
dhcpctl_callback_set_value (omapi_object_t
*h
,
87 omapi_data_string_t
*name
,
88 omapi_typed_data_t
*value
)
90 if (h
-> type
!= dhcpctl_callback_type
)
91 return ISC_R_INVALIDARG
;
93 if (h
-> inner
&& h
-> inner
-> type
-> set_value
)
94 return (*(h
-> inner
-> type
-> set_value
))
95 (h
-> inner
, id
, name
, value
);
96 return ISC_R_NOTFOUND
;
99 isc_result_t
dhcpctl_callback_get_value (omapi_object_t
*h
,
101 omapi_data_string_t
*name
,
102 omapi_value_t
**value
)
104 if (h
-> type
!= dhcpctl_callback_type
)
105 return ISC_R_INVALIDARG
;
107 if (h
-> inner
&& h
-> inner
-> type
-> get_value
)
108 return (*(h
-> inner
-> type
-> get_value
))
109 (h
-> inner
, id
, name
, value
);
110 return ISC_R_NOTFOUND
;
113 isc_result_t
dhcpctl_callback_signal_handler (omapi_object_t
*o
,
114 const char *name
, va_list ap
)
116 dhcpctl_callback_object_t
*p
;
117 isc_result_t waitstatus
;
119 if (o
-> type
!= dhcpctl_callback_type
)
120 return ISC_R_INVALIDARG
;
121 p
= (dhcpctl_callback_object_t
*)o
;
123 /* Not a signal we recognize? */
124 if (strcmp (name
, "ready")) {
125 if (p
-> inner
&& p
-> inner
-> type
-> signal_handler
)
126 return (*(p
-> inner
-> type
-> signal_handler
))
127 (p
-> inner
, name
, ap
);
128 return ISC_R_NOTFOUND
;
131 if (p
-> object
-> type
== dhcpctl_remote_type
) {
132 waitstatus
= (((dhcpctl_remote_object_t
*)
133 (p
-> object
)) -> waitstatus
);
135 waitstatus
= ISC_R_SUCCESS
;
137 /* Do the callback. */
139 (*(p
-> callback
)) (p
-> object
, waitstatus
, p
-> data
);
141 return ISC_R_SUCCESS
;
144 isc_result_t
dhcpctl_callback_destroy (omapi_object_t
*h
,
145 const char *file
, int line
)
147 dhcpctl_callback_object_t
*p
;
148 if (h
-> type
!= dhcpctl_callback_type
)
149 return ISC_R_INVALIDARG
;
150 p
= (dhcpctl_callback_object_t
*)h
;
152 omapi_object_dereference ((omapi_object_t
**)&p
-> handle
,
154 return ISC_R_SUCCESS
;
157 /* Write all the published values associated with the object through the
158 specified connection. */
160 isc_result_t
dhcpctl_callback_stuff_values (omapi_object_t
*c
,
165 if (p
-> type
!= dhcpctl_callback_type
)
166 return ISC_R_INVALIDARG
;
168 if (p
-> inner
&& p
-> inner
-> type
-> stuff_values
)
169 return (*(p
-> inner
-> type
-> stuff_values
)) (c
, id
,
171 return ISC_R_SUCCESS
;