libamxd  6.4.1
Data Model Manager
Collaboration diagram for Parameters:

Macros

#define amxd_object_set_value(type, object, name, value)    amxd_object_set_ ## type(object, name, value)
 Helper macro for setting a value. More...
 
#define amxd_object_get_value(type, object, name, status)    amxd_object_get_ ## type(object, name, status)
 Helper macro for getting a value. More...
 

Functions

amxd_status_t amxd_object_add_param (amxd_object_t *const object, amxd_param_t *const param)
 Adds a parameter definition to an object. More...
 
amxd_param_tamxd_object_get_param_def (const amxd_object_t *const object, const char *name)
 Gets a parameter definition from an object. More...
 
amxd_status_t amxd_object_set_param (amxd_object_t *const object, const char *name, amxc_var_t *const value)
 Sets a value for a parameter in a data model object. More...
 
amxd_status_t amxd_object_set_params (amxd_object_t *const object, amxc_var_t *const values)
 Sets multiple parameter values in a data model object. More...
 
amxd_status_t amxd_object_get_param (amxd_object_t *const object, const char *name, amxc_var_t *const value)
 Gets a single parameter value. More...
 
const amxc_var_t * amxd_object_get_param_value (const amxd_object_t *const object, const char *name)
 Gets the variant in which the parameter value is stored. More...
 
amxd_status_t amxd_object_get_params (amxd_object_t *const object, amxc_var_t *const params, amxd_dm_access_t access)
 Gets all parameter values of an object. More...
 

Detailed Description

Macro Definition Documentation

◆ amxd_object_get_value

#define amxd_object_get_value (   type,
  object,
  name,
  status 
)     amxd_object_get_ ## type(object, name, status)

Helper macro for getting a value.

This helper macro gets a value, using a type indicator

Parameters
typethe data type that must be returned
objectpointer to a data model object
nameparameter name
statusoptional pointer to a amxd_status_t or NULL

Definition at line 100 of file amxd_object_parameter.h.

◆ amxd_object_set_value

#define amxd_object_set_value (   type,
  object,
  name,
  value 
)     amxd_object_set_ ## type(object, name, value)

Helper macro for setting a value.

This helper macro sets a value for a certain parameter

Parameters
typethe data type, must be a valid parameter type, or must be convertable to a valid parameter type
objectpointer to a data model object
nameparameter name
valuethe new value, must match the given type

Definition at line 85 of file amxd_object_parameter.h.

Function Documentation

◆ amxd_object_add_param()

amxd_status_t amxd_object_add_param ( amxd_object_t *const  object,
amxd_param_t *const  param 
)

Adds a parameter definition to an object.

The parameter definition can be created using amxd_param_new.

Adding the parameter definition to an object fails when:

  • The parameter definition was already added to an object
  • The amxd_oattr_locked atrtribute was set on the object
  • The parameter definition is a key parameter and the object is a mult-instance object with instances, is an instance object, is a singleton object, is a mib definition.
  • The object contains already a parameter with the same name

When adding a parameter definition to a multi-instance object or an instance object and none of the following parameters attributes are set:

Parameters
objectpointer to a data model object, the parameter definition is added to this object
parampointer to the parameter definition
Returns
  • amxd_status_ok: parameter definition is added to the data model object
  • amxd_status_duplicate: parameter definition can not be added, another parameter exists with the same name
  • amxd_status_invalid_attr: parameter can not be added because the object and parameter attributes do not match
  • amxd_status_unknown_error: any other error

Definition at line 96 of file amxd_object_parameter.c.

