#ifndef _BHND_NVRAM_BHND_NVRAM_DATAVAR_H_
#define _BHND_NVRAM_BHND_NVRAM_DATAVAR_H_
#include <sys/param.h>
#include <sys/linker_set.h>
#include <sys/refcount.h>
#include "bhnd_nvram_io.h"
#include "bhnd_nvram_data.h"
SET_DECLARE(bhnd_nvram_data_class_set, bhnd_nvram_data_class);
void *bhnd_nvram_data_generic_find(
struct bhnd_nvram_data *nv, const char *name);
int bhnd_nvram_data_generic_rp_getvar(
struct bhnd_nvram_data *nv, void *cookiep,
void *outp, size_t *olen, bhnd_nvram_type otype);
int bhnd_nvram_data_generic_rp_copy_val(
struct bhnd_nvram_data *nv, void *cookiep,
bhnd_nvram_val **val);
typedef int (bhnd_nvram_data_op_probe)(struct bhnd_nvram_io *io);
typedef int (bhnd_nvram_data_op_getvar_direct)(
struct bhnd_nvram_io *io, const char *name,
void *outp, size_t *olen, bhnd_nvram_type otype);
typedef int (bhnd_nvram_data_op_serialize)(
bhnd_nvram_data_class *cls,
bhnd_nvram_plist *props,
bhnd_nvram_plist *options, void *outp,
size_t *olen);
typedef int (bhnd_nvram_data_op_new)(struct bhnd_nvram_data *nv,
struct bhnd_nvram_io *io);
typedef void (bhnd_nvram_data_op_free)(struct bhnd_nvram_data *nv);
typedef size_t (bhnd_nvram_data_op_count)(struct bhnd_nvram_data *nv);
typedef bhnd_nvram_plist*(bhnd_nvram_data_op_options)(
struct bhnd_nvram_data *nv);
typedef uint32_t (bhnd_nvram_data_op_caps)(struct bhnd_nvram_data *nv);
typedef const char *(bhnd_nvram_data_op_next)(struct bhnd_nvram_data *nv,
void **cookiep);
typedef void *(bhnd_nvram_data_op_find)(struct bhnd_nvram_data *nv,
const char *name);
typedef int (bhnd_nvram_data_op_copy_val)(
struct bhnd_nvram_data *nv, void *cookiep,
bhnd_nvram_val **value);
typedef int (bhnd_nvram_data_op_getvar_order)(
struct bhnd_nvram_data *nv, void *cookiep1,
void *cookiep2);
typedef const char *(bhnd_nvram_data_op_getvar_name)(
struct bhnd_nvram_data *nv,
void *cookiep);
typedef int (bhnd_nvram_data_op_getvar)(struct bhnd_nvram_data *nv,
void *cookiep, void *buf, size_t *len,
bhnd_nvram_type type);
typedef const void *(bhnd_nvram_data_op_getvar_ptr)(
struct bhnd_nvram_data *nv, void *cookiep,
size_t *len, bhnd_nvram_type *type);
typedef int (bhnd_nvram_data_op_filter_setvar)(
struct bhnd_nvram_data *nv, const char *name,
bhnd_nvram_val *value, bhnd_nvram_val **result);
typedef int (bhnd_nvram_data_op_filter_unsetvar)(
struct bhnd_nvram_data *nv, const char *name);
struct bhnd_nvram_data_class {
const char *desc;
uint32_t caps;
size_t size;
bhnd_nvram_data_op_probe *op_probe;
bhnd_nvram_data_op_getvar_direct *op_getvar_direct;
bhnd_nvram_data_op_serialize *op_serialize;
bhnd_nvram_data_op_new *op_new;
bhnd_nvram_data_op_free *op_free;
bhnd_nvram_data_op_count *op_count;
bhnd_nvram_data_op_options *op_options;
bhnd_nvram_data_op_caps *op_caps;
bhnd_nvram_data_op_next *op_next;
bhnd_nvram_data_op_find *op_find;
bhnd_nvram_data_op_copy_val *op_copy_val;
bhnd_nvram_data_op_getvar_order *op_getvar_order;
bhnd_nvram_data_op_getvar *op_getvar;
bhnd_nvram_data_op_getvar_ptr *op_getvar_ptr;
bhnd_nvram_data_op_getvar_name *op_getvar_name;
bhnd_nvram_data_op_filter_setvar *op_filter_setvar;
bhnd_nvram_data_op_filter_unsetvar *op_filter_unsetvar;
};
struct bhnd_nvram_data {
struct bhnd_nvram_data_class *cls;
volatile u_int refs;
};
#define BHND_NVRAM_DATA_CLASS_DECL_METHOD(_cname, _mname) \
static bhnd_nvram_data_op_ ## _mname \
bhnd_nvram_ ## _cname ## _ ## _mname; \
#define BHND_NVRAM_DATA_CLASS_ASSIGN_METHOD(_cname, _mname) \
.op_ ## _mname = bhnd_nvram_ ## _cname ## _ ## _mname,
#define BHND_NVRAM_DATA_CLASS_ITER_METHODS(_cname, _macro) \
_macro(_cname, probe) \
_macro(_cname, getvar_direct) \
_macro(_cname, serialize) \
_macro(_cname, new) \
_macro(_cname, free) \
_macro(_cname, count) \
_macro(_cname, options) \
_macro(_cname, caps) \
_macro(_cname, next) \
_macro(_cname, find) \
_macro(_cname, copy_val) \
_macro(_cname, getvar_order) \
_macro(_cname, getvar) \
_macro(_cname, getvar_ptr) \
_macro(_cname, getvar_name) \
_macro(_cname, filter_setvar) \
_macro(_cname, filter_unsetvar)
#define BHND_NVRAM_DATA_CLASS_DEFN(_cname, _desc, _caps, _size) \
BHND_NVRAM_DATA_CLASS_ITER_METHODS(_cname, \
BHND_NVRAM_DATA_CLASS_DECL_METHOD) \
\
struct bhnd_nvram_data_class bhnd_nvram_## _cname ## _class = { \
.desc = (_desc), \
.caps = (_caps), \
.size = (_size), \
BHND_NVRAM_DATA_CLASS_ITER_METHODS(_cname, \
BHND_NVRAM_DATA_CLASS_ASSIGN_METHOD) \
}; \
\
DATA_SET(bhnd_nvram_data_class_set, \
bhnd_nvram_## _cname ## _class);
#endif