1 /*- 2 * Copyright (c) 2015-2016 Landon Fuller <landonf@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer, 10 * without modification. 11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13 * redistribution must be conditioned upon including a substantially 14 * similar Disclaimer requirement for further binary redistribution. 15 * 16 * NO WARRANTY 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGES. 28 * 29 * $FreeBSD$ 30 */ 31 32 #ifndef _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_ 33 #define _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_ 34 35 #include "bhnd_nvram_value.h" 36 37 int bhnd_nvram_val_generic_encode(bhnd_nvram_val *value, 38 void *outp, size_t *olen, bhnd_nvram_type otype); 39 int bhnd_nvram_val_generic_encode_elem(bhnd_nvram_val *value, 40 const void *inp, size_t ilen, void *outp, size_t *olen, 41 bhnd_nvram_type otype); 42 const void *bhnd_nvram_val_generic_next(bhnd_nvram_val *value, 43 const void *prev, size_t *olen); 44 45 /** 46 * Filter input data prior to initialization. 47 * 48 * This may be used to permit direct initialization from data types other than 49 * the default native_type defined by @p fmt. 50 * 51 * @param[in,out] fmt Indirect pointer to the NVRAM value format. If 52 * modified by the caller, initialization will be 53 * restarted and performed using the provided 54 * format instance. 55 * @param inp Input data. 56 * @param ilen Input data length. 57 * @param itype Input data type. 58 * 59 * @retval 0 If initialization from @p inp is supported. 60 * @retval EFTYPE If initialization from @p inp is unsupported. 61 * @retval EFAULT if @p ilen is not correctly aligned for elements of 62 * @p itype. 63 */ 64 typedef int (bhnd_nvram_val_op_filter)(const bhnd_nvram_val_fmt **fmt, 65 const void *inp, size_t ilen, bhnd_nvram_type itype); 66 67 /** @see bhnd_nvram_val_encode() */ 68 typedef int (bhnd_nvram_val_op_encode)(bhnd_nvram_val *value, void *outp, 69 size_t *olen, bhnd_nvram_type otype); 70 71 /** @see bhnd_nvram_val_encode_elem() */ 72 typedef int (bhnd_nvram_val_op_encode_elem)(bhnd_nvram_val *value, 73 const void *inp, size_t ilen, void *outp, size_t *olen, 74 bhnd_nvram_type otype); 75 76 /** @see bhnd_nvram_val_next() */ 77 typedef const void *(bhnd_nvram_val_op_next)(bhnd_nvram_val *value, 78 const void *prev, size_t *olen); 79 80 /** @see bhnd_nvram_val_nelem() */ 81 typedef size_t (bhnd_nvram_val_op_nelem)(bhnd_nvram_val *value); 82 83 /** 84 * NVRAM value format. 85 * 86 * Provides a set of callbacks to support defining custom parsing 87 * and encoding/conversion behavior when representing values as 88 * instances of bhnd_nvram_val. 89 */ 90 struct bhnd_nvram_val_fmt { 91 const char *name; /**< type name */ 92 bhnd_nvram_type native_type; /**< native value representation */ 93 bhnd_nvram_val_op_filter *op_filter; 94 bhnd_nvram_val_op_encode *op_encode; 95 bhnd_nvram_val_op_encode_elem *op_encode_elem; 96 bhnd_nvram_val_op_nelem *op_nelem; 97 bhnd_nvram_val_op_next *op_next; 98 }; 99 100 #endif /* _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_ */ 101