api_mode.h (3861B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: api_mode.h 8 * Purpose: API mode header 9 */ 10 11 #ifndef _API_MODE_H_ 12 #define _API_MODE_H_ 13 14 #include "tokenizer.h" 15 #include "cint_datatypes.h" 16 #include "shared/error.h" 17 18 #define API_MODE_E_NONE _SHR_E_NONE 19 #define API_MODE_E_INTERNAL _SHR_E_INTERNAL 20 #define API_MODE_E_MEMORY _SHR_E_MEMORY 21 #define API_MODE_E_UNIT _SHR_E_UNIT 22 #define API_MODE_E_PARAM _SHR_E_PARAM 23 #define API_MODE_E_EMPTY _SHR_E_EMPTY 24 #define API_MODE_E_FULL _SHR_E_FULL 25 #define API_MODE_E_NOT_FOUND _SHR_E_NOT_FOUND 26 #define API_MODE_E_EXISTS _SHR_E_EXISTS 27 #define API_MODE_E_TIMEOUT _SHR_E_TIMEOUT 28 #define API_MODE_E_BUSY _SHR_E_BUSY 29 #define API_MODE_E_FAIL _SHR_E_FAIL 30 #define API_MODE_E_DISABLED _SHR_E_DISABLED 31 #define API_MODE_E_BADID _SHR_E_BADID 32 #define API_MODE_E_RESOURCE _SHR_E_RESOURCE 33 #define API_MODE_E_CONFIG _SHR_E_CONFIG 34 #define API_MODE_E_UNAVAIL _SHR_E_UNAVAIL 35 #define API_MODE_E_INIT _SHR_E_INIT 36 #define API_MODE_E_PORT _SHR_E_PORT 37 38 #define API_MODE_SUCCESS(_rv) _SHR_E_SUCCESS(_rv) 39 #define API_MODE_FAILURE(_rv) _SHR_E_FAILURE(_rv) 40 #define API_MODE_IF_ERROR_RETURN(_rv) _SHR_E_IF_ERROR_RETURN(_rv) 41 42 #define HELP '?' 43 #define INFO '!' 44 45 #define IS_FIRST 0x0001 46 #define IS_VAR 0x0002 47 #define IS_TYPE 0x0004 48 49 typedef struct api_mode_arg_s { 50 int flags; 51 int kind; 52 const char *value; 53 api_mode_token_t *token; 54 const cint_datatype_t *dt; 55 struct api_mode_arg_s *sub; /* composite or keyword:value */ 56 struct api_mode_arg_s *parent; /* parent of sub */ 57 struct api_mode_arg_s *next; /* next in arg list */ 58 struct api_mode_arg_s *mm; /* next in memory management list */ 59 } api_mode_arg_t; 60 61 typedef int (*api_mode_arg_cb_t)(api_mode_arg_t *arg, void *user_data); 62 63 typedef struct api_mode_parse_s { 64 int verbose; 65 int done; 66 int result; 67 api_mode_arg_t *root; 68 api_mode_arg_t *base; 69 api_mode_arg_cb_t callback; 70 void *user_data; 71 } api_mode_parse_t; 72 73 extern int api_mode_debug; 74 75 extern int api_mode_token(const char *s, void *parser, 76 int kind, api_mode_arg_t **arg); 77 extern int api_mode_get(void *p, char *buf, int max_size); 78 79 extern api_mode_arg_t *api_mode_node(void *prs, const char *value, int kind); 80 extern api_mode_arg_t *api_mode_execute(void *prs, api_mode_arg_t *arg); 81 extern api_mode_arg_t *api_mode_mark(api_mode_arg_t *arg, int flag); 82 extern api_mode_arg_t *api_mode_sub(api_mode_arg_t *pri, api_mode_arg_t *sec); 83 extern api_mode_arg_t *api_mode_key_value(api_mode_arg_t *key, 84 api_mode_arg_t *value); 85 extern api_mode_arg_t *api_mode_range(api_mode_arg_t *from, 86 api_mode_arg_t *to, 87 api_mode_arg_t *times, 88 api_mode_arg_t *incr); 89 extern api_mode_arg_t *api_mode_append(api_mode_arg_t *src, 90 api_mode_arg_t *arg); 91 extern api_mode_arg_t *api_mode_sub_append(api_mode_arg_t *src, 92 api_mode_arg_t *arg); 93 94 extern api_mode_arg_t *api_mode_arg_next(api_mode_arg_t *arg); 95 96 #define PARSE_VERBOSE 0x0001 97 #define PARSE_DEBUG 0x0002 98 #define SCAN_DEBUG 0x0004 99 100 extern int api_mode_parse_string(const char *input, int flags, 101 api_mode_arg_cb_t cb, void *user_data); 102 extern void api_mode_show(int indent, api_mode_arg_t *start); 103 extern int api_mode_process_command(int u, char *s); 104 extern int api_mode_unexpected(void); 105 106 #endif /* _API_MODE_H_ */