libamxd  6.4.1
Data Model Manager
amxd_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(__AMXD_TYPES_H__)
56 #define __AMXD_TYPES_H__
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
63 #include <stdint.h>
64 
65 #if !defined(USE_DOXYGEN)
66 #define AMXD_INLINE static inline
67 #else
68 #define AMXD_INLINE
69 #endif
70 
75 //-----------------------------------------------------------------------------
76 // common typedefs, struct, enums
77 typedef enum _amxd_status {
108 
109 typedef enum _amxd_action {
111  action_any = 0, // callback functions added with this reason or always called
112  action_param_read, // read parameter value
113  action_param_write, // set parameter value
114  action_param_validate, // validate new value
115  action_param_describe, // get parameter definition
116  action_param_destroy, // remove and clean up parameter
117  action_object_read, // get all parameter values of an object
118  action_object_write, // set parameter values
119  action_object_validate, // validate the full object
120  action_object_list, // fetch list(s)
121  action_object_describe, // describe object, list all parameters, functions or children
122  action_object_tree, // list full tree, starting from an object
123  action_object_add_inst, // add an instance
124  action_object_del_inst, // verify instance can be deleted
125  action_object_destroy, // remove and clean up an object (any)
126  action_object_add_mib, // extend the object with a known mib
127  action_describe_action, // describe the action itself
129 
135 typedef enum _amxd_dm_access {
146 
147 typedef struct _amxd_object amxd_object_t;
148 typedef struct _amxd_parameter amxd_param_t;
149 
150 typedef amxd_status_t (* amxd_action_fn_t) (amxd_object_t* const object, // the object
151  amxd_param_t* const param, // the parameter
152  amxd_action_t reason, // the action id (reason)
153  const amxc_var_t* const args, // action arguments, when null default behaviour
154  amxc_var_t* const retval, // action retval
155  void* priv); // some private cb data (can be NULL)
156 
157 typedef struct _amxd_dm_cb {
158  amxc_llist_it_t it;
161  void* priv;
162  bool enable;
164 //-----------------------------------------------------------------------------
165 
166 //-----------------------------------------------------------------------------
167 // object related typedefs, structs & enums
177 typedef enum _amxd_object_type {
192 
198 typedef enum _amxd_oattr_id {
213 
214 typedef enum _amxd_direction {
219 
220 typedef struct _amxd_object_attr {
221  uint32_t read_only : 1; // object can not be changed directly, use functions to interact
222  // a read-only object is read only for remote clients
223  uint32_t persistent : 1; // object is persistent if in dm tree, dm save will store the object
224  uint32_t priv : 1; // object is private - not visible to remote clients
225  uint32_t locked : 1; // object is locked - not possible to add new functions or parameters
226  uint32_t prot : 1; // object is not visible from external sources
228 
229 struct _amxd_object {
230  amxc_llist_it_t it; // it.list pointer points to parent object in dm tree
231  // depending on type the list pointer is pointing to
232  // objects (singelton & templates)
233  // instances (instance object)
234  // data model mibs list
235 
236  amxd_object_type_t type; // object type
237  amxd_object_attr_t attr; // object attributes
238  char* name; // object name
239  char* index_name; // index as string, by default always null until requested
240  uint32_t index; // index - only valid for instance objects
241  uint32_t last_index; // last index used - only valid for template objects
242 
243  amxc_llist_t objects; // list of children in dm tree
244  amxc_llist_t instances; // list of instances - only used for template objects
245  amxc_llist_t functions; // list of functions - for derived objects only overides
246  amxc_llist_t parameters; // list of parameters
247 
248  amxc_llist_t derived_objects; // list of derived objects
249  amxc_llist_it_t derived_from; // derived_from.list points to source object derived_objects
250 
251  void* priv; // private data
252 
253  amxc_llist_t cb_fns; // action callback functions, see amxd_dm_cb_t
254  amxc_array_t mib_names; // array of added mib names
255 
256  amxc_var_t events; // list of event names
257 };
258 
259 typedef struct _amxd_dm {
261  amxp_signal_mngr_t sigmngr;
262  amxc_llist_t mibs;
264  amxc_llist_t deferred;
266 //-----------------------------------------------------------------------------
267 
268 //-----------------------------------------------------------------------------
269 // function related typedefs, structs & enums
270 typedef struct _amxd_function amxd_function_t;
271 
272 typedef amxd_status_t (* amxd_object_fn_t) (amxd_object_t* object, // object the function is called on
273  amxd_function_t* func, // the function definition
274  amxc_var_t* args, // incoming arguments (type = htable), can be used as out arguments
275  amxc_var_t* ret); // the return value
276 
282 typedef enum _amxd_aattr_id {
289 
290 typedef struct _amxd_arg_attr {
291  uint32_t in : 1; // in argument
292  uint32_t out : 1; // out argument
293  uint32_t mandatory : 1; // mandatory argument
294  uint32_t strict : 1; // strict typed (incomming value type must match defined type)
296 
297 typedef struct _amxd_func_arg {
298  amxc_llist_it_t it; // it.list points to the list containing argument in the function def
299  amxd_arg_attr_t attr; // argument attributes
300  char* name; // argument name
301  uint32_t type; // argument type, must be existing variant type, can be AMXC_VAR_ID_ANY
302  amxc_var_t default_value; // default value for optional arguments
304 
310 typedef enum _amxd_fattr_id {
324 
325 typedef struct _amxd_func_attr {
326  uint32_t templ : 1; // function can be called on template objects
327  uint32_t instance : 1; // function can be called on instance objects
328  // REMARK: functions on singleton objects should ignore these flags
329  uint32_t priv : 1; // function is private - not visible to remote clients
330  uint32_t prot : 1; // not visible from external sources (web-ui, usp, ...)
331  uint32_t async : 1; // function is handled asynchronously
333 
342  amxc_llist_it_t it; //< it.list points to the list containing functions in the objects
343  amxd_func_attr_t attr; //< function attributes
344  char* name; //< function name
345  uint32_t ret_type; //< function return type, must be a amxc_var_id
346  amxc_llist_t args; //< function arguments definition
347  amxd_object_fn_t impl; //< function implementation (when null = not implemented)
348  amxc_var_t* flags; //< function flags
349  void* priv; //< private user data
350 };
351 //-----------------------------------------------------------------------------
352 
353 //-----------------------------------------------------------------------------
354 typedef enum _amxd_pattr_id {
368 
369 typedef struct _amxd_param_attr {
370  uint32_t templ : 1; // parameter is available in template objects
371  uint32_t instance : 1; // parameter is available in instance objects
372  // REMARK: parametes in singleton objects should ignore these flags
373  uint32_t priv : 1; // parameter is private - not visible to remote clients
374  uint32_t read_only : 1; // parameter is read-only for remote clients
375  uint32_t persistent : 1; // parameter is persistent and should be stored in local
376  // storage when the containing object is saved
377  uint32_t variable : 1; // the parameter is volatile, no events are send
378  // rw funcs must be set
379  uint32_t counter : 1; // the parameter is an instance counter
380  uint32_t key : 1; // the parameter is a key parameter
381  uint32_t unique : 1; // Can only be set in combination with the key attribute
382  uint32_t prot : 1; // Not visible from external sources (web-ui, usp, ...)
383  uint32_t changeable : 1; // Indicates that the key parameter can be changed
385 
387  amxc_llist_it_t it; // it.list points to the list containing parameters in the objects
388  amxd_param_attr_t attr; // parameter attributes
389  char* name; // parameter name
390  amxc_var_t value; // parameter value
391  amxc_llist_t cb_fns; // action callback functions, see amxd_dm_cb_t
392  void* priv; // private data
393  amxc_var_t* flags; // parameter flags
394 };
395 //-----------------------------------------------------------------------------
396 
397 //-----------------------------------------------------------------------------
398 typedef enum _amxd_path_type {
405 
406 typedef struct _amxd_path {
407  amxc_string_t path;
408  char* param;
409  amxc_var_t parts;
411  const char* reason;
412  uint64_t ref_index;
414 
415 #ifdef __cplusplus
416 }
417 #endif
418 
419 #endif // __AMXD_TYPES_H__
420 
_amxd_pattr_id
Definition: amxd_types.h:354
@ amxd_pattr_template
Definition: amxd_types.h:355
@ amxd_pattr_private
Definition: amxd_types.h:357
@ amxd_pattr_persistent
Definition: amxd_types.h:359
@ amxd_pattr_variable
Definition: amxd_types.h:360
@ amxd_pattr_instance
Definition: amxd_types.h:356
@ amxd_pattr_unique
Definition: amxd_types.h:363
@ amxd_pattr_protected
Definition: amxd_types.h:364
@ amxd_pattr_mutable
Definition: amxd_types.h:365
@ amxd_pattr_key
Definition: amxd_types.h:362
@ amxd_pattr_read_only
Definition: amxd_types.h:358
@ amxd_pattr_counter
Definition: amxd_types.h:361
@ amxd_pattr_max
Definition: amxd_types.h:366
_amxd_action
Definition: amxd_types.h:109
@ action_param_write
Definition: amxd_types.h:113
@ action_object_write
Definition: amxd_types.h:118
@ action_object_add_inst
Definition: amxd_types.h:123
@ action_param_destroy
Definition: amxd_types.h:116
@ action_object_tree
Definition: amxd_types.h:122
@ action_invalid
Definition: amxd_types.h:110
@ action_object_del_inst
Definition: amxd_types.h:124
@ action_object_describe
Definition: amxd_types.h:121
@ action_describe_action
Definition: amxd_types.h:127
@ action_object_read
Definition: amxd_types.h:117
@ action_object_list
Definition: amxd_types.h:120
@ action_any
Definition: amxd_types.h:111
@ action_object_validate
Definition: amxd_types.h:119
@ action_object_destroy
Definition: amxd_types.h:125
@ action_param_read
Definition: amxd_types.h:112
@ action_param_validate
Definition: amxd_types.h:114
@ action_param_describe
Definition: amxd_types.h:115
@ action_object_add_mib
Definition: amxd_types.h:126
struct _amxd_func_arg amxd_func_arg_t
enum _amxd_path_type amxd_path_type_t
amxd_status_t(* amxd_action_fn_t)(amxd_object_t *const object, amxd_param_t *const param, amxd_action_t reason, const amxc_var_t *const args, amxc_var_t *const retval, void *priv)
Definition: amxd_types.h:150
enum _amxd_direction amxd_direction_t
struct _amxd_path amxd_path_t
enum _amxd_action amxd_action_t
struct _amxd_arg_attr amxd_arg_attr_t
enum _amxd_pattr_id amxd_pattr_id_t
enum _amxd_status amxd_status_t
struct _amxd_object_attr amxd_object_attr_t
_amxd_path_type
Definition: amxd_types.h:398
@ amxd_path_invalid
Definition: amxd_types.h:399
@ amxd_path_reference
Definition: amxd_types.h:403
@ amxd_path_supported
Definition: amxd_types.h:402
@ amxd_path_search
Definition: amxd_types.h:401
@ amxd_path_object
Definition: amxd_types.h:400
amxd_status_t(* amxd_object_fn_t)(amxd_object_t *object, amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
Definition: amxd_types.h:272
_amxd_status
Definition: amxd_types.h:77
@ amxd_status_invalid_arg
Definition: amxd_types.h:96
@ amxd_status_invalid_expr
Definition: amxd_types.h:100
@ amxd_status_read_only
Definition: amxd_types.h:93
@ amxd_status_invalid_name
Definition: amxd_types.h:86
@ amxd_status_invalid_attr
Definition: amxd_types.h:87
@ amxd_status_missing_key
Definition: amxd_types.h:94
@ amxd_status_parameter_not_found
Definition: amxd_types.h:82
@ amxd_status_function_not_implemented
Definition: amxd_types.h:83
@ amxd_status_last
Definition: amxd_types.h:106
@ amxd_status_permission_denied
Definition: amxd_types.h:101
@ amxd_status_invalid_path
Definition: amxd_types.h:99
@ amxd_status_not_instantiated
Definition: amxd_types.h:103
@ amxd_status_invalid_type
Definition: amxd_types.h:90
@ amxd_status_object_not_found
Definition: amxd_types.h:80
@ amxd_status_invalid_function
Definition: amxd_types.h:84
@ amxd_status_file_not_found
Definition: amxd_types.h:95
@ amxd_status_invalid_function_argument
Definition: amxd_types.h:85
@ amxd_status_ok
Definition: amxd_types.h:78
@ amxd_status_unknown_error
Definition: amxd_types.h:79
@ amxd_status_out_of_mem
Definition: amxd_types.h:97
@ amxd_status_timeout
Definition: amxd_types.h:105
@ amxd_status_invalid_value
Definition: amxd_types.h:88
@ amxd_status_invalid_action
Definition: amxd_types.h:89
@ amxd_status_not_a_template
Definition: amxd_types.h:104
@ amxd_status_deferred
Definition: amxd_types.h:92
@ amxd_status_not_supported
Definition: amxd_types.h:102
@ amxd_status_recursion
Definition: amxd_types.h:98
@ amxd_status_function_not_found
Definition: amxd_types.h:81
@ amxd_status_duplicate
Definition: amxd_types.h:91
struct _amxd_func_attr amxd_func_attr_t
struct _amxd_param_attr amxd_param_attr_t
struct _amxd_dm amxd_dm_t
_amxd_direction
Definition: amxd_types.h:214
@ amxd_direction_down
Definition: amxd_types.h:216
@ amxd_direction_down_reverse
Definition: amxd_types.h:217
@ amxd_direction_up
Definition: amxd_types.h:215
struct _amxd_dm_cb amxd_dm_cb_t
_amxd_fattr_id
The method attributes.
Definition: amxd_types.h:310
enum _amxd_fattr_id amxd_fattr_id_t
The method attributes.
enum _amxd_object_type amxd_object_type_t
The different object types.
_amxd_aattr_id
The method argument attributes.
Definition: amxd_types.h:282
enum _amxd_dm_access amxd_dm_access_t
Access level.
enum _amxd_aattr_id amxd_aattr_id_t
The method argument attributes.
enum _amxd_oattr_id amxd_oattr_id_t
The object attributes.
_amxd_oattr_id
The object attributes.
Definition: amxd_types.h:198
_amxd_dm_access
Access level.
Definition: amxd_types.h:135
_amxd_object_type
The different object types.
Definition: amxd_types.h:177
@ amxd_fattr_max
Definition: amxd_types.h:322
@ amxd_fattr_template
Definition: amxd_types.h:311
@ amxd_fattr_async
Definition: amxd_types.h:321
@ amxd_fattr_private
Definition: amxd_types.h:313
@ amxd_fattr_protected
Definition: amxd_types.h:317
@ amxd_fattr_instance
Definition: amxd_types.h:312
@ amxd_aattr_max
Definition: amxd_types.h:287
@ amxd_aattr_strict
Definition: amxd_types.h:286
@ amxd_aattr_in
Definition: amxd_types.h:283
@ amxd_aattr_mandatory
Definition: amxd_types.h:285
@ amxd_aattr_out
Definition: amxd_types.h:284
@ amxd_oattr_read_only
Definition: amxd_types.h:199
@ amxd_oattr_locked
Definition: amxd_types.h:206
@ amxd_oattr_protected
Definition: amxd_types.h:210
@ amxd_oattr_max
Definition: amxd_types.h:211
@ amxd_oattr_persistent
Definition: amxd_types.h:200
@ amxd_oattr_private
Definition: amxd_types.h:202
@ amxd_dm_access_private
Definition: amxd_types.h:141
@ amxd_dm_access_protected
Definition: amxd_types.h:139
@ amxd_dm_access_public
Definition: amxd_types.h:136
@ amxd_object_root
Definition: amxd_types.h:178
@ amxd_object_template
Definition: amxd_types.h:183
@ amxd_object_mib
Definition: amxd_types.h:188
@ amxd_object_singleton
Definition: amxd_types.h:181
@ amxd_object_instance
Definition: amxd_types.h:186
@ amxd_object_invalid
Definition: amxd_types.h:190
uint32_t in
Definition: amxd_types.h:291
uint32_t strict
Definition: amxd_types.h:294
uint32_t mandatory
Definition: amxd_types.h:293
uint32_t out
Definition: amxd_types.h:292
amxc_llist_it_t it
Definition: amxd_types.h:158
amxd_action_t reason
Definition: amxd_types.h:160
void * priv
Definition: amxd_types.h:161
amxd_action_fn_t fn
Definition: amxd_types.h:159
amxc_llist_t mibs
Definition: amxd_types.h:262
amxd_status_t status
Definition: amxd_types.h:263
amxd_object_t object
Definition: amxd_types.h:260
amxc_llist_t deferred
Definition: amxd_types.h:264
amxp_signal_mngr_t sigmngr
Definition: amxd_types.h:261
amxc_llist_it_t it
Definition: amxd_types.h:298
amxc_var_t default_value
Definition: amxd_types.h:302
uint32_t type
Definition: amxd_types.h:301
amxd_arg_attr_t attr
Definition: amxd_types.h:299
uint32_t templ
Definition: amxd_types.h:326
uint32_t priv
Definition: amxd_types.h:329
uint32_t async
Definition: amxd_types.h:331
uint32_t prot
Definition: amxd_types.h:330
uint32_t instance
Definition: amxd_types.h:327
RPC method structure.
Definition: amxd_types.h:341
amxc_llist_t args
Definition: amxd_types.h:346
amxc_llist_it_t it
Definition: amxd_types.h:342
uint32_t ret_type
Definition: amxd_types.h:345
amxc_var_t * flags
Definition: amxd_types.h:348
amxd_object_fn_t impl
Definition: amxd_types.h:347
amxd_func_attr_t attr
Definition: amxd_types.h:343
uint32_t read_only
Definition: amxd_types.h:221
uint32_t persistent
Definition: amxd_types.h:223
amxc_llist_t derived_objects
Definition: amxd_types.h:248
amxc_llist_it_t derived_from
Definition: amxd_types.h:249
amxd_object_type_t type
Definition: amxd_types.h:236
amxd_object_attr_t attr
Definition: amxd_types.h:237
uint32_t last_index
Definition: amxd_types.h:241
amxc_llist_t functions
Definition: amxd_types.h:245
amxc_llist_t cb_fns
Definition: amxd_types.h:253
uint32_t index
Definition: amxd_types.h:240
amxc_llist_t objects
Definition: amxd_types.h:243
amxc_array_t mib_names
Definition: amxd_types.h:254
char * name
Definition: amxd_types.h:238
amxc_llist_it_t it
Definition: amxd_types.h:230
amxc_llist_t instances
Definition: amxd_types.h:244
void * priv
Definition: amxd_types.h:251
amxc_var_t events
Definition: amxd_types.h:256
char * index_name
Definition: amxd_types.h:239
amxc_llist_t parameters
Definition: amxd_types.h:246
uint32_t unique
Definition: amxd_types.h:381
uint32_t templ
Definition: amxd_types.h:370
uint32_t persistent
Definition: amxd_types.h:375
uint32_t read_only
Definition: amxd_types.h:374
uint32_t variable
Definition: amxd_types.h:377
uint32_t changeable
Definition: amxd_types.h:383
uint32_t instance
Definition: amxd_types.h:371
uint32_t counter
Definition: amxd_types.h:379
amxc_llist_it_t it
Definition: amxd_types.h:387
amxc_var_t value
Definition: amxd_types.h:390
amxd_param_attr_t attr
Definition: amxd_types.h:388
amxc_var_t * flags
Definition: amxd_types.h:393
amxc_llist_t cb_fns
Definition: amxd_types.h:391
amxd_path_type_t type
Definition: amxd_types.h:410
char * param
Definition: amxd_types.h:408
const char * reason
Definition: amxd_types.h:411
amxc_string_t path
Definition: amxd_types.h:407
amxc_var_t parts
Definition: amxd_types.h:409
uint64_t ref_index
Definition: amxd_types.h:412