libamxo  4.3.4
Object Definition Language (ODL) parsing
test_plugin.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 <stdlib.h>
56 #include <stdio.h>
57 
58 #include <amxc/amxc.h>
59 #include <amxp/amxp_signal.h>
60 #include <amxp/amxp_slot.h>
61 #include <amxd/amxd_dm.h>
62 #include <amxd/amxd_object.h>
63 #include <amxd/amxd_action.h>
64 #include <amxd/amxd_transaction.h>
65 
66 #include <amxo/amxo.h>
67 
68 #include <amxc/amxc_macros.h>
69 static amxo_parser_t* local_parser = NULL;
70 
71 int _test_entry_point(int reason,
72  amxd_dm_t* dm,
73  amxo_parser_t* parser);
74 
75 int _test_failing_entry_point(UNUSED int reason,
76  UNUSED amxd_dm_t* dm,
77  UNUSED amxo_parser_t* parser);
78 
79 amxd_status_t _test_func(amxd_object_t* object,
80  amxd_function_t* func,
81  amxc_var_t* args,
82  amxc_var_t* ret);
83 amxd_status_t _TestObject_TestFunc1(amxd_object_t* object,
84  amxd_function_t* func,
85  amxc_var_t* args,
86  amxc_var_t* ret);
87 amxd_status_t _TestObject_TestFunc2(amxd_object_t* object,
88  amxd_function_t* func,
89  amxc_var_t* args,
90  amxc_var_t* ret);
91 amxd_status_t _TestObject_TestFunc4(amxd_object_t* object,
92  amxd_function_t* func,
93  amxc_var_t* args,
94  amxc_var_t* ret);
95 
96 amxd_status_t __TestObject_TestFunc1(amxd_object_t* object,
97  amxd_function_t* func,
98  amxc_var_t* args,
99  amxc_var_t* ret);
100 amxd_status_t TestObject_TestFunc2(amxd_object_t* object,
101  amxd_function_t* func,
102  amxc_var_t* args,
103  amxc_var_t* ret);
104 amxd_status_t __TestFunc3(amxd_object_t* object,
105  amxd_function_t* func,
106  amxc_var_t* args,
107  amxc_var_t* ret);
108 amxd_status_t TestFunc4(amxd_object_t* object,
109  amxd_function_t* func,
110  amxc_var_t* args,
111  amxc_var_t* ret);
112 
113 amxd_status_t _test_dummy_action(amxd_object_t* const object,
114  amxd_param_t* const param,
115  amxd_action_t reason,
116  const amxc_var_t* const args,
117  amxc_var_t* const retval,
118  void* priv);
119 
120 amxd_status_t _test_func(amxd_object_t* object,
121  amxd_function_t* func,
122  amxc_var_t* args,
123  amxc_var_t* ret) {
124  char* path = amxd_object_get_path(object, AMXD_OBJECT_NAMED);
125  printf("Function call: \n");
126  printf("Object - %s\n", path);
127  printf("Function - %s\n", amxd_function_get_name(func));
128  amxc_var_copy(ret, args);
129  if(args != NULL) {
130  fflush(stdout);
131  amxc_var_dump(args, STDOUT_FILENO);
132  }
133  free(path);
134  return 0;
135 }
136 
137 amxd_status_t _TestObject_TestFunc1(amxd_object_t* object,
138  amxd_function_t* func,
139  amxc_var_t* args,
140  amxc_var_t* ret) {
141  return _test_func(object, func, args, ret);
142 }
143 
144 amxd_status_t _TestObject_TestFunc2(amxd_object_t* object,
145  amxd_function_t* func,
146  amxc_var_t* args,
147  amxc_var_t* ret) {
148  return _test_func(object, func, args, ret);
149 }
150 
151 amxd_status_t _TestObject_TestFunc4(amxd_object_t* object,
152  amxd_function_t* func,
153  amxc_var_t* args,
154  amxc_var_t* ret) {
155  return _test_func(object, func, args, ret);
156 }
157 
158 
159 // PCB Style symbols
161 amxd_status_t __TestObject_TestFunc1(amxd_object_t* object,
162  amxd_function_t* func,
163  amxc_var_t* args,
164  amxc_var_t* ret) {
165  return _test_func(object, func, args, ret);
166 }
167 
168 amxd_status_t TestObject_TestFunc2(amxd_object_t* object,
169  amxd_function_t* func,
170  amxc_var_t* args,
171  amxc_var_t* ret) {
172  return _test_func(object, func, args, ret);
173 }
174 
175 amxd_status_t __TestFunc3(amxd_object_t* object,
176  amxd_function_t* func,
177  amxc_var_t* args,
178  amxc_var_t* ret) {
179  return _test_func(object, func, args, ret);
180 }
181 
182 amxd_status_t TestFunc4(amxd_object_t* object,
183  amxd_function_t* func,
184  amxc_var_t* args,
185  amxc_var_t* ret) {
186  return _test_func(object, func, args, ret);
187 }
189 
190 int _test_entry_point(UNUSED int reason,
191  UNUSED amxd_dm_t* dm,
192  UNUSED amxo_parser_t* parser) {
193 
194  amxc_var_t* counter = amxo_parser_get_config(parser, "counter");
195  amxc_var_set(uint32_t, counter, amxc_var_constcast(uint32_t, counter) + 1);
196 
197  if(reason == 0) {
198  local_parser = parser;
199  } else {
200  local_parser = NULL;
201  }
202  return 0;
203 }
204 
206  UNUSED amxd_dm_t* dm,
207  UNUSED amxo_parser_t* parser) {
208 
209  amxc_var_t* counter = amxo_parser_get_config(parser, "counter");
210  amxc_var_set(uint32_t, counter, amxc_var_constcast(uint32_t, counter) + 1);
211 
212  return -1;
213 }
Ambiorix ODL parser header file.
amxc_var_t * amxo_parser_get_config(amxo_parser_t *parser, const char *path)
Gets a configuration option.
The ODL parser structure.
Definition: amxo_types.h:245
#define UNUSED
Definition: test_issue_48.c:84
amxd_status_t TestObject_TestFunc2(amxd_object_t *object, amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
Definition: test_plugin.c:168
amxd_status_t _test_dummy_action(amxd_object_t *const object, amxd_param_t *const param, amxd_action_t reason, const amxc_var_t *const args, amxc_var_t *const retval, void *priv)
amxd_status_t _TestObject_TestFunc2(amxd_object_t *object, amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
Definition: test_plugin.c:144
static amxo_parser_t * local_parser
Definition: test_plugin.c:69
amxd_status_t _test_func(amxd_object_t *object, amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
Definition: test_plugin.c:120
amxd_status_t __TestObject_TestFunc1(amxd_object_t *object, amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
Definition: test_plugin.c:161
int _test_entry_point(int reason, amxd_dm_t *dm, amxo_parser_t *parser)
amxd_status_t _TestObject_TestFunc1(amxd_object_t *object, amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
Definition: test_plugin.c:137
amxd_status_t TestFunc4(amxd_object_t *object, amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
Definition: test_plugin.c:182
amxd_status_t __TestFunc3(amxd_object_t *object, amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
Definition: test_plugin.c:175
int _test_failing_entry_point(UNUSED int reason, UNUSED amxd_dm_t *dm, UNUSED amxo_parser_t *parser)
Definition: test_plugin.c:205
amxd_status_t _TestObject_TestFunc4(amxd_object_t *object, amxd_function_t *func, amxc_var_t *args, amxc_var_t *ret)
Definition: test_plugin.c:151