autocli.h (5065B)
1 /* 2 * 3 * 4 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 5 * 6 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 7 */ 8 9 #ifndef __BCM_INT_AUTOCLI_H__ 10 #define __BCM_INT_AUTOCLI_H__ 11 12 #include <sdk_config.h> 13 #include <bcm/types.h> 14 15 /* 16 * Sizes and configuration defines 17 */ 18 #ifndef AUTOCLI_MAX_FPARAMS 19 #define AUTOCLI_MAX_FPARAMS 32 20 #endif 21 22 #ifndef AUTOCLI_MAX_VARIABLE_NAME 23 #define AUTOCLI_MAX_VARIABLE_NAME 64 24 #endif 25 26 #ifndef AUTOCLI_MAX_VARIABLES 27 #define AUTOCLI_MAX_VARIABLES 1024 28 #endif 29 30 31 /****************************************************************************** 32 * 33 * Autogen Description Structures 34 */ 35 36 /* 37 * Description of a named parameter or structure member. 38 */ 39 typedef struct autocli_parameter_desc_s { 40 const char* basetype; 41 const char* name; 42 int pcount; 43 int array; 44 } autocli_parameter_desc_t; 45 46 typedef struct autocli_fparams_s { 47 void* rv; 48 void* args[AUTOCLI_MAX_FPARAMS]; 49 } autocli_fparams_t; 50 51 /* 52 * Function description structure 53 */ 54 55 typedef int (*autocli_wrapper_f)(autocli_fparams_t* params); 56 57 typedef struct autocli_function_s { 58 const char* name; 59 autocli_wrapper_f wrapper; 60 autocli_parameter_desc_t returns; 61 autocli_parameter_desc_t* params; 62 int nparams; 63 } autocli_function_t; 64 65 /* 66 * Structure description structure 67 */ 68 typedef struct autocli_struct_type_s { 69 const char* name; 70 int size; 71 const autocli_parameter_desc_t* struct_members; 72 void* (*maddr)(void* p, int idx); 73 } autocli_struct_type_t; 74 75 76 /* 77 * Enum value mapping structure 78 */ 79 typedef struct autocli_enum_map_s { 80 const char* name; 81 int value; 82 } autocli_enum_map_t; 83 84 /* 85 * Enum description structure 86 */ 87 typedef struct autocli_enum_type_s { 88 const char* name; 89 autocli_enum_map_t* enum_map; 90 } autocli_enum_type_t; 91 92 93 /* 94 * Autogenerated CLI Description Structure 95 */ 96 typedef struct autocli_data_s { 97 98 autocli_function_t* functions; 99 autocli_struct_type_t* structures; 100 autocli_enum_type_t* enums; 101 autocli_parameter_desc_t* typedefs; 102 103 } autocli_data_t; 104 105 106 /***************************************************************************** 107 * 108 * Public Interface 109 */ 110 111 /* 112 * Error Conditions 113 */ 114 typedef enum autocli_error_e { 115 116 AUTOCLI_E_NONE = 0, 117 AUTOCLI_E_INTERNAL = -1, 118 AUTOCLI_E_MEMORY = -2, 119 AUTOCLI_E_PARAM = -3, 120 AUTOCLI_E_EXISTS = -4, 121 AUTOCLI_E_TYPE_NOT_FOUND = -5, 122 AUTOCLI_E_BAD_VARIABLE = -6, 123 AUTOCLI_E_BAD_TYPE = -7, 124 AUTOCLI_E_NOT_FOUND = -8, 125 AUTOCLI_E_BAD_EXPRESSION = -9, 126 AUTOCLI_E_LAST = -10 127 128 } autocli_error_t; 129 130 131 /* 132 * Atomic data types structure 133 */ 134 #define AUTOCLI_ATOMIC_TYPE_F_INT 0x1 135 136 typedef struct autocli_atomic_type_s { 137 const char* name; 138 int size; 139 uint32 flags; 140 int (*print)(void* p); 141 int (*set)(void* p, const char* expr); 142 } autocli_atomic_type_t; 143 144 145 extern int autocli_init(autocli_atomic_type_t* atomics); 146 147 extern int autocli_add_data(autocli_data_t* data); 148 149 extern int autocli_validate_types(int print); 150 151 extern int autocli_variable_print(const char* var); 152 153 extern int autocli_variable_create(const char* var, const char* type); 154 155 extern int autocli_variable_delete(const char* var); 156 157 extern int autocli_variable_show(const char* var); 158 159 extern int autocli_variable_set(const char* var, const char* expr); 160 161 extern int autocli_function_call(const char* f, const char** params, void** rv); 162 163 extern const char* autocli_error(int err); 164 165 166 167 /***************************************************************************** 168 * 169 * The following data structures are private and used internally 170 */ 171 172 /* 173 * Generic datatype description structure 174 */ 175 #define AUTOCLI_DATATYPE_F_ATOMIC 0x1 176 #define AUTOCLI_DATATYPE_F_STRUCT 0x2 177 #define AUTOCLI_DATATYPE_F_ENUM 0x4 178 #define AUTOCLI_DATATYPE_F_FUNC 0x8 179 180 typedef struct autocli_datatype_s { 181 182 /* Flags for this datatype */ 183 uint32 flags; 184 185 /* 186 * The description of this datatype 187 */ 188 autocli_parameter_desc_t desc; 189 190 /* 191 * Pointer to the description of the basetype 192 */ 193 union { 194 autocli_atomic_type_t* ap; 195 autocli_struct_type_t* sp; 196 autocli_enum_type_t* ep; 197 autocli_function_t* fp; 198 void* p; 199 } basetype; 200 201 /* 202 * Original type name. May be different from basetype name based on aliases or typedefs. 203 * Also used for temporary storage. 204 */ 205 char type[AUTOCLI_MAX_VARIABLE_NAME]; 206 207 208 } autocli_datatype_t; 209 210 211 /* 212 * Generic variable instance structure 213 */ 214 215 #define AUTOCLI_VARIABLE_F_AUTO 0x1 216 #define AUTOCLI_VARIABLE_F_SDATA 0x2 217 218 typedef struct autocli_variable_s { 219 220 /* Variable Flags */ 221 uint32 flags; 222 223 /* The name of the variable */ 224 char name[AUTOCLI_MAX_VARIABLE_NAME]; 225 226 autocli_datatype_t dt; 227 228 void* data; 229 int size; 230 231 } autocli_variable_t; 232 233 234 235 #endif /* __BCM_INT_AUTOCLI_H__ */ 236