libamxd  6.4.1
Data Model Manager
amxd_dm_get_sup_function.c File Reference
#include <string.h>
#include <stdlib.h>
#include "amxd_priv.h"
#include <amxd/amxd_dm.h>
#include <amxd/amxd_object.h>
#include <amxd/amxd_path.h>
#include <amxd/amxd_dm_functions.h>
#include <amxd/amxd_transaction.h>
#include "amxd_assert.h"
#include "amxd_object_priv.h"
#include "amxd_dm_priv.h"

Go to the source code of this file.

Functions

static void amxd_describe_object_usp (amxc_var_t *object_data, amxc_var_t *retval)
 
static void amxd_describe_param_usp (amxc_var_t *param_data, amxc_var_t *retval)
 
static void amxd_describe_func_usp (amxc_var_t *func_data, amxc_var_t *retval)
 
static void amxd_get_supported_add_data (amxd_object_t *const object, amxc_var_t *data, get_supported_args_t *sup)
 
static bool amxd_get_supported_filter (amxd_object_t *const object, UNUSED int32_t depth, UNUSED void *priv)
 
static void amxd_get_supported_impl (amxd_object_t *const object, int32_t depth, void *priv)
 
static amxd_status_t amxd_get_supported (amxd_object_t *object, get_supported_args_t *sup)
 
amxd_status_t amxd_object_func_get_supported (amxd_object_t *object, UNUSED amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
 

Function Documentation

◆ amxd_describe_func_usp()

static void amxd_describe_func_usp ( amxc_var_t *  func_data,
amxc_var_t *  retval 
)
static

Definition at line 104 of file amxd_dm_get_sup_function.c.

105  {
106  amxc_string_t* name = amxc_var_take(amxc_string_t, GET_ARG(func_data, "name"));
107  amxc_var_t* args = GET_ARG(func_data, "arguments");
108  amxc_var_t* out_args = NULL;
109  amxc_var_t* in_args = NULL;
110 
111  amxc_string_append(name, "()", 2);
112  amxc_var_add_key(uint32_t, retval, "command_type",
113  GETP_BOOL(func_data, "attributes.asynchronous")? 2:1);
114  amxc_var_add_key(cstring_t, retval, "command_name", amxc_string_get(name, 0));
115  out_args = amxc_var_add_key(amxc_llist_t, retval, "output_arg_names", NULL);
116  in_args = amxc_var_add_key(amxc_llist_t, retval, "input_arg_names", NULL);
117  amxc_var_for_each(arg, args) {
118  amxc_var_t* arg_attrs = GET_ARG(arg, "attributes");
119  if(GET_BOOL(arg_attrs, "out")) {
120  amxc_var_add(cstring_t, out_args, GET_CHAR(arg, "name"));
121  }
122  if(GET_BOOL(arg_attrs, "in")) {
123  amxc_var_add(cstring_t, in_args, GET_CHAR(arg, "name"));
124  }
125  }
126  amxc_string_delete(&name);
127 }

◆ amxd_describe_object_usp()

static void amxd_describe_object_usp ( amxc_var_t *  object_data,
amxc_var_t *  retval 
)
static

Definition at line 71 of file amxd_dm_get_sup_function.c.

72  {
73  uint32_t access = 1;
74  uint32_t obj_type = GET_UINT32(object_data, "type_id");
75  amxc_var_t* attrs = GET_ARG(object_data, "attributes");
76 
77  if(GET_BOOL(attrs, "read-only")) {
78  access = 0;
79  }
80  amxc_var_add_key(bool, retval, "is_multi_instance", obj_type == amxd_object_template);
81  if(obj_type == amxd_object_template) {
82  amxc_var_add_key(uint32_t, retval, "access", access);
83  }
84 }
@ amxd_object_template
Definition: amxd_types.h:183

◆ amxd_describe_param_usp()

static void amxd_describe_param_usp ( amxc_var_t *  param_data,
amxc_var_t *  retval 
)
static

Definition at line 86 of file amxd_dm_get_sup_function.c.

87  {
88  amxc_var_t* attrs = GET_ARG(param_data, "attributes");
89  amxc_var_t* name = GET_ARG(param_data, "name");
90  uint32_t param_type = GET_UINT32(param_data, "type_id");
91 
92  amxc_var_set_key(retval, "param_name", name, AMXC_VAR_FLAG_DEFAULT);
93  if(GET_BOOL(attrs, "read-only") || (GET_BOOL(attrs, "key") && !GET_BOOL(attrs, "mutable"))) {
94  amxc_var_add_key(uint32_t, retval, "access", 0);
95  } else {
96  amxc_var_add_key(uint32_t, retval, "access", 1);
97  }
98  amxc_var_add_key(uint32_t, retval, "type", param_type);
99  amxc_var_add_key(uint32_t, retval, "value_change", GET_BOOL(attrs, "volatile")? 2:1);
100 
101  amxc_var_delete(&attrs);
102 }

◆ amxd_get_supported()

static amxd_status_t amxd_get_supported ( amxd_object_t object,
get_supported_args_t sup 
)
static

Definition at line 214 of file amxd_dm_get_sup_function.c.

215  {
217 
218  amxc_var_set_type(sup->ret, AMXC_VAR_ID_HTABLE);
223  sup->first_lvl ? 1 : INT32_MAX,
224  sup);
225 
227 
228  return status;
229 }
static bool amxd_get_supported_filter(amxd_object_t *const object, UNUSED int32_t depth, UNUSED void *priv)
static void amxd_get_supported_impl(amxd_object_t *const object, int32_t depth, void *priv)
enum _amxd_status amxd_status_t
@ amxd_status_invalid_path
Definition: amxd_types.h:99
@ amxd_status_ok
Definition: amxd_types.h:78
@ amxd_direction_down
Definition: amxd_types.h:216
void amxd_object_hierarchy_walk(amxd_object_t *const object, const amxd_direction_t direction, amxd_object_filter_fn_t filter, amxd_object_cb_fn_t cb, int32_t depth, void *priv)
Iterates over all objects in the data model tree.
static amxd_status_t status