97  {
99  amxd_param_t* object_param = NULL;
100  when_null(object, exit);
101  when_null(param, exit);
102  when_not_null(param->it.llist, exit);
103 
104  when_true(amxd_object_is_attr_set(object, amxd_oattr_locked), exit);
105 
106  retval = amxd_object_check_key_param(object, param);
107  when_failed(retval, exit);
108 
109  amxc_llist_for_each(it, (&object->parameters)) {
110  const char* object_param_name = NULL;
111  const char* param_name = NULL;
112  object_param = amxc_llist_it_get_data(it, amxd_param_t, it);
113  object_param_name = amxd_param_get_name(object_param);
114  param_name = amxd_param_get_name(param);
115  if(strcmp(param_name, object_param_name) == 0) {
116  retval = amxd_status_duplicate;
117  goto exit;
118  }
119  object_param = NULL;
120  }
121 
122  // parameters added to template object by default only work on
123  // instances. This is a design descision.
124  // For other behavior set the attributes before adding the parameter
125  // to the object
126  if((amxd_object_get_type(object) == amxd_object_template) ||
128  if((param->attr.instance == 0) && (param->attr.templ == 0)) {
129  param->attr.instance = 1;
130  }
131  }
132 
134  if((param->attr.templ == 1) && (param->attr.instance == 0)) {
135  retval = amxd_status_invalid_attr;
136  goto exit;
137  }
138  }
139 
140  amxc_llist_append(&object->parameters, &param->it);
141 
142 exit:
143  return retval;
144 }
static amxd_status_t amxd_object_check_key_param(amxd_object_t *const object, amxd_param_t *const param)
const char * amxd_param_get_name(const amxd_param_t *const param)
enum _amxd_status amxd_status_t
@ amxd_status_invalid_attr
Definition: amxd_types.h:87
@ amxd_status_unknown_error
Definition: amxd_types.h:79
@ amxd_status_duplicate
Definition: amxd_types.h:91
@ amxd_oattr_locked
Definition: amxd_types.h:206
@ amxd_object_template
Definition: amxd_types.h:183
@ amxd_object_instance
Definition: amxd_types.h:186
static amxd_object_type_t amxd_object_get_type(const amxd_object_t *const object)
Returns the object type.
Definition: amxd_object.h:586
bool amxd_object_is_attr_set(const amxd_object_t *const object, const amxd_oattr_id_t attr)
Checks if an attribute is set.
Definition: amxd_object.c:348
amxc_llist_t parameters
Definition: amxd_types.h:246
uint32_t templ
Definition: amxd_types.h:370
uint32_t instance
Definition: amxd_types.h:371
amxc_llist_it_t it
Definition: amxd_types.h:387
amxd_param_attr_t attr
Definition: amxd_types.h:388

◆ amxd_object_get_param()

amxd_status_t amxd_object_get_param ( amxd_object_t *const  object,
const char *  name,
amxc_var_t *const  value 
)

Gets a single parameter value.

This function invokes an action_object_read and can read private and protected parameters.

The default implementation of the action_object_read will fetch the real value of the paranmeter.

The action_object_read implementation can be overriden.

As an alternative to get a single parameter value of an object the macro amxd_object_get_value can be used.

Parameters
objectpointer to a data model object
namethe name of the parameter
valuean initialized variant, the value of the parameter will be copied in this variant.
Returns
amxd_status_ok when the new value is set correctly.

Definition at line 252 of file amxd_object_parameter.c.

254  {
256  amxc_var_t args;
257  amxc_var_t* params = NULL;
258  amxc_var_t params_value;
259  amxd_param_t* def = NULL;
260 
261  amxc_var_init(&args);
262  amxc_var_init(&params_value);
263  when_null(object, exit);
264  when_null(value, exit);
265  when_str_empty(name, exit);
266 
267  def = amxd_object_get_param_def(object, name);
268  if(def != NULL) {
271  amxc_var_copy(value, &def->value);
272  retval = amxd_status_ok;
273  goto exit;
274  }
275  }
276  }
277 
278  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
279  amxc_var_add_key(uint32_t, &args, "access", amxd_dm_access_private);
280  params = amxc_var_add_key(amxc_llist_t, &args, "parameters", NULL);
281  amxc_var_add(cstring_t, params, name);
282  retval = amxd_dm_invoke_action(object,
283  NULL,
285  &args,
286  &params_value);
287  if(retval == amxd_status_ok) {
288  amxc_var_t* param_val = amxc_var_get_path(&params_value,
289  name,
290  AMXC_VAR_FLAG_DEFAULT);
291  when_null_status(param_val, exit, retval = amxd_status_parameter_not_found);
292  amxc_var_copy(value, param_val);
293  }
294 
295 exit:
296  amxc_var_clean(&params_value);
297  amxc_var_clean(&args);
298  return retval;
299 }
amxd_status_t amxd_dm_invoke_action(amxd_object_t *object, amxd_param_t *param, amxd_action_t reason, const amxc_var_t *const args, amxc_var_t *const retval)
Definition: amxd_dm.c:591
bool amxd_object_has_action(amxd_object_t *const object, const amxd_action_t reason)
bool amxd_param_has_action(amxd_param_t *const param, const amxd_action_t reason)
@ action_object_read
Definition: amxd_types.h:117
@ action_param_read
Definition: amxd_types.h:112
@ amxd_status_parameter_not_found
Definition: amxd_types.h:82
@ amxd_status_ok
Definition: amxd_types.h:78
@ amxd_dm_access_private
Definition: amxd_types.h:141
amxd_param_t * amxd_object_get_param_def(const amxd_object_t *const object, const char *name)
Gets a parameter definition from an object.
amxc_var_t value
Definition: amxd_types.h:390

