libamxd  6.4.1
Data Model Manager
amxd_action_param_describe.c File Reference
#include <amxc/amxc.h>
#include <amxp/amxp_signal.h>
#include <amxd/amxd_types.h>
#include <amxd/amxd_common.h>
#include <amxd/amxd_dm.h>
#include <amxd/amxd_object.h>
#include <amxd/amxd_action.h>
#include <amxd/amxd_parameter.h>
#include "amxd_priv.h"
#include "amxd_assert.h"

Go to the source code of this file.

Functions

static void amxd_param_describe_actions (amxd_object_t *object, amxd_param_t *param, amxc_var_t *actions, amxd_action_t action)
 
void amxd_param_build_description (amxc_var_t *description, const char *name, uint32_t type_id, uint32_t attrs, amxc_var_t *flags)
 
amxd_status_t amxd_action_param_describe (amxd_object_t *object, amxd_param_t *param, amxd_action_t reason, const amxc_var_t *const args, amxc_var_t *const retval, UNUSED void *priv)
 
amxd_status_t amxd_param_describe (amxd_param_t *const param, amxc_var_t *const value)
 

Function Documentation

◆ amxd_action_param_describe()

amxd_status_t amxd_action_param_describe ( amxd_object_t object,
amxd_param_t param,
amxd_action_t  reason,
const amxc_var_t *const  args,
amxc_var_t *const  retval,
UNUSED void *  priv 
)

Definition at line 141 of file amxd_action_param_describe.c.

146  {
148  amxc_var_t* value = NULL;
149  amxc_var_t* constraints = NULL;
150 
151  when_null(param, exit);
152  when_null(retval, exit);
153 
154  when_true_status(reason != action_param_describe,
155  exit,
157 
159  amxd_param_get_name(param),
160  amxd_param_get_type(param),
161  amxd_param_get_attrs(param),
162  param->flags);
163 
164  constraints = amxc_var_add_key(amxc_htable_t, retval, "validate", NULL);
165  amxd_param_describe_actions(object, param, constraints, action_param_validate);
166  if(amxc_htable_is_empty(amxc_var_constcast(amxc_htable_t, constraints))) {
167  amxc_var_delete((&constraints));
168  }
169 
170  if((GET_ARG(args, "no-param-value") == NULL) || !GET_BOOL(args, "no-param-value")) {
171  value = amxc_var_get_key(retval, "value", AMXC_VAR_FLAG_DEFAULT);
172  amxd_dm_invoke_action(object, param, action_param_read, args, value);
173  }
174 
176 
177 exit:
178  return status;
179 }
void amxd_param_build_description(amxc_var_t *description, const char *name, uint32_t type_id, uint32_t attrs, amxc_var_t *flags)
static void amxd_param_describe_actions(amxd_object_t *object, amxd_param_t *param, amxc_var_t *actions, amxd_action_t action)
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
const char * amxd_param_get_name(const amxd_param_t *const param)
static uint32_t amxd_param_get_type(const amxd_param_t *const param)
uint32_t amxd_param_get_attrs(const amxd_param_t *const param)
@ action_param_read
Definition: amxd_types.h:112
@ action_param_validate
Definition: amxd_types.h:114
@ action_param_describe
Definition: amxd_types.h:115
enum _amxd_status amxd_status_t
@ amxd_status_function_not_implemented
Definition: amxd_types.h:83
@ amxd_status_ok
Definition: amxd_types.h:78
@ amxd_status_unknown_error
Definition: amxd_types.h:79
amxc_var_t * flags
Definition: amxd_types.h:393
static amxd_status_t status

◆ amxd_param_build_description()

void amxd_param_build_description ( amxc_var_t *  description,
const char *  name,
uint32_t  type_id,
uint32_t  attrs,
amxc_var_t *  flags 
)

Definition at line 109 of file amxd_action_param_describe.c.