◆ amxd_get_supported_add_data()

static void amxd_get_supported_add_data ( amxd_object_t *const  object,
amxc_var_t *  data,
get_supported_args_t sup 
)
static

Definition at line 129 of file amxd_dm_get_sup_function.c.

131  {
132  uint32_t flags = 0;
133  amxc_var_t object_data;
134 
135  amxc_var_init(&object_data);
136  flags = AMXD_TEMPLATE_INFO;
137  if(sup->params) {
138  flags |= AMXD_OBJECT_PARAM;
139  }
140  if(sup->functions) {
142  }
143  if(sup->events) {
144  flags |= AMXD_OBJECT_EVENT;
145  }
146  amxd_object_describe(object, &object_data, flags, sup->access);
147 
148  amxd_describe_object_usp(&object_data, data);
149  if(sup->params) {
150  const amxc_var_t* params = GET_ARG(&object_data, "parameters");
151  amxc_var_t* usp_params
152  = amxc_var_add_key(amxc_llist_t, data, "supported_params", NULL);
153  amxc_var_for_each(param, params) {
154  amxc_var_t* usp_param = amxc_var_add(amxc_htable_t, usp_params, NULL);
155  amxd_describe_param_usp(param, usp_param);
156  }
157  }
158 
159  if(sup->functions) {
160  const amxc_var_t* funcs = GET_ARG(&object_data, "functions");
161  amxc_var_t* usp_funcs
162  = amxc_var_add_key(amxc_llist_t, data, "supported_commands", NULL);
163  amxc_var_for_each(func, funcs) {
164  amxc_var_t* usp_func = amxc_var_add(amxc_htable_t, usp_funcs, NULL);
165  amxd_describe_func_usp(func, usp_func);
166  }
167  }
168 
169  if(sup->events) {
170  const amxc_var_t* events = GET_ARG(&object_data, "events");
171  amxc_var_t* usp_events
172  = amxc_var_add_key(amxc_llist_t, data, "supported_events", NULL);
173  amxc_var_copy(usp_events, events);
174  }
175 
176  amxc_var_clean(&object_data);
177 }
static void amxd_describe_param_usp(amxc_var_t *param_data, amxc_var_t *retval)
static void amxd_describe_func_usp(amxc_var_t *func_data, amxc_var_t *retval)
static void amxd_describe_object_usp(amxc_var_t *object_data, amxc_var_t *retval)
#define AMXD_OBJECT_EVENT
Definition: amxd_object.h:318
amxd_status_t amxd_object_describe(amxd_object_t *const object, amxc_var_t *const value, uint32_t flags, amxd_dm_access_t access)
#define AMXD_TEMPLATE_INFO
List and describe flag.
Definition: amxd_object.h:314
#define AMXD_OBJECT_NO_BASE
List and describe flag.
Definition: amxd_object.h:301
#define AMXD_OBJECT_FUNC
List and describe flag.
Definition: amxd_object.h:260
#define AMXD_OBJECT_PARAM
List and describe flag.
Definition: amxd_object.h:244
amxd_dm_access_t access

◆ amxd_get_supported_filter()

static bool amxd_get_supported_filter ( amxd_object_t *const  object,
UNUSED int32_t  depth,
UNUSED void *  priv 
)
static

Definition at line 179 of file amxd_dm_get_sup_function.c.

181  {
183 
185  return false;
186  }
188  return false;
189  }
191  (sup->access == amxd_dm_access_public)) {
192  return false;
193  }
194  return true;
195 }
@ amxd_oattr_protected
Definition: amxd_types.h:210
@ amxd_oattr_private
Definition: amxd_types.h:202
@ amxd_dm_access_public
Definition: amxd_types.h:136
@ 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

◆ amxd_get_supported_impl()

static void amxd_get_supported_impl ( amxd_object_t *const  object,
int32_t  depth,
void *  priv 
)
static

Definition at line 197 of file amxd_dm_get_sup_function.c.

199  {
201  char* sup_path = amxd_object_get_path(object,
204  amxc_var_t* data = amxc_var_add_key(amxc_htable_t, sup->ret, sup_path, NULL);
205  if(sup->first_lvl && (depth == 0)) {
206  sup->functions = false;
207  sup->params = false;
208  sup->events = false;
209  }
210  amxd_get_supported_add_data(object, data, sup);
211  free(sup_path);
212 }
static void amxd_get_supported_add_data(amxd_object_t *const object, amxc_var_t *data, get_supported_args_t *sup)
#define AMXD_OBJECT_SUPPORTED
Path format flag - adds {i} as placeholder for an instance object.
Definition: amxd_object.h:226
#define AMXD_OBJECT_TERMINATE
Path format flag - when set the object path is terminated with a dot.
Definition: amxd_object.h:214
amxd_object_t amxd_status_t amxd_status_t char * amxd_object_get_path(const amxd_object_t *object, const uint32_t flags)
Get the full path of the object.

◆ amxd_object_func_get_supported()

amxd_status_t amxd_object_func_get_supported ( amxd_object_t object,
UNUSED amxd_function_t func,
amxc_var_t *  args,
amxc_var_t *  ret 
)

Definition at line 231 of file amxd_dm_get_sup_function.c.

234  {
236  amxc_var_t* var_rel_path = GET_ARG(args, "rel_path");
237  const char* rel_path = GET_CHAR(var_rel_path, NULL);
238 
240  sup.functions = GET_BOOL(args, "functions");
241  sup.params = GET_BOOL(args, "parameters");
242  sup.events = GET_BOOL(args, "events");
243  sup.first_lvl = GET_BOOL(args, "first_level_only");
244  sup.access = (amxd_dm_access_t) GET_UINT32(args, "access");
245  sup.ret = ret;
246 
247  amxc_var_take_it(var_rel_path);
248  if((rel_path != NULL) && (*rel_path != 0)) {
249  amxd_path_t path;
250  char* obj_path = NULL;
251 
252  amxd_path_init(&path, rel_path);
253  obj_path = amxd_path_get_supported_path(&path);
254  if(obj_path != NULL) {
255  object = amxd_object_findf(object, "%s", obj_path);
256  }
257  free(obj_path);
258  amxd_path_clean(&path);
259  when_null_status(object, exit, retval = amxd_status_object_not_found);
260  } else {
261  char* obj_path = NULL;
262 
264  object = amxd_dm_findf(amxd_object_get_dm(object), "%s", obj_path);
265  free(obj_path);
266  when_null_status(object, exit, retval = amxd_status_object_not_found);
267  }
268 
269  retval = amxd_get_supported(object, &sup);
270 
271 exit:
272  amxc_var_delete(&var_rel_path);
273  return retval;
274 }
amxd_object_t * amxd_dm_findf(amxd_dm_t *const dm, const char *abs_path,...) __attribute__((format(printf
static amxd_status_t amxd_get_supported(amxd_object_t *object, get_supported_args_t *sup)
@ amxd_status_object_not_found
Definition: amxd_types.h:80
@ amxd_status_unknown_error
Definition: amxd_types.h:79
enum _amxd_dm_access amxd_dm_access_t
Access level.
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_dm_t * amxd_object_get_dm(const amxd_object_t *const object)
Get the data model.
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
char * amxd_path_get_supported_path(amxd_path_t *path)
Translates the path into a path that can be used to fetch the object definition.
Definition: amxd_path.c:611
void amxd_path_clean(amxd_path_t *path)
Cleans an amxd_path_t structure.
Definition: amxd_path.c:351