TR181-XPON  1.4.0
TR-181 PON manager.
pon_stat.c
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2022 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or
8 ** without modification, are permitted provided that the following
9 ** conditions are met:
10 **
11 ** 1. Redistributions of source code must retain the above copyright
12 ** notice, this list of conditions and the following disclaimer.
13 **
14 ** 2. Redistributions in binary form must reproduce the above
15 ** copyright notice, this list of conditions and the following
16 ** disclaimer in the documentation and/or other materials provided
17 ** with the distribution.
18 **
19 ** Subject to the terms and conditions of this license, each
20 ** copyright holder and contributor hereby grants to those receiving
21 ** rights under this license a perpetual, worldwide, non-exclusive,
22 ** no-charge, royalty-free, irrevocable (except for failure to
23 ** satisfy the conditions of this license) patent license to make,
24 ** have made, use, offer to sell, sell, import, and otherwise
25 ** transfer this software, where such license applies only to those
26 ** patent claims, already acquired or hereafter acquired, licensable
27 ** by such copyright holder or contributor that are necessarily
28 ** infringed by:
29 **
30 ** (a) their Contribution(s) (the licensed copyrights of copyright
31 ** holders and non-copyrightable additions of contributors, in
32 ** source or binary form) alone; or
33 **
34 ** (b) combination of their Contribution(s) with the work of
35 ** authorship to which such Contribution(s) was added by such
36 ** copyright holder or contributor, if, at the time the Contribution
37 ** is added, such addition causes such combination to be necessarily
38 ** infringed. The patent license shall not apply to any other
39 ** combinations which include the Contribution.
40 **
41 ** Except as expressly stated above, no rights or licenses from any
42 ** copyright holder or contributor is granted under this license,
43 ** whether expressly, by implication, estoppel or otherwise.
44 **
45 ** DISCLAIMER
46 **
47 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
48 ** CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
49 ** INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
50 ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
51 ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
52 ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
55 ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
56 ** AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
58 ** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 ** POSSIBILITY OF SUCH DAMAGE.
60 **
61 ****************************************************************************/
62 
63 /* Related header */
64 #include "pon_stat.h"
65 
66 /* System headers */
67 #include <amxc/amxc_macros.h> /* UNUSED */
68 
69 /* Other libraries' headers */
74 #include <amxp/amxp.h>
75 #include <amxc/amxc.h>
76 #include <amxd/amxd_types.h>
77 #include <amxo/amxo.h> /* amxo_connection_add() */
78 
79 /* Own headers */
80 #include "data_model.h" /* dm_add_instance() */
81 #include "dm_xpon_mngr.h" /* xpon_mngr_get_parser() */
82 #include "pon_ctrl.h" /* handle_file_descriptor() */
83 #include "xpon_trace.h"
84 
85 
95 int dm_instance_added(UNUSED const char* function_name,
96  amxc_var_t* args,
97  UNUSED amxc_var_t* ret) {
98 
99  SAH_TRACEZ_INFO(ME, "called");
100  return dm_add_instance(args);
101 }
102 
110 int dm_instance_removed(UNUSED const char* function_name,
111  amxc_var_t* args,
112  UNUSED amxc_var_t* ret) {
113 
114  SAH_TRACEZ_INFO(ME, "called");
115  return dm_remove_instance(args);
116 }
117 
125 int dm_object_changed(UNUSED const char* function_name,
126  amxc_var_t* args,
127  UNUSED amxc_var_t* ret) {
128 
129  SAH_TRACEZ_INFO(ME, "called");
130  return dm_change_object(args);
131 }
132 
166 int dm_add_or_change_instance(UNUSED const char* function_name,
167  amxc_var_t* args,
168  UNUSED amxc_var_t* ret) {
169  SAH_TRACEZ_INFO(ME, "called");
170  return dm_add_or_change_instance_impl(args);
171 }
172 
182 int omci_reset_mib(UNUSED const char* function_name,
183  amxc_var_t* args,
184  UNUSED amxc_var_t* ret) {
185 
186  SAH_TRACEZ_INFO(ME, "called");
187  return dm_omci_reset_mib(args);
188 }
189 
190 static void handle_fd(int fd, UNUSED void* priv) {
191  when_false_trace(fd > 0, exit, ERROR, "Invalid fd [%d]", fd);
192 
193  SAH_TRACEZ_DEBUG(ME, "fd=%d readable", fd);
195 
196 exit:
197  return;
198 }
199 
200 
201 static int watch_file_descriptor_common(amxc_var_t* args,
202  bool start) {
203  int rc = -1;
204  amxo_parser_t* const parser = xpon_mngr_get_parser();
205  when_null(parser, exit);
206  when_null(args, exit);
207 
208  const uint32_t type = amxc_var_type_of(args);
209  when_false_trace(type == AMXC_VAR_ID_FD, exit, ERROR,
210  "Type of 'args' = %d != FD", type);
211  const int fd = amxc_var_constcast(fd_t, args);
212  when_false_trace(fd > 0, exit, ERROR, "Invalid fd [%d]", fd);
213 
214  if(start) {
215  if(amxo_connection_add(parser, fd, handle_fd, NULL, AMXO_CUSTOM, NULL) != 0) {
216  SAH_TRACEZ_ERROR(ME, "Failed to start monitoring fd=%d", fd);
217  goto exit;
218  }
219  } else {
220  if(amxo_connection_remove(parser, fd) != 0) {
221  SAH_TRACEZ_ERROR(ME, "Failed to stop monitoring fd=%d", fd);
222  goto exit;
223  }
224  }
225 
226  rc = 0;
227 
228 exit:
229  return rc;
230 }
231 
245 int watch_file_descriptor_start(UNUSED const char* function_name,
246  amxc_var_t* args,
247  UNUSED amxc_var_t* ret) {
248  return watch_file_descriptor_common(args, /*start=*/ true);
249 }
250 
264 int watch_file_descriptor_stop(UNUSED const char* function_name,
265  amxc_var_t* args,
266  UNUSED amxc_var_t* ret) {
267  return watch_file_descriptor_common(args, /*start=*/ false);
268 }
269 
277 int dm_set_xpon_parameter(UNUSED const char* function_name,
278  amxc_var_t* args,
279  UNUSED amxc_var_t* ret) {
280 
281  SAH_TRACEZ_INFO(ME, "called");
282  return dm_set_xpon_parameter_impl(args);
283 }
284 
int dm_omci_reset_mib(const amxc_var_t *const args)
Definition: data_model.c:1049
int dm_change_object(const amxc_var_t *const args)
Definition: data_model.c:821
int dm_add_or_change_instance_impl(const amxc_var_t *const args)
Definition: data_model.c:922
int dm_remove_instance(const amxc_var_t *const args)
Definition: data_model.c:788
int dm_set_xpon_parameter_impl(const amxc_var_t *const args)
Definition: data_model.c:1106
int dm_add_instance(const amxc_var_t *const args)
Definition: data_model.c:762
amxo_parser_t *PRIVATE xpon_mngr_get_parser(void)
void pon_ctrl_handle_file_descriptor(int fd)
Definition: pon_ctrl.c:277
int dm_add_or_change_instance(UNUSED const char *function_name, amxc_var_t *args, UNUSED amxc_var_t *ret)
Definition: pon_stat.c:166
int dm_instance_added(UNUSED const char *function_name, amxc_var_t *args, UNUSED amxc_var_t *ret)
Definition: pon_stat.c:95
static void handle_fd(int fd, UNUSED void *priv)
Definition: pon_stat.c:190
int omci_reset_mib(UNUSED const char *function_name, amxc_var_t *args, UNUSED amxc_var_t *ret)
Definition: pon_stat.c:182
int dm_instance_removed(UNUSED const char *function_name, amxc_var_t *args, UNUSED amxc_var_t *ret)
Definition: pon_stat.c:110
int watch_file_descriptor_stop(UNUSED const char *function_name, amxc_var_t *args, UNUSED amxc_var_t *ret)
Definition: pon_stat.c:264
int watch_file_descriptor_start(UNUSED const char *function_name, amxc_var_t *args, UNUSED amxc_var_t *ret)
Definition: pon_stat.c:245
static int watch_file_descriptor_common(amxc_var_t *args, bool start)
Definition: pon_stat.c:201
int dm_object_changed(UNUSED const char *function_name, amxc_var_t *args, UNUSED amxc_var_t *ret)
Definition: pon_stat.c:125
int dm_set_xpon_parameter(UNUSED const char *function_name, amxc_var_t *args, UNUSED amxc_var_t *ret)
Definition: pon_stat.c:277
#define SAH_TRACEZ_DEBUG(zone, format,...)
Definition: xpon_trace.h:115
#define ME
Definition: xpon_trace.h:78