TR181-XPON  1.4.0
TR-181 PON manager.
object_intf_priv.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
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 "object_intf_priv.h"
65 
66 /* System headers */
67 #include <stdint.h>
68 #include <stdlib.h> /* calloc(), free() */
69 
70 /* Other libraries' headers */
71 
79 #include <amxp/amxp.h>
80 #include <amxd/amxd_object_hierarchy.h> /* amxd_object_get_instance() */
81 
82 /* Own headers */
83 #include "dm_xpon_mngr.h" /* xpon_mngr_get_dm() */
84 #include "utils_time.h" /* time_get_system_uptime() */
85 #include "xpon_trace.h"
86 
87 
89  object_intf_priv_t* priv = calloc(1, sizeof(object_intf_priv_t));
90  when_null_trace(priv, exit, ERROR, "Failed to create object_intf_priv_t");
92 
93 exit:
94  return priv;
95 }
96 
106 void oipriv_attach_private_data(const amxc_var_t* const data) {
107 
108  const char* const path = GETP_CHAR(data, "path");
109  const uint32_t index = GET_UINT32(data, "index");
110  SAH_TRACEZ_DEBUG(ME, "path='%s' index=%d", path, index);
111 
112  amxd_dm_t* const dm = xpon_mngr_get_dm();
113  const amxd_object_t* const obj = amxd_dm_signal_get_object(dm, data);
114  amxd_object_t* const inst = amxd_object_get_instance(obj, NULL, index);
115  when_null_trace(inst, exit, ERROR, "Failed to get instance");
116  object_intf_priv_t* const priv = create_priv();
117  when_null_trace(priv, exit, ERROR, "Failed to create object_intf_priv_t");
118  inst->priv = priv;
119 
120 exit:
121  return;
122 }
123 
125  if(priv) {
126  free(priv);
127  }
128 }
129 
139 void oipriv_update_last_change(const amxc_var_t* const data) {
140 
141  const char* const path = GETP_CHAR(data, "path");
142  SAH_TRACEZ_DEBUG(ME, "path='%s'", path);
143 
144  amxd_dm_t* const dm = xpon_mngr_get_dm();
145  const amxd_object_t* const obj = amxd_dm_signal_get_object(dm, data);
146  when_null_trace(obj->priv, exit, ERROR, "object %s has no private data", path);
147 
148  object_intf_priv_t* const priv = (object_intf_priv_t* const) obj->priv;
150 
151 exit:
152  return;
153 }
154 
amxd_dm_t *PRIVATE xpon_mngr_get_dm(void)
void oipriv_delete_private_data(object_intf_priv_t *priv)
void oipriv_update_last_change(const amxc_var_t *const data)
static object_intf_priv_t * create_priv(void)
void oipriv_attach_private_data(const amxc_var_t *const data)
on event dm
uint32_t time_get_system_uptime(void)
Definition: utils_time.c:75
#define SAH_TRACEZ_DEBUG(zone, format,...)
Definition: xpon_trace.h:115
#define ME
Definition: xpon_trace.h:78