libamxo  4.3.4
Object Definition Language (ODL) parsing
amxo_types.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2023 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or without modification,
8 ** are permitted provided that the following conditions are met:
9 **
10 ** 1. Redistributions of source code must retain the above copyright notice,
11 ** this list of conditions and the following disclaimer.
12 **
13 ** 2. Redistributions in binary form must reproduce the above copyright notice,
14 ** this list of conditions and the following disclaimer in the documentation
15 ** and/or other materials provided with the distribution.
16 **
17 ** Subject to the terms and conditions of this license, each copyright holder
18 ** and contributor hereby grants to those receiving rights under this license
19 ** a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
20 ** (except for failure to satisfy the conditions of this license) patent license
21 ** to make, have made, use, offer to sell, sell, import, and otherwise transfer
22 ** this software, where such license applies only to those patent claims, already
23 ** acquired or hereafter acquired, licensable by such copyright holder or contributor
24 ** that are necessarily infringed by:
25 **
26 ** (a) their Contribution(s) (the licensed copyrights of copyright holders and
27 ** non-copyrightable additions of contributors, in source or binary form) alone;
28 ** or
29 **
30 ** (b) combination of their Contribution(s) with the work of authorship to which
31 ** such Contribution(s) was added by such copyright holder or contributor, if,
32 ** at the time the Contribution is added, such addition causes such combination
33 ** to be necessarily infringed. The patent license shall not apply to any other
34 ** combinations which include the Contribution.
35 **
36 ** Except as expressly stated above, no rights or licenses from any copyright
37 ** holder or contributor is granted under this license, whether expressly, by
38 ** implication, estoppel or otherwise.
39 **
40 ** DISCLAIMER
41 **
42 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
46 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
51 ** USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 **
53 ****************************************************************************/
54 
55 #if !defined(__AMXO_TYPES_H__)
56 #define __AMXO_TYPES_H__
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
63 #include <amxc/amxc.h>
64 #include <amxd/amxd_types.h>
65 #include <amxp/amxp_connection.h>
66 
67 typedef struct _amxo_parser amxo_parser_t;
68 
69 typedef ssize_t (* amxo_reader_t) (amxo_parser_t* parser, char* buf, size_t max_size);
70 
71 typedef void (* amxo_fn_ptr_t)(void);
72 
80 #define AMXO_FUNC(x) ((amxo_fn_ptr_t) x)
81 
82 typedef enum _amxo_fn_type {
88 
89 typedef void (* amxo_res_get_default_t) (amxo_parser_t* parser, void* priv);
90 
92  const char* fn_name,
93  amxo_fn_type_t type,
94  const char* data,
95  void* priv);
96 
97 typedef void (* amxo_res_clean_fn_t) (amxo_parser_t* parser,
98  void* priv);
99 
100 typedef struct _amxo_resolver {
101  amxc_htable_it_t hit;
105  void* priv;
107 
108 typedef void (* amxo_comment_t) (amxo_parser_t* parser, const char* comment);
109 
110 typedef void (* amxo_start_end_t) (amxo_parser_t* parser);
111 
112 typedef void (* amxo_include_t) (amxo_parser_t* parser,
113  const char* file);
114 
115 typedef void (* amxo_section_t) (amxo_parser_t* parser,
116  int section_id);
117 
118 typedef void (* amxo_set_config_t) (amxo_parser_t* parser,
119  const char* option,
120  amxc_var_t* value);
121 
122 typedef void (* amxo_create_object_t) (amxo_parser_t* parser,
123  amxd_object_t* parent,
124  const char* name,
125  int64_t attr_bitmask,
126  amxd_object_type_t type);
127 
128 typedef void (* amxo_add_instance_t) (amxo_parser_t* parser,
129  amxd_object_t* parent,
130  uint32_t index,
131  const char* name);
132 
133 typedef void (* amxo_select_object_t) (amxo_parser_t* parser,
134  amxd_object_t* parent,
135  const char* path);
136 
137 typedef void (* amxo_end_object_t) (amxo_parser_t* parser,
138  amxd_object_t* object);
139 
140 typedef void (* amxo_add_mib_t) (amxo_parser_t* parser,
141  amxd_object_t* object,
142  const char* mib);
143 
144 typedef void (* amxo_add_param_func_t) (amxo_parser_t* parser,
145  amxd_object_t* object,
146  const char* name,
147  int64_t attr_bitmask,
148  uint32_t type);
149 
150 typedef void (* amxo_set_param_t) (amxo_parser_t* parser,
151  amxd_object_t* object,
152  amxd_param_t* param,
153  amxc_var_t* value);
154 
155 typedef void (* amxo_end_param_t) (amxo_parser_t* parser,
156  amxd_object_t* object,
157  amxd_param_t* param);
158 typedef void (* amxo_end_func_t) (amxo_parser_t* parser,
159  amxd_object_t* object,
160  amxd_function_t* function);
161 
162 typedef void (* amxo_add_func_arg_t) (amxo_parser_t* parser,
163  amxd_object_t* object,
164  amxd_function_t* func,
165  const char* name,
166  int64_t attr_bitmask,
167  uint32_t type,
168  amxc_var_t* def_value);
169 
170 typedef void (* amxo_set_counter_t) (amxo_parser_t* parser,
171  amxd_object_t* parent,
172  const char* name);
173 
174 typedef void (* amxo_set_action_cb_t) (amxo_parser_t* parser,
175  amxd_object_t* object,
176  amxd_param_t* param,
177  amxd_action_t action_id,
178  const char* action_name,
179  const amxc_var_t* data);
180 
181 typedef struct _amxo_hooks {
182  amxc_llist_it_t it;
205 
206 typedef enum _amxo_reason {
211 
212 typedef enum _amxo_con_type {
217 
218 typedef int (* amxo_entry_point_t) (int reason,
219  amxd_dm_t* dm,
220  amxo_parser_t* parser);
221 
222 typedef struct _amxo_entry {
223  amxc_llist_it_t it;
226 
227 typedef void (* amxo_fd_cb_t) (int fd, void* priv);
228 
229 #define amxo_fd_read_t amxo_fd_cb_t
230 #define amxo_connection_t amxp_connection_t
231 
245 struct _amxo_parser {
246  void* scanner;
247  int fd;
250  amxc_var_t config;
253  amxc_llist_t global_config;
256  amxc_rbuffer_t rbuffer;
258  amxd_status_t status;
259  amxc_string_t msg;
261  amxc_astack_t object_stack;
262  amxd_object_t* object;
263  amxd_param_t* param;
264  amxd_function_t* func;
265  amxc_var_t* data;
267  amxc_string_t* resolved_fn_name;
268  amxc_llist_t function_names;
269  amxc_htable_t* resolvers;
271  amxc_llist_t* _unused_1;
272  amxc_llist_t* _unused_2;
273  amxc_llist_t* entry_points;
274  amxc_llist_t* hooks;
275  amxc_var_t* post_includes;
277  amxc_var_t* include_stack;
279  const char* file;
280  uint32_t line;
281 
282  amxc_htable_t mibs;
283  amxc_lstack_t event_list;
286 
287  char buffer[128];
288  size_t buffer_len;
289 
290  amxc_llist_t* sync_contexts;
291 };
292 
293 #ifdef __cplusplus
294 }
295 #endif
296 
297 #endif // __AMXO_TYPES_H__
298 
void(* amxo_fn_ptr_t)(void)
Definition: amxo_types.h:71
void(* amxo_add_instance_t)(amxo_parser_t *parser, amxd_object_t *parent, uint32_t index, const char *name)
Definition: amxo_types.h:128
void(* amxo_start_end_t)(amxo_parser_t *parser)
Definition: amxo_types.h:110
void(* amxo_create_object_t)(amxo_parser_t *parser, amxd_object_t *parent, const char *name, int64_t attr_bitmask, amxd_object_type_t type)
Definition: amxo_types.h:122
amxo_fn_ptr_t(* amxo_res_resolve_fn_t)(amxo_parser_t *parser, const char *fn_name, amxo_fn_type_t type, const char *data, void *priv)
Definition: amxo_types.h:91
void(* amxo_set_action_cb_t)(amxo_parser_t *parser, amxd_object_t *object, amxd_param_t *param, amxd_action_t action_id, const char *action_name, const amxc_var_t *data)
Definition: amxo_types.h:174
struct _amxo_hooks amxo_hooks_t
ssize_t(* amxo_reader_t)(amxo_parser_t *parser, char *buf, size_t max_size)
Definition: amxo_types.h:69
void(* amxo_include_t)(amxo_parser_t *parser, const char *file)
Definition: amxo_types.h:112
void(* amxo_add_param_func_t)(amxo_parser_t *parser, amxd_object_t *object, const char *name, int64_t attr_bitmask, uint32_t type)
Definition: amxo_types.h:144
enum _amxo_fn_type amxo_fn_type_t
void(* amxo_set_config_t)(amxo_parser_t *parser, const char *option, amxc_var_t *value)
Definition: amxo_types.h:118
void(* amxo_add_mib_t)(amxo_parser_t *parser, amxd_object_t *object, const char *mib)
Definition: amxo_types.h:140
struct _amxo_resolver amxo_resolver_t
void(* amxo_set_param_t)(amxo_parser_t *parser, amxd_object_t *object, amxd_param_t *param, amxc_var_t *value)
Definition: amxo_types.h:150
void(* amxo_select_object_t)(amxo_parser_t *parser, amxd_object_t *parent, const char *path)
Definition: amxo_types.h:133
void(* amxo_res_get_default_t)(amxo_parser_t *parser, void *priv)
Definition: amxo_types.h:89
_amxo_fn_type
Definition: amxo_types.h:82
@ amxo_function_ep
Definition: amxo_types.h:86
@ amxo_function_rpc
Definition: amxo_types.h:84
@ amxo_function_event
Definition: amxo_types.h:85
@ amxo_function_action
Definition: amxo_types.h:83
void(* amxo_end_func_t)(amxo_parser_t *parser, amxd_object_t *object, amxd_function_t *function)
Definition: amxo_types.h:158
void(* amxo_end_object_t)(amxo_parser_t *parser, amxd_object_t *object)
Definition: amxo_types.h:137
void(* amxo_section_t)(amxo_parser_t *parser, int section_id)
Definition: amxo_types.h:115
int(* amxo_entry_point_t)(int reason, amxd_dm_t *dm, amxo_parser_t *parser)
Definition: amxo_types.h:218
void(* amxo_set_counter_t)(amxo_parser_t *parser, amxd_object_t *parent, const char *name)
Definition: amxo_types.h:170
enum _amxo_reason amxo_reason_t
struct _amxo_entry amxo_entry_t
enum _amxo_con_type amxo_con_type_t
_amxo_reason
Definition: amxo_types.h:206
@ AMXO_ODL_LOADED
Definition: amxo_types.h:209
@ AMXO_START
Definition: amxo_types.h:207
@ AMXO_STOP
Definition: amxo_types.h:208
_amxo_con_type
Definition: amxo_types.h:212
@ AMXO_CUSTOM
Definition: amxo_types.h:215
@ AMXO_LISTEN
Definition: amxo_types.h:214
@ AMXO_BUS
Definition: amxo_types.h:213
void(* amxo_add_func_arg_t)(amxo_parser_t *parser, amxd_object_t *object, amxd_function_t *func, const char *name, int64_t attr_bitmask, uint32_t type, amxc_var_t *def_value)
Definition: amxo_types.h:162
void(* amxo_res_clean_fn_t)(amxo_parser_t *parser, void *priv)
Definition: amxo_types.h:97
void(* amxo_fd_cb_t)(int fd, void *priv)
Definition: amxo_types.h:227
void(* amxo_end_param_t)(amxo_parser_t *parser, amxd_object_t *object, amxd_param_t *param)
Definition: amxo_types.h:155
void(* amxo_comment_t)(amxo_parser_t *parser, const char *comment)
Definition: amxo_types.h:108
Definition: amxo_types.h:222
amxo_entry_point_t entry_point
Definition: amxo_types.h:224
amxc_llist_it_t it
Definition: amxo_types.h:223
amxo_include_t start_include
Definition: amxo_types.h:186
amxo_set_counter_t set_counter
Definition: amxo_types.h:202
amxo_comment_t comment
Definition: amxo_types.h:183
amxo_start_end_t end
Definition: amxo_types.h:185
amxo_add_func_arg_t add_func_arg
Definition: amxo_types.h:199
amxo_add_instance_t add_instance
Definition: amxo_types.h:192
amxo_section_t end_section
Definition: amxo_types.h:190
amxc_llist_it_t it
Definition: amxo_types.h:182
amxo_add_param_func_t add_param
Definition: amxo_types.h:195
amxo_end_func_t end_func
Definition: amxo_types.h:200
amxo_end_param_t end_param
Definition: amxo_types.h:197
amxo_section_t start_section
Definition: amxo_types.h:189
amxo_set_action_cb_t set_action_cb
Definition: amxo_types.h:203
amxo_add_param_func_t add_func
Definition: amxo_types.h:198
amxo_select_object_t select_object
Definition: amxo_types.h:193
amxo_set_config_t set_config
Definition: amxo_types.h:188
amxo_start_end_t start
Definition: amxo_types.h:184
amxo_add_mib_t add_mib
Definition: amxo_types.h:201
amxo_set_param_t set_param
Definition: amxo_types.h:196
amxo_end_object_t end_object
Definition: amxo_types.h:194
amxo_create_object_t create_object
Definition: amxo_types.h:191
amxo_include_t end_include
Definition: amxo_types.h:187
The ODL parser structure.
Definition: amxo_types.h:245
amxc_htable_t * resolvers
Definition: amxo_types.h:269
amxc_htable_t mibs
Definition: amxo_types.h:282
amxo_fn_ptr_t resolved_fn
Definition: amxo_types.h:266
amxc_llist_t * hooks
Definition: amxo_types.h:274
char buffer[128]
Definition: amxo_types.h:287
amxc_llist_t * _unused_2
Definition: amxo_types.h:272
amxc_astack_t object_stack
Definition: amxo_types.h:261
size_t buffer_len
Definition: amxo_types.h:288
amxc_lstack_t event_list
Definition: amxo_types.h:283
amxc_llist_t function_names
Definition: amxo_types.h:268
amxo_reader_t reader
Definition: amxo_types.h:257
amxc_string_t msg
Definition: amxo_types.h:259
amxd_param_t * param
Definition: amxo_types.h:263
amxc_var_t config
Definition: amxo_types.h:250
amxc_string_t * resolved_fn_name
Definition: amxo_types.h:267
amxc_rbuffer_t rbuffer
Definition: amxo_types.h:256
amxc_var_t * include_stack
Definition: amxo_types.h:277
amxc_llist_t * _unused_1
Definition: amxo_types.h:271
const char * file
Definition: amxo_types.h:279
amxc_llist_t * entry_points
Definition: amxo_types.h:273
amxd_status_t status
Definition: amxo_types.h:258
uint32_t line
Definition: amxo_types.h:280
amxc_var_t * data
Definition: amxo_types.h:265
amxc_llist_t global_config
Definition: amxo_types.h:253
void * scanner
Definition: amxo_types.h:246
amxc_var_t * post_includes
Definition: amxo_types.h:275
amxd_object_t * object
Definition: amxo_types.h:262
amxd_function_t * func
Definition: amxo_types.h:264
amxo_parser_t * parent
Definition: amxo_types.h:285
amxc_llist_t * sync_contexts
Definition: amxo_types.h:290
amxo_res_get_default_t get
Definition: amxo_types.h:102
amxo_res_resolve_fn_t resolve
Definition: amxo_types.h:103
amxo_res_clean_fn_t clean
Definition: amxo_types.h:104
amxc_htable_it_t hit
Definition: amxo_types.h:101