113  {
114  static const char* attr_name[] = {
115  "template", "instance", "private", "read-only", "persistent",
116  "volatile", "counter", "key", "unique", "protected", "mutable"
117  };
118  amxc_var_t* subvar = NULL;
119  amxc_var_set_type(description, AMXC_VAR_ID_HTABLE);
120 
121  amxc_var_add_key(cstring_t, description, "name", name);
122  amxc_var_add_key(uint32_t, description, "type_id", type_id);
123  amxc_var_add_key(cstring_t, description, "type_name", amxc_var_get_type_name_from_id(type_id));
124  amxc_var_add_new_key(description, "value");
125  subvar = amxc_var_add_key(amxc_htable_t, description, "attributes", NULL);
126  for(int i = 0; i <= amxd_pattr_max; i++) {
127  amxc_var_add_key(bool, subvar, attr_name[i], IS_BIT_SET(attrs, i));
128  }
129  subvar = amxc_var_add_key(amxc_llist_t, description, "flags", NULL);
130  if(flags != NULL) {
131  const amxc_htable_t* ht_flags = amxc_var_constcast(amxc_htable_t, flags);
132  amxc_htable_iterate(it, ht_flags) {
133  amxc_var_t* flag = amxc_var_from_htable_it(it);
134  if(amxc_var_dyncast(bool, flag)) {
135  amxc_var_add(cstring_t, subvar, amxc_htable_it_get_key(it));
136  }
137  }
138  }
139 }
#define IS_BIT_SET(b, f)
Definition: amxd_common.h:66
@ amxd_pattr_max
Definition: amxd_types.h:366

◆ amxd_param_describe()

amxd_status_t amxd_param_describe ( amxd_param_t *const  param,
amxc_var_t *const  value 
)

Definition at line 181 of file amxd_action_param_describe.c.

182  {
184  amxd_object_t* object = NULL;
185 
186  when_null(param, exit);
187  when_null(value, exit);
188 
189  object = amxd_param_get_owner(param);
190  retval = amxd_dm_invoke_action(object,
191  param,
193  NULL,
194  value);
195 
196 exit:
197  return retval;
198 }
amxd_object_t * amxd_param_get_owner(const amxd_param_t *const param)

◆ amxd_param_describe_actions()

static void amxd_param_describe_actions ( amxd_object_t object,
amxd_param_t param,
amxc_var_t *  actions,
amxd_action_t  action 
)
static

Definition at line 68 of file amxd_action_param_describe.c.

71  {
72  amxc_llist_t* cb_fns = &param->cb_fns;
73  amxd_object_t* super = NULL;
74  amxd_param_t* super_param = NULL;
75 
76  when_null(object, exit);
77  when_null(param, exit);
78 
79  amxc_llist_for_each(it, cb_fns) {
80  amxd_dm_cb_t* cb_fn = amxc_llist_it_get_data(it, amxd_dm_cb_t, it);
81  if(cb_fn->reason != action) {
82  continue;
83  }
84  cb_fn->fn(object, param, action_describe_action, NULL, actions, cb_fn->priv);
85  }
86 
87  when_false(amxc_htable_is_empty(amxc_var_constcast(amxc_htable_t, actions)), exit);
88 
90  super = amxd_object_get_parent(object);
91  } else {
92  super = (object->derived_from.llist == NULL) ?
93  NULL :
94  amxc_container_of(object->derived_from.llist,
96  derived_objects);
97  }
98  if(super != NULL) {
99  super_param = amxd_object_get_param_def(object, amxd_param_get_name(param));
100  if(super_param != NULL) {
101  amxd_param_describe_actions(super, super_param, actions, action);
102  }
103  }
104 
105 exit:
106  return;
107 }
@ action_describe_action
Definition: amxd_types.h:127
@ amxd_object_instance
Definition: amxd_types.h:186
amxd_object_t * amxd_object_get_parent(const amxd_object_t *const object)
Get the parent object.
amxd_param_t * amxd_object_get_param_def(const amxd_object_t *const object, const char *name)
Gets a parameter definition from an object.
static amxd_object_type_t amxd_object_get_type(const amxd_object_t *const object)
Returns the object type.
Definition: amxd_object.h:586
amxc_llist_it_t derived_from
Definition: amxd_types.h:249
amxc_llist_t cb_fns
Definition: amxd_types.h:391
static int cb_fn(amxd_object_t *start_object, amxd_object_t *matching_object, UNUSED void *priv)