◆ amxd_object_get_param_def()

amxd_param_t* amxd_object_get_param_def ( const amxd_object_t *const  object,
const char *  name 
)

Gets a parameter definition from an object.

Parameters
objectpointer to a data model object
namename of the parameter
Returns
a pointer to a parameter definition or NULL if no parameter definition is found for the given name.

Definition at line 146 of file amxd_object_parameter.c.

147  {
148  amxd_param_t* param = NULL;
149  amxd_path_t param_path;
150  amxd_object_t* real_obj = (amxd_object_t*) object;
151  const char* rel_path = NULL;
152 
153  amxd_path_init(&param_path, name);
154 
155  when_null(object, exit);
156  when_str_empty(name, exit);
157  when_true(object->type == amxd_object_root, exit);
158 
159  rel_path = amxd_path_get(&param_path, AMXD_OBJECT_TERMINATE);
160  real_obj = amxd_object_findf(real_obj, "%s", rel_path);
161  when_null(real_obj, exit);
162 
163  amxc_llist_for_each(it, (&real_obj->parameters)) {
164  const char* param_name = NULL;
165  param = amxc_llist_it_get_data(it, amxd_param_t, it);
166  param_name = amxd_param_get_name(param);
167  if(strcmp(param_name, amxd_path_get_param(&param_path)) == 0) {
168  break;
169  }
170  param = NULL;
171  }
172 
173 exit:
174  amxd_path_clean(&param_path);
175  return param;
176 }
#define AMXD_OBJECT_TERMINATE
Path format flag - when set the object path is terminated with a dot.
Definition: amxd_object.h:214
@ amxd_object_root
Definition: amxd_types.h:178
amxd_object_t * amxd_object_findf(amxd_object_t *object, const char *rel_path,...) __attribute__((format(printf
Find an object in the data model tree, starting from an object.
amxd_status_t amxd_path_init(amxd_path_t *path, const char *object_path)
Initializes an amxd_path_t structure.
Definition: amxd_path.c:328
const char * amxd_path_get_param(amxd_path_t *path)
Gets the parameter name.
Definition: amxd_path.c:497
const char * amxd_path_get(amxd_path_t *path, int flags)
Returns the path stored in the amxd_path_t structure.
Definition: amxd_path.c:470
void amxd_path_clean(amxd_path_t *path)
Cleans an amxd_path_t structure.
Definition: amxd_path.c:351
amxd_object_type_t type
Definition: amxd_types.h:236

◆ amxd_object_get_param_value()

const amxc_var_t* amxd_object_get_param_value ( const amxd_object_t *const  object,
const char *  name 
)

Gets the variant in which the parameter value is stored.

This function will return the pointer to the amxc_var_t structure in which the value of the parameter is stored.

Parameters
objectpointer to a data model object
namethe name of the parameter
Returns
The pointer to the variant containing the parameters value or NULL if the object doesn't contain a parameter with the given name.

Definition at line 301 of file amxd_object_parameter.c.

302  {
303  amxc_var_t* value = NULL;
304  amxd_param_t* param = amxd_object_get_param_def(object, name);
305  if(param != NULL) {
306  value = &param->value;
307  }
308 
309  return value;
310 }

◆ amxd_object_get_params()

amxd_status_t amxd_object_get_params ( amxd_object_t *const  object,
amxc_var_t *const  params,
amxd_dm_access_t  access 
)

Gets all parameter values of an object.

This function invokes an action_object_read and can read private and protected parameters, depending on the provided access value.

The default implementation of the action_object_read will fetch the real value of the paranmeters.

The action_object_read implementation can be overriden.

A provided variant will be initialized to a variant containing a hash table. For each parameter a key - value pair is added, The key is the parameter name and the value is the parameter value. The type is matching the parameter type.

Using the access value, it is possible to filter out some parameters. When providing amxd_dm_access_public, no private or protected parameters are returned, when using amxd_dm_access_protected no private parameters are returned.

Parameters
objectpointer to a data model object
paramsan initialized variant, the variant will be initialized to the hash table type, the value of the parameters will be copied in this hash table.
accesscan be set to amxd_dm_access_public, amxd_dm_access_protected, or amxd_dm_access_private
Returns
amxd_status_ok when the new value is set correctly.

Definition at line 314 of file amxd_action_object_read.c.

316  {
318  amxc_var_t args;
319 
320  amxc_var_init(&args);
321  when_null(object, exit);
322  when_null(params, exit);
323 
324  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
325  amxc_var_add_key(uint32_t, &args, "access", access);
326  retval = amxd_dm_invoke_action(object,
327  NULL,
329  &args,
330  params);
331 
332 exit:
333  amxc_var_clean(&args);
334  return retval;
335 }

◆ amxd_object_set_param()

amxd_status_t amxd_object_set_param ( amxd_object_t *const  object,
const char *  name,
amxc_var_t *const  value 
)

Sets a value for a parameter in a data model object.

When the type of the new value doesn't match the type of the parameter definition, the new value is converted to the type of the parameter.

This function invokes an action_object_write and can change read-only parameters or private and protected parameters.

The default implementation of the action_object_write will set the new value if possible. The following sets are not allowed and will fail:

  • set a value of an instance parameter on a multi-instance object
  • set a value of a template parameter on a instance object.

The new parameter value is also validated, the action_param_validate is invoked before applying the value to the parameter. The set fails if the provided value is not valid for the parameter.

The behavior of this function depends on the implementation of

Note
No object validation is done, it is the responsibility of the caller of this function to check if the object is valid after setting the value.

As an alternative to set a single parameter value of an object the macro amxd_object_set_value can be used.

Parameters
objectpointer to a data model object
namename of the parameter
valuethe new value
Returns
amxd_status_ok when the new value is set correctly.

Definition at line 221 of file amxd_object_parameter.c.

223  {
225  amxc_var_t* params = NULL;
226  amxc_var_t args;
227  amxc_var_t retval;
228 
229  amxc_var_init(&args);
230  amxc_var_init(&retval);
231  when_null(object, exit);
232  when_null(value, exit);
233  when_str_empty(name, exit);
234 
235  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
236  params = amxc_var_add_key(amxc_htable_t, &args, "parameters", NULL);
237  amxc_var_set_key(params, name, value, AMXC_VAR_FLAG_COPY);
238  amxc_var_add_key(uint32_t, &args, "access", amxd_dm_access_private);
239  amxc_var_add_key(bool, &args, "set_read_only", true);
240  status = amxd_dm_invoke_action(object,
241  NULL,
243  &args,
244  &retval);
245 
246 exit:
247  amxc_var_clean(&retval);
248  amxc_var_clean(&args);
249  return status;
250 }
@ action_object_write
Definition: amxd_types.h:118
static amxd_status_t status

◆ amxd_object_set_params()

amxd_status_t amxd_object_set_params ( amxd_object_t *const  object,
amxc_var_t *const  values 
)

Sets multiple parameter values in a data model object.

The behavior of this function is the same as amxd_object_set_param. The only differences is that the value arguments is a variant containing a hash table where the keys are considered parameter names.

When the object is a template object, it is possible to pass for each instance or some instances a separate hash table as value in the top level table, the key must be the name of the instance.

When a parameter or instance is not found the function fails.

Parameters
objectpointer to a data model object
valuesa variant containing a hash table where the keys are the parameter names and the values the new values for the parameters.
Returns
amxd_status_ok when the new value is set correctly.

Definition at line 270 of file amxd_action_object_write.c.

271  {
272 
274  amxc_var_t args;
275 
276  amxc_var_init(&args);
277  when_null(object, exit);
278  when_true(amxc_var_is_null(values) ||
279  amxc_var_type_of(values) != AMXC_VAR_ID_HTABLE,
280  exit);
281 
282  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
283  amxc_var_set_key(&args, "parameters", values, AMXC_VAR_FLAG_COPY);
284  amxc_var_add_key(uint32_t, &args, "access", amxd_dm_access_private);
285  amxc_var_add_key(bool, &args, "set_read_only", true);
286  status = amxd_dm_invoke_action(object,
287  NULL,
289  &args,
290  NULL);
291 
292 exit:
293  amxc_var_clean(&args);
294  return status;
295 }