dhcpctl/callback.c

Go to the documentation of this file.
00001 /* callback.c
00002 
00003    The dhcpctl callback object. */
00004 
00005 /*
00006  * Copyright (c) 2004,2007,2009,2014 by Internet Systems Consortium, Inc. ("ISC")
00007  * Copyright (c) 1999-2003 by Internet Software Consortium
00008  *
00009  * Permission to use, copy, modify, and distribute this software for any
00010  * purpose with or without fee is hereby granted, provided that the above
00011  * copyright notice and this permission notice appear in all copies.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
00014  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00015  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
00016  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00017  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00018  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00019  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00020  *
00021  *   Internet Systems Consortium, Inc.
00022  *   950 Charter Street
00023  *   Redwood City, CA 94063
00024  *   <info@isc.org>
00025  *   https://www.isc.org/
00026  *
00027  */
00028 
00029 #include "dhcpd.h"
00030 #include <omapip/omapip_p.h>
00031 #include "dhcpctl.h"
00032 
00033 /* dhcpctl_set_callback
00034 
00035    synchronous, with asynchronous aftereffect
00036    handle is some object upon which some kind of process has been
00037    started - e.g., an open, an update or a refresh.
00038    data is an anonymous pointer containing some information that
00039    the callback will use to figure out what event completed.
00040    return value of 0 means callback was successfully set, a nonzero
00041    status code is returned otherwise.
00042    Upon completion of whatever task is in process, the callback
00043    will be passed the handle to the object, a status code
00044    indicating what happened, and the anonymous pointer passed to  */
00045 
00046 dhcpctl_status dhcpctl_set_callback (dhcpctl_handle h, void *data,
00047                                      void (*func) (dhcpctl_handle,
00048                                                    dhcpctl_status, void *))
00049 {
00050         dhcpctl_callback_object_t *callback;
00051         omapi_object_t *inner;
00052 
00053         callback = dmalloc (sizeof *callback, MDL);
00054         if (!callback)
00055                 return ISC_R_NOMEMORY;
00056 
00057         /* Tie the callback object to the innermost object in the chain. */
00058         for (inner = h; inner -> inner; inner = inner -> inner)
00059                 ;
00060         omapi_object_reference (&inner -> inner,
00061                                 (omapi_object_t *)callback, MDL);
00062         omapi_object_reference ((omapi_object_t **)&callback -> outer,
00063                                 inner, MDL);
00064 
00065         /* Save the actual handle pointer we were passed for the callback. */
00066         omapi_object_reference (&callback -> object, h, MDL);
00067         callback -> data = data;
00068         callback -> callback = func;
00069         
00070         return ISC_R_SUCCESS;
00071 }
00072 
00073 /* Callback methods (not meant to be called directly) */
00074 
00075 isc_result_t dhcpctl_callback_set_value (omapi_object_t *h,
00076                                          omapi_object_t *id,
00077                                          omapi_data_string_t *name,
00078                                          omapi_typed_data_t *value)
00079 {
00080         if (h -> type != dhcpctl_callback_type)
00081                 return DHCP_R_INVALIDARG;
00082 
00083         if (h -> inner && h -> inner -> type -> set_value)
00084                 return (*(h -> inner -> type -> set_value))
00085                         (h -> inner, id, name, value);
00086         return ISC_R_NOTFOUND;
00087 }
00088 
00089 isc_result_t dhcpctl_callback_get_value (omapi_object_t *h,
00090                                          omapi_object_t *id,
00091                                          omapi_data_string_t *name,
00092                                          omapi_value_t **value)
00093 {
00094         if (h -> type != dhcpctl_callback_type)
00095                 return DHCP_R_INVALIDARG;
00096         
00097         if (h -> inner && h -> inner -> type -> get_value)
00098                 return (*(h -> inner -> type -> get_value))
00099                         (h -> inner, id, name, value);
00100         return ISC_R_NOTFOUND;
00101 }
00102 
00103 isc_result_t dhcpctl_callback_signal_handler (omapi_object_t *o,
00104                                               const char *name, va_list ap)
00105 {
00106         dhcpctl_callback_object_t *p;
00107         isc_result_t waitstatus;
00108 
00109         if (o -> type != dhcpctl_callback_type)
00110                 return DHCP_R_INVALIDARG;
00111         p = (dhcpctl_callback_object_t *)o;
00112 
00113         /* Not a signal we recognize? */
00114         if (strcmp (name, "ready")) {
00115                 if (p -> inner && p -> inner -> type -> signal_handler)
00116                         return (*(p -> inner -> type -> signal_handler))
00117                                 (p -> inner, name, ap);
00118                 return ISC_R_NOTFOUND;
00119         }
00120 
00121         if (p -> object -> type == dhcpctl_remote_type) {
00122                 waitstatus = (((dhcpctl_remote_object_t *)
00123                                (p -> object)) -> waitstatus);
00124         } else
00125                 waitstatus = ISC_R_SUCCESS;
00126 
00127         /* Do the callback. */
00128         if (p -> callback)
00129                 (*(p -> callback)) (p -> object, waitstatus, p -> data);
00130 
00131         return ISC_R_SUCCESS;
00132 }
00133 
00134 isc_result_t dhcpctl_callback_destroy (omapi_object_t *h,
00135                                        const char *file, int line)
00136 {
00137         dhcpctl_callback_object_t *p;
00138         if (h -> type != dhcpctl_callback_type)
00139                 return DHCP_R_INVALIDARG;
00140         p = (dhcpctl_callback_object_t *)h;
00141         if (p -> handle)
00142                 omapi_object_dereference ((omapi_object_t **)&p -> handle,
00143                                           file, line);
00144         return ISC_R_SUCCESS;
00145 }
00146 
00147 /* Write all the published values associated with the object through the
00148    specified connection. */
00149 
00150 isc_result_t dhcpctl_callback_stuff_values (omapi_object_t *c,
00151                                             omapi_object_t *id,
00152                                             omapi_object_t *p)
00153 {
00154         if (p -> type != dhcpctl_callback_type)
00155                 return DHCP_R_INVALIDARG;
00156 
00157         if (p -> inner && p -> inner -> type -> stuff_values)
00158                 return (*(p -> inner -> type -> stuff_values)) (c, id,
00159                                                                 p -> inner);
00160         return ISC_R_SUCCESS;
00161 }
00162 

Generated on 5 Apr 2014 for ISC DHCP by  doxygen 1.6.1