15184Sek110237 /* 25184Sek110237 * CDDL HEADER START 35184Sek110237 * 45184Sek110237 * The contents of this file are subject to the terms of the 55184Sek110237 * Common Development and Distribution License (the "License"). 65184Sek110237 * You may not use this file except in compliance with the License. 75184Sek110237 * 85184Sek110237 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95184Sek110237 * or http://www.opensolaris.org/os/licensing. 105184Sek110237 * See the License for the specific language governing permissions 115184Sek110237 * and limitations under the License. 125184Sek110237 * 135184Sek110237 * When distributing Covered Code, include this CDDL HEADER in each 145184Sek110237 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155184Sek110237 * If applicable, add the following below this CDDL HEADER, with the 165184Sek110237 * fields enclosed by brackets "[]" replaced with your own identifying 175184Sek110237 * information: Portions Copyright [yyyy] [name of copyright owner] 185184Sek110237 * 195184Sek110237 * CDDL HEADER END 205184Sek110237 */ 215184Sek110237 /* 22*6212Saw148015 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 235184Sek110237 * Use is subject to license terms. 245184Sek110237 */ 255184Sek110237 265184Sek110237 #ifndef _FB_VARS_H 275184Sek110237 #define _FB_VARS_H 285184Sek110237 295184Sek110237 #pragma ident "%Z%%M% %I% %E% SMI" 305184Sek110237 315184Sek110237 #include "config.h" 325184Sek110237 335184Sek110237 #include <stdio.h> 345184Sek110237 #include <sys/types.h> 355184Sek110237 #ifdef HAVE_STDINT_H 365184Sek110237 #include <stdint.h> 375184Sek110237 #endif 385184Sek110237 395184Sek110237 #ifdef __cplusplus 405184Sek110237 extern "C" { 415184Sek110237 #endif 425184Sek110237 43*6212Saw148015 /* Attribute Value Descriptor types */ 44*6212Saw148015 typedef enum avd_type { 45*6212Saw148015 AVD_INVALID = 0, /* avd is empty */ 46*6212Saw148015 AVD_VAL_BOOL, /* avd contains a boolean_t */ 47*6212Saw148015 AVD_VARVAL_BOOL, /* avd points to the boolean_t in a var_t */ 48*6212Saw148015 AVD_VAL_INT, /* avd contains an fbint_t */ 49*6212Saw148015 AVD_VARVAL_INT, /* avd points to the fbint_t in a var_t */ 50*6212Saw148015 AVD_VAL_STR, /* avd contains a sting (*char) */ 51*6212Saw148015 AVD_VARVAL_STR, /* avd points to a string in a var_t */ 52*6212Saw148015 AVD_VAL_DBL, /* avd contains a double float */ 53*6212Saw148015 AVD_VARVAL_DBL, /* avd points to the double in a var_t */ 54*6212Saw148015 AVD_IND_VAR, /* avd points a var_t */ 55*6212Saw148015 AVD_IND_RANDVAR /* avd points to the randdist_t associated */ 56*6212Saw148015 /* with a random type var_t */ 57*6212Saw148015 } avd_type_t; 58*6212Saw148015 59*6212Saw148015 typedef uint64_t fbint_t; 60*6212Saw148015 61*6212Saw148015 /* Attribute Value Descriptor */ 62*6212Saw148015 typedef struct avd { 63*6212Saw148015 avd_type_t avd_type; 64*6212Saw148015 union { 65*6212Saw148015 boolean_t boolval; 66*6212Saw148015 boolean_t *boolptr; 67*6212Saw148015 fbint_t intval; 68*6212Saw148015 fbint_t *intptr; 69*6212Saw148015 double dblval; 70*6212Saw148015 double *dblptr; 71*6212Saw148015 char *strval; 72*6212Saw148015 char **strptr; 73*6212Saw148015 struct randdist *randptr; 74*6212Saw148015 struct var *varptr; 75*6212Saw148015 } avd_val; 76*6212Saw148015 } *avd_t; 77*6212Saw148015 78*6212Saw148015 #define AVD_IS_RANDOM(vp) ((vp)->avd_type == AVD_IND_RANDVAR) 795184Sek110237 805184Sek110237 typedef struct var { 815184Sek110237 char *var_name; 825184Sek110237 int var_type; 835184Sek110237 struct var *var_next; 84*6212Saw148015 union { 85*6212Saw148015 boolean_t boolean; 86*6212Saw148015 fbint_t integer; 87*6212Saw148015 double dbl_flt; 88*6212Saw148015 char *string; 89*6212Saw148015 struct randdist *randptr; 90*6212Saw148015 } var_val; 915184Sek110237 } var_t; 925184Sek110237 93*6212Saw148015 #define VAR_TYPE_GLOBAL 0x00 /* global variable */ 94*6212Saw148015 #define VAR_TYPE_DYNAMIC 0x01 /* Dynamic variable */ 95*6212Saw148015 #define VAR_TYPE_RANDOM 0x02 /* random variable */ 96*6212Saw148015 #define VAR_TYPE_MASK 0x0f 97*6212Saw148015 #define VAR_TYPE_BOOL_SET 0x10 /* var contains a boolean */ 98*6212Saw148015 #define VAR_TYPE_INT_SET 0x20 /* var contains an integer */ 99*6212Saw148015 #define VAR_TYPE_STR_SET 0x30 /* var contains a string */ 100*6212Saw148015 #define VAR_TYPE_DBL_SET 0x40 /* var contains a double */ 101*6212Saw148015 #define VAR_TYPE_RAND_SET 0x50 /* var contains a randdist pointer */ 102*6212Saw148015 #define VAR_TYPE_SET_MASK 0xf0 103*6212Saw148015 104*6212Saw148015 #define VAR_HAS_BOOLEAN(vp) \ 105*6212Saw148015 (((vp)->var_type & VAR_TYPE_SET_MASK) == VAR_TYPE_BOOL_SET) 106*6212Saw148015 107*6212Saw148015 #define VAR_HAS_INTEGER(vp) \ 108*6212Saw148015 (((vp)->var_type & VAR_TYPE_SET_MASK) == VAR_TYPE_INT_SET) 109*6212Saw148015 110*6212Saw148015 #define VAR_HAS_DOUBLE(vp) \ 111*6212Saw148015 (((vp)->var_type & VAR_TYPE_SET_MASK) == VAR_TYPE_DBL_SET) 112*6212Saw148015 113*6212Saw148015 #define VAR_HAS_STRING(vp) \ 114*6212Saw148015 (((vp)->var_type & VAR_TYPE_SET_MASK) == VAR_TYPE_STR_SET) 115*6212Saw148015 116*6212Saw148015 #define VAR_HAS_RANDDIST(vp) \ 117*6212Saw148015 (((vp)->var_type & VAR_TYPE_SET_MASK) == VAR_TYPE_RAND_SET) 118*6212Saw148015 119*6212Saw148015 #define VAR_SET_BOOL(vp, val) \ 120*6212Saw148015 { \ 121*6212Saw148015 (vp)->var_val.boolean = (val); \ 122*6212Saw148015 (vp)->var_type = \ 123*6212Saw148015 (((vp)->var_type & (~VAR_TYPE_SET_MASK)) | VAR_TYPE_BOOL_SET);\ 124*6212Saw148015 } 1255184Sek110237 126*6212Saw148015 #define VAR_SET_INT(vp, val) \ 127*6212Saw148015 { \ 128*6212Saw148015 (vp)->var_val.integer = (val); \ 129*6212Saw148015 (vp)->var_type = \ 130*6212Saw148015 (((vp)->var_type & (~VAR_TYPE_SET_MASK)) | VAR_TYPE_INT_SET); \ 131*6212Saw148015 } 132*6212Saw148015 133*6212Saw148015 #define VAR_SET_DBL(vp, val) \ 134*6212Saw148015 { \ 135*6212Saw148015 (vp)->var_val.dbl_flt = (val); \ 136*6212Saw148015 (vp)->var_type = \ 137*6212Saw148015 (((vp)->var_type & (~VAR_TYPE_SET_MASK)) | VAR_TYPE_DBL_SET); \ 138*6212Saw148015 } 139*6212Saw148015 140*6212Saw148015 #define VAR_SET_STR(vp, val) \ 141*6212Saw148015 { \ 142*6212Saw148015 (vp)->var_val.string = (val); \ 143*6212Saw148015 (vp)->var_type = \ 144*6212Saw148015 (((vp)->var_type & (~VAR_TYPE_SET_MASK)) | VAR_TYPE_STR_SET); \ 145*6212Saw148015 } 146*6212Saw148015 147*6212Saw148015 #define VAR_SET_RAND(vp, val) \ 148*6212Saw148015 { \ 149*6212Saw148015 (vp)->var_val.randptr = (val); \ 150*6212Saw148015 (vp)->var_type = \ 151*6212Saw148015 (((vp)->var_type & (~VAR_TYPE_SET_MASK)) | VAR_TYPE_RAND_SET);\ 152*6212Saw148015 } 153*6212Saw148015 154*6212Saw148015 avd_t avd_bool_alloc(boolean_t bool); 155*6212Saw148015 avd_t avd_int_alloc(fbint_t integer); 156*6212Saw148015 avd_t avd_str_alloc(char *string); 157*6212Saw148015 avd_t var_ref_attr(char *name); 158*6212Saw148015 int var_assign_boolean(char *name, boolean_t bool); 159*6212Saw148015 int var_assign_integer(char *name, fbint_t integer); 1605184Sek110237 int var_assign_string(char *name, char *string); 1615184Sek110237 int var_assign_var(char *name, char *string); 162*6212Saw148015 var_t *var_define_randvar(char *name); 163*6212Saw148015 var_t *var_find_randvar(char *name); 164*6212Saw148015 boolean_t var_to_boolean(char *name); 165*6212Saw148015 fbint_t var_to_integer(char *name); 1665184Sek110237 char *var_to_string(char *name); 167*6212Saw148015 char *var_randvar_to_string(char *name, int param); 168*6212Saw148015 boolean_t avd_get_bool(avd_t); 169*6212Saw148015 fbint_t avd_get_int(avd_t); 170*6212Saw148015 double avd_get_dbl(avd_t); 171*6212Saw148015 char *avd_get_str(avd_t); 172*6212Saw148015 int var_is_set4_randvar(char *name); 1735184Sek110237 1745184Sek110237 #ifdef __cplusplus 1755184Sek110237 } 1765184Sek110237 #endif 1775184Sek110237 1785184Sek110237 #endif /* _FB_VARS_H */ 179