RDK Documentation (Open Sourced RDK Components)
dcatr181.c
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2019 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 #include <stdio.h>
21 #include <string.h>
22 /* ccsp message bus header includes */
23 #include <pthread.h>
24 #include "ccsp_base_api.h"
25 #include "ccsp_message_bus.h"
26 #include "ccsp_memory.h"
27 
28 #include "dcatr181.h"
29 #include "dcautils.h"
30 #include "safec_lib.h"
31 
32 
33 /* Enable debug prints */
34 //#define TR181_DEBUG
35 #ifdef TR181_DEBUG
36 #define print_message(...) LOG(__VA_ARGS__)
37 #else
38 #define print_message(...)
39 #endif
40 
41 
42 /**
43  * @addtogroup DCA_TYPES
44  * @{
45  */
46 
47 #define CCSP_BUS_CLIENT "ccsp.busclient"
48 #define CCSP_BUS_CFG CCSP_MSG_BUS_CFG /* OR /tmp/ccsp_msg.cfg */
49 #define DST_COMP_CR "com.cisco.spvtg.ccsp.CR"
50 #define DST_COMP_SUBSYS "eRT."
51 #define DST_COMP_ID DST_COMP_SUBSYS DST_COMP_CR /* eRT.com.cisco.spvtg.ccsp.CR */
52 
53 /* @} */ // End of group DCA_TYPES
54 
55 void *ccsp_bus_handle = NULL;
56 
57 /**
58  * @addtogroup DCA_APIS
59  * @{
60  */
61 
62 /**
63  * @brief This API initalizes the ccsp message bus.
64  *
65  * @return Returns status of operation.
66  * @retval Returns zero on success, appropiate errorcode otherwise.
67  */
69 {
70  int ret = 0;
71 
72  if ( NULL == ccsp_bus_handle )
73  {
74  ret = CCSP_Message_Bus_Init(CCSP_BUS_CLIENT, CCSP_BUS_CFG, &ccsp_bus_handle, (CCSP_MESSAGE_BUS_MALLOC)Ansc_AllocateMemory_Callback, Ansc_FreeMemory_Callback);
75  if ( 0 != ret )
76  {
77  print_message("[%s]:CCSP_Message_Bus_Init() failed ret_val = %d\n", __FUNCTION__, ret);
78  ccsp_bus_handle = NULL;
79  return 1;
80  }
81  }
82 
83  return ret;
84 }
85 
86 /**
87  * @brief This API is to uninitialize message bus.
88  */
90 {
91  CCSP_Message_Bus_Exit(ccsp_bus_handle);
92  ccsp_bus_handle = NULL;
93 }
94 
95 /**
96  * @brief This API is to retrieve the value of TR181 telemetry.
97  *
98  * @return Returns status of operation.
99  * @retval Returns zero on success, appropiate errorcode otherwise.
100  */
101 int get_tr181param_value( const char* path_namespace, char* parm_value, int len)
102 {
103  UNREFERENCED_PARAMETER(len);
104  int ret = 0;
105  int comp_size = 0;
106  int val_size = 0;
107  char* dst_pathname = NULL;
108  char* dst_compid = NULL;
109  char* parameter_name[1] = {NULL};
110  parameterValStruct_t** param_val = NULL;
111  componentStruct_t** components = NULL;
112  errno_t rc = -1;
113 
114  if( NULL == ccsp_bus_handle || NULL == path_namespace || NULL == parm_value)
115  {
116  print_message("[%s]:Invalid input arguments\n", __FUNCTION__);
117  return 1;
118  }
119 
120  /* Get dest component id and path */
121  ret = CcspBaseIf_discComponentSupportingNamespace(ccsp_bus_handle, DST_COMP_ID, path_namespace, DST_COMP_SUBSYS, &components, &comp_size);
122  if ( CCSP_SUCCESS != ret || 1 > comp_size )
123  {
124  print_message("[%s]:Unable to find the destination component namespace ret_val = %d comp_size = %d\n", __FUNCTION__, ret, comp_size);
125  return 1;
126  }
127 
128  dst_compid = components[0]->componentName;
129  dst_pathname = components[0]->dbusPath;
130  parameter_name[0] = (char*)path_namespace;
131 
132  /* Get values of tr181 object */
133  ret = CcspBaseIf_getParameterValues(ccsp_bus_handle, dst_compid, dst_pathname, parameter_name, 1, &val_size, &param_val);
134  if( CCSP_SUCCESS != ret || 1 > val_size )
135  {
136  print_message("[%s]:Unable get param values ret_val = %d size = %d\n", __FUNCTION__, ret, val_size);
137  free_componentStruct_t(ccsp_bus_handle, comp_size, components);
138  return 1;
139  }
140 
141  rc = sprintf_s(parm_value,len,"%s", param_val[0]->parameterValue);
142  if(rc < EOK)
143  {
144  ERR_CHK(rc);
145  free_componentStruct_t(ccsp_bus_handle, comp_size, components);
146  free_parameterValStruct_t(ccsp_bus_handle, val_size, param_val);
147  return 1;
148  }
149  free_componentStruct_t(ccsp_bus_handle, comp_size, components);
150  free_parameterValStruct_t(ccsp_bus_handle, val_size, param_val);
151 
152  return 0;
153 }
154 
155 /** @} */ //END OF GROUP DCA_APIS
get_tr181param_value
int get_tr181param_value(const char *path_namespace, char *parm_value, int len)
This API is to retrieve the value of TR181 telemetry.
Definition: dcatr181.c:101
ccsp_handler_exit
void ccsp_handler_exit()
This API is to uninitialize message bus.
Definition: dcatr181.c:89
ccsp_handler_init
int ccsp_handler_init()
This API initalizes the ccsp message bus.
Definition: dcatr181.c:68