2 * Copyright (c) 2015-2016 Landon Fuller <landonf@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
32 #ifndef _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_
33 #define _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_
35 #include "bhnd_nvram_value.h"
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);
46 * Filter input data prior to initialization.
48 * This may be used to permit direct initialization from data types other than
49 * the default native_type defined by @p fmt.
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
55 * @param inp Input data.
56 * @param ilen Input data length.
57 * @param itype Input data type.
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
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);
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);
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);
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);
80 /** @see bhnd_nvram_val_nelem() */
81 typedef size_t (bhnd_nvram_val_op_nelem)(bhnd_nvram_val *value);
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.
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;
100 #endif /* _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_ */