xref: /onnv-gate/usr/src/cmd/filebench/common/vars.h (revision 7556:55f6926392fe)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _FB_VARS_H
27 #define	_FB_VARS_H
28 
29 #include "config.h"
30 
31 #include <stdio.h>
32 #include <sys/types.h>
33 #ifdef HAVE_STDINT_H
34 #include <stdint.h>
35 #endif
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 /* Attribute Value Descriptor types */
42 typedef enum avd_type {
43 	AVD_INVALID = 0,	/* avd is empty */
44 	AVD_VAL_BOOL,		/* avd contains a boolean_t */
45 	AVD_VARVAL_BOOL,	/* avd points to the boolean_t in a var_t */
46 	AVD_VAL_INT,		/* avd contains an fbint_t */
47 	AVD_VARVAL_INT,		/* avd points to the fbint_t in a var_t */
48 	AVD_VAL_STR,		/* avd contains a sting (*char) */
49 	AVD_VARVAL_STR,		/* avd points to a string in a var_t */
50 	AVD_VAL_DBL,		/* avd contains a double float */
51 	AVD_VARVAL_DBL,		/* avd points to the double in a var_t */
52 	AVD_IND_VAR,		/* avd points a var_t */
53 	AVD_IND_RANDVAR		/* avd points to the randdist_t associated */
54 				/* with a random type var_t */
55 } avd_type_t;
56 
57 typedef uint64_t fbint_t;
58 
59 /* Attribute Value Descriptor */
60 typedef struct avd {
61 	avd_type_t  avd_type;
62 	union {
63 		boolean_t	boolval;
64 		boolean_t	*boolptr;
65 		fbint_t		intval;
66 		fbint_t		*intptr;
67 		double		dblval;
68 		double		*dblptr;
69 		char		*strval;
70 		char		**strptr;
71 		struct randdist *randptr;
72 		struct var	*varptr;
73 	} avd_val;
74 } *avd_t;
75 
76 #define	AVD_IS_RANDOM(vp)	((vp) && ((vp)->avd_type == AVD_IND_RANDVAR))
77 #define	AVD_IS_STRING(vp)	((vp) && (((vp)->avd_type == AVD_VAL_STR) || \
78 				((vp)->avd_type == AVD_VARVAL_STR)))
79 
80 typedef struct var {
81 	char		*var_name;
82 	int		var_type;
83 	struct var	*var_next;
84 	union {
85 		boolean_t	boolean;
86 		fbint_t		integer;
87 		double		dbl_flt;
88 		char		*string;
89 		struct randdist *randptr;
90 		struct var	*varptr;
91 	} var_val;
92 } var_t;
93 
94 #define	VAR_TYPE_GLOBAL		0x00	/* global variable */
95 #define	VAR_TYPE_DYNAMIC	0x01	/* Dynamic variable */
96 #define	VAR_TYPE_RANDOM		0x02	/* random variable */
97 #define	VAR_TYPE_LOCAL		0x03	/* Local variable */
98 #define	VAR_TYPE_MASK		0x0f
99 #define	VAR_TYPE_BOOL_SET	0x10	/* var contains a boolean */
100 #define	VAR_TYPE_INT_SET	0x20	/* var contains an integer */
101 #define	VAR_TYPE_STR_SET	0x30	/* var contains a string */
102 #define	VAR_TYPE_DBL_SET	0x40	/* var contains a double */
103 #define	VAR_TYPE_RAND_SET	0x50	/* var contains a randdist pointer */
104 #define	VAR_TYPE_INDVAR_SET	0x60    /* var points to another local var */
105 #define	VAR_TYPE_SET_MASK	0xf0
106 
107 #define	VAR_HAS_BOOLEAN(vp) \
108 	(((vp)->var_type & VAR_TYPE_SET_MASK) == VAR_TYPE_BOOL_SET)
109 
110 #define	VAR_HAS_INTEGER(vp) \
111 	(((vp)->var_type & VAR_TYPE_SET_MASK) == VAR_TYPE_INT_SET)
112 
113 #define	VAR_HAS_DOUBLE(vp) \
114 	(((vp)->var_type & VAR_TYPE_SET_MASK) == VAR_TYPE_DBL_SET)
115 
116 #define	VAR_HAS_STRING(vp) \
117 	(((vp)->var_type & VAR_TYPE_SET_MASK) == VAR_TYPE_STR_SET)
118 
119 #define	VAR_HAS_RANDDIST(vp) \
120 	(((vp)->var_type & VAR_TYPE_SET_MASK) == VAR_TYPE_RAND_SET)
121 
122 #define	VAR_HAS_INDVAR(vp) \
123 	(((vp)->var_type & VAR_TYPE_SET_MASK) == VAR_TYPE_INDVAR_SET)
124 
125 #define	VAR_SET_BOOL(vp, val)	\
126 	{			\
127 		(vp)->var_val.boolean = (val); \
128 		(vp)->var_type = \
129 		(((vp)->var_type & (~VAR_TYPE_SET_MASK)) | VAR_TYPE_BOOL_SET);\
130 	}
131 
132 #define	VAR_SET_INT(vp, val)	\
133 	{			\
134 		(vp)->var_val.integer = (val); \
135 		(vp)->var_type = \
136 		(((vp)->var_type & (~VAR_TYPE_SET_MASK)) | VAR_TYPE_INT_SET); \
137 	}
138 
139 #define	VAR_SET_DBL(vp, val)	\
140 	{			\
141 		(vp)->var_val.dbl_flt = (val); \
142 		(vp)->var_type = \
143 		    (((vp)->var_type & (~VAR_TYPE_SET_MASK)) | \
144 		    VAR_TYPE_DBL_SET); \
145 	}
146 
147 #define	VAR_SET_STR(vp, val)	\
148 	{			\
149 		(vp)->var_val.string = (val); \
150 		(vp)->var_type = \
151 		    (((vp)->var_type & (~VAR_TYPE_SET_MASK)) | \
152 		    VAR_TYPE_STR_SET); \
153 	}
154 
155 #define	VAR_SET_RAND(vp, val)	\
156 	{			\
157 		(vp)->var_val.randptr = (val); \
158 		(vp)->var_type = \
159 		    (((vp)->var_type & (~VAR_TYPE_SET_MASK)) | \
160 		    VAR_TYPE_RAND_SET); \
161 	}
162 
163 #define	VAR_SET_INDVAR(vp, val)	\
164 	{			\
165 		(vp)->var_val.varptr = (val); \
166 		(vp)->var_type = \
167 		    (((vp)->var_type & (~VAR_TYPE_SET_MASK)) | \
168 		    VAR_TYPE_INDVAR_SET); \
169 	}
170 
171 avd_t avd_bool_alloc(boolean_t bool);
172 avd_t avd_int_alloc(fbint_t integer);
173 avd_t avd_str_alloc(char *string);
174 boolean_t avd_get_bool(avd_t);
175 fbint_t avd_get_int(avd_t);
176 double avd_get_dbl(avd_t);
177 char *avd_get_str(avd_t);
178 void avd_update(avd_t *avdp, var_t *lvar_list);
179 avd_t var_ref_attr(char *name);
180 int var_assign_boolean(char *name, boolean_t bool);
181 int var_assign_integer(char *name, fbint_t integer);
182 int var_assign_double(char *name, double dbl);
183 int var_assign_string(char *name, char *string);
184 int var_assign_var(char *name, char *string);
185 void var_update_comp_lvars(var_t *newlvar, var_t *proto_comp_vars,
186     var_t *mstr_lvars);
187 var_t *var_define_randvar(char *name);
188 var_t *var_find_randvar(char *name);
189 boolean_t var_to_boolean(char *name);
190 fbint_t var_to_integer(char *name);
191 var_t *var_lvar_alloc_local(char *name);
192 var_t *var_lvar_assign_boolean(char *name, boolean_t);
193 var_t *var_lvar_assign_integer(char *name, fbint_t);
194 var_t *var_lvar_assign_double(char *name, double);
195 var_t *var_lvar_assign_string(char *name, char *string);
196 var_t *var_lvar_assign_var(char *name, char *src_name);
197 char *var_to_string(char *name);
198 char *var_randvar_to_string(char *name, int param);
199 int var_is_set4_randvar(char *name);
200 
201 #ifdef	__cplusplus
202 }
203 #endif
204 
205 #endif	/* _FB_VARS_H */
206