libamxd  6.4.1
Data Model Manager
amxd_dm_functions.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

void amxd_def_funcs_remove_args (amxc_var_t *args)
 
amxd_status_t amxd_object_func_list (amxd_object_t *object, UNUSED amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
 
amxd_status_t amxd_object_func_describe (amxd_object_t *object, UNUSED amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
 
amxd_status_t amxd_object_func_exec (amxd_object_t *object, UNUSED amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
 

Function Documentation

◆ amxd_def_funcs_remove_args()

void amxd_def_funcs_remove_args ( amxc_var_t *  args)

Definition at line 71 of file amxd_dm_functions.c.

71  {
72  amxc_var_t* access = GET_ARG(args, "access");
73  uint32_t iaccess = amxc_var_dyncast(uint32_t, access);
74  const char* invalid_args[] = {
75  "set_read_only",
76  NULL
77  };
78 
79  for(int i = 0; invalid_args[i] != NULL; i++) {
80  amxc_var_t* arg = GET_ARG(args, invalid_args[i]);
81  amxc_var_delete(&arg);
82  }
83 
84  if(iaccess > amxd_dm_access_protected) {
85  amxc_var_set(uint32_t, access, amxd_dm_access_protected);
86  }
87 }
@ amxd_dm_access_protected
Definition: amxd_types.h:139

◆ amxd_object_func_describe()

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

Definition at line 112 of file amxd_dm_functions.c.

115  {
116 
118  amxc_var_t* var_rel_path = GET_ARG(args, "rel_path");
119  const char* rel_path = GET_CHAR(var_rel_path, NULL);
120  amxc_var_t* exists = GET_ARG(args, "exists");
122 
123  amxc_var_take_it(var_rel_path);
124  if((rel_path != NULL) && (*rel_path != 0)) {
125  object = amxd_object_findf(object, "%s", rel_path);
126  }
127 
128  if((exists != NULL) && amxc_var_dyncast(bool, exists)) {
129  retval = amxd_status_ok;
130  amxc_var_set(bool, ret, object != NULL);
131  goto exit;
132  }
133 
134  when_null_status(object, exit, retval = amxd_status_object_not_found);
135 
136  retval = amxd_dm_invoke_action(object,
137  NULL,
139  args,
140  ret);
141 
142 exit:
143 
144  amxc_var_delete(&var_rel_path);
145  return retval;
146 }
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
void amxd_def_funcs_remove_args(amxc_var_t *args)
@ action_object_describe
Definition: amxd_types.h:121
enum _amxd_status amxd_status_t
@ amxd_status_object_not_found
Definition: amxd_types.h:80
@ amxd_status_ok
Definition: amxd_types.h:78
@ amxd_status_unknown_error
Definition: amxd_types.h:79
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_object_func_exec()

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

Definition at line 148 of file amxd_dm_functions.c.

151  {
153  amxc_var_t* var_rel_path = GET_ARG(args, "rel_path");
154  const char* rel_path = GET_CHAR(var_rel_path, NULL);
155  const char* method = GET_CHAR(args, "method");
156  amxc_var_t* method_args = GET_ARG(args, "args");
157 
159 
160  amxc_var_take_it(var_rel_path);
161  if((rel_path != NULL) && (*rel_path != 0)) {
162  object = amxd_object_findf(object, "%s", rel_path);
163  }
164 
165  if(object != NULL) {
166  retval = amxd_object_invoke_function(object, method, method_args, ret);
167  if(amxc_var_is_null(method_args) ||
168  amxc_htable_is_empty(amxc_var_constcast(amxc_htable_t, method_args))) {
169  amxc_var_delete(&method_args);
170  }
171  } else {
173  }
174 
175  amxc_var_delete(&var_rel_path);
176  return retval;
177 
178 }
amxd_status_t amxd_object_invoke_function(amxd_object_t *const object, const char *func_name, amxc_var_t *const args, amxc_var_t *const ret)
Calls an object RPC method.

◆ amxd_object_func_list()

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

Definition at line 89 of file amxd_dm_functions.c.

92  {
94  const char* rel_path = GET_CHAR(args, "rel_path");
96 
97  if((rel_path != NULL) && (*rel_path != 0)) {
98  object = amxd_object_findf(object, "%s", rel_path);
99  when_null_status(object, exit, retval = amxd_status_object_not_found);
100  }
101 
102  retval = amxd_dm_invoke_action(object,
103  NULL,
105  args,
106  ret);
107 
108 exit:
109  return retval;
110 }
@ action_object_list
Definition: amxd_types.h:120