libamxd  6.4.1
Data Model Manager
amxd_dm_functions.c
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 #include <string.h>
56 #include <stdlib.h>
57 
58 #include "amxd_priv.h"
59 
60 #include <amxd/amxd_dm.h>
61 #include <amxd/amxd_object.h>
62 #include <amxd/amxd_path.h>
63 #include <amxd/amxd_dm_functions.h>
64 #include <amxd/amxd_transaction.h>
65 
66 #include "amxd_priv.h"
67 #include "amxd_assert.h"
68 #include "amxd_object_priv.h"
69 #include "amxd_dm_priv.h"
70 
71 void amxd_def_funcs_remove_args(amxc_var_t* args) {
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 }
88 
90  UNUSED amxd_function_t* func,
91  amxc_var_t* args,
92  amxc_var_t* ret) {
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 }
111 
113  UNUSED amxd_function_t* func,
114  amxc_var_t* args,
115  amxc_var_t* ret) {
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 }
147 
149  UNUSED amxd_function_t* func,
150  amxc_var_t* args,
151  amxc_var_t* ret) {
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 }
179 
Ambiorix Data Model API header file.
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
amxd_status_t amxd_object_func_list(amxd_object_t *object, UNUSED amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
void amxd_def_funcs_remove_args(amxc_var_t *args)
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)
Ambiorix Data Model API header file.
Ambiorix path API header file.
Ambiorix Data Model API header file.
@ action_object_describe
Definition: amxd_types.h:121
@ action_object_list
Definition: amxd_types.h:120
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_dm_access_protected
Definition: amxd_types.h:139
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_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.
RPC method structure.
Definition: amxd_types.h:341