RDK Documentation (Open Sourced RDK Components)
TR69BusAgent.cpp
Go to the documentation of this file.
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 2016 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 /**
21 * @file
22 *
23 * @brief TR69 Bus Agent Public API.
24 *
25 */
26 
27 
28 
29 /**
30 * @defgroup tr69hostif
31 * @{
32 * @defgroup tr69BusAgent
33 * @{
34 **/
35 
36 
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #endif
41 #include <cstdio>
42 #include <unistd.h>
43 #include <cstring>
44 
45 #include "libIBus.h"
46 #include "libIARMCore.h"
47 #include "TR69BusAgent.h"
48 #include "rdk_debug.h"
49 #define LOG_TR69HOSTIF "LOG.RDK.TR69HOSTIF"
50 
51 #define MAX_RETRY_LOOP 15
52 
53  fpIncomingTR69Request tr69AgentCallback;
54 
55  faultCode_t TR69Bus_ProcessSharedMalloc(size_t size, void **ptr)
56  {
57  IARM_Result_t retCode = IARM_Malloc(IARM_MEMTYPE_PROCESSLOCAL, size, ptr);
58 
59  if (IARM_RESULT_SUCCESS != retCode)
60  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s: Failed to malloc from shared mem, IARM err code = %d\n", __FUNCTION__, retCode);
61 
62  switch (retCode)
63  {
64  case IARM_RESULT_SUCCESS:
65  return fcNoFault;
66  case IARM_RESULT_OOM:
67  return fcRequestDenied;
68  case IARM_RESULT_INVALID_PARAM:
69  case IARM_RESULT_IPCCORE_FAIL:
70  default:
71  return fcInternalError;
72  }
73  }
74 
75  IARM_Result_t _TR69AgentCallback_FuncWrapper(void *arg)
76  {
77  HOSTIF_MsgData_t *requestInfo = (HOSTIF_MsgData_t *) arg;
78 // RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s:%d] Enter \n", __FILE__, __FUNCTION__, __LINE__);
79  if (NULL == requestInfo)
80  {
81  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s: Null RequestInfo Arguments Caught !!!\n", __FUNCTION__);
82  return IARM_RESULT_IPCCORE_FAIL;
83  }
84 
85  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s:%d] paramName:%s \n", __FILE__, __FUNCTION__, __LINE__, requestInfo->paramName);
86 
87  if (false == tr69AgentCallback(requestInfo))
88  {
89  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s: tr69AgentCallback returned error !!!\n", __FUNCTION__);
90  return IARM_RESULT_IPCCORE_FAIL;
91  }
92 
93  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s: tr69AgentCallback returned success !!!\n", __FUNCTION__);
94 // RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s:%d] Exit \n", __FILE__, __FUNCTION__, __LINE__);
95  return IARM_RESULT_SUCCESS;
96  }
97 
98  bool tr69Register( const char *pOwnerName, fpIncomingTR69Request incomingTr69RequestCallback)
99  {
100  IARM_Result_t ret = IARM_RESULT_SUCCESS;
101 
102 
103  if (!pOwnerName)
104  {
105  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s: Owner's name cannot be null \r\n", __FUNCTION__);
106  return false;
107  }
108 
109  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"%s: Registering %s callback function (%s) \r\n", __FUNCTION__, pOwnerName, IARM_BUS_TR69_COMMON_API_AgentParameterHandler);
110 
111  tr69AgentCallback = incomingTr69RequestCallback;
112  if (NULL == tr69AgentCallback)
113  {
114  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error registering callback for %s, incomingTr69RequestCallback is null\n", pOwnerName);
115  return false;
116  }
117 
118  for(int loop = 0; loop < MAX_RETRY_LOOP; loop++)
119  {
120  ret = IARM_Bus_RegisterCall(IARM_BUS_TR69_COMMON_API_AgentParameterHandler, _TR69AgentCallback_FuncWrapper);
121  if(IARM_RESULT_SUCCESS == ret)
122  {
123 // RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s:%d] Success in IARM_Bus_RegisterCall with RPC: %s \r\n", __FILE__, __FUNCTION__, __LINE__, IARM_BUS_TR69_COMMON_API_AgentParameterHandler);
124 // RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s:%d] Success to register %s with %s \r\n", __FILE__, __FUNCTION__, __LINE__, pOwnerName, IARM_BUS_TR69_BUS_MGR_NAME);
125  break;
126  }
127  else{
128  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s:%d] Failed in IARM_Bus_RegisterCall with RPC: %s, so retrying [ %d ] times. \r\n", __FILE__, __FUNCTION__, __LINE__, IARM_BUS_TR69_COMMON_API_AgentParameterHandler, loop);
129  }
130  sleep (2);
131  }
132  return true;
133  }
134 
135  bool tr69UnRegister(const char *pOwnerName)
136  {
137  IARM_Result_t ret = IARM_RESULT_SUCCESS;
138  if (!pOwnerName)
139  {
140  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s: Owner's name cannot be null \r\n", __FUNCTION__);
141  return false;
142  }
143  return true;
144  }
145 
147  {
148  char *paramValue = NULL;
149 
150  if (fcNoFault != requestInfo->faultCode)
151  return false;
152 
153  if (HOSTIF_GET == requestInfo->reqType)
154  {
155  if ('\0' == requestInfo->paramValue[0])
156  {
157  requestInfo->faultCode = fcInvalidParameterValue;
158  return false;
159  }
160  }
161  //RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s:%d] Exit \n", __FILE__, __FUNCTION__, __LINE__);
162  return true;
163  }
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 
170 
171 /** @} */
172 /** @} */
_HostIf_MsgData_t::reqType
HostIf_ReqType_t reqType
Definition: hostIf_tr69ReqHandler.h:178
tr69RequestComplete
bool tr69RequestComplete(HOSTIF_MsgData_t *)
TR69 Request Complete function.
Definition: TR69BusAgent.cpp:146
rdk_debug.h
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
fpIncomingTR69Request
bool(* fpIncomingTR69Request)(HOSTIF_MsgData_t *)
TR69 Incoming Request function pointer.
Definition: TR69BusAgent.h:375
IARM_Bus_RegisterCall
IARM_Result_t IARM_Bus_RegisterCall(const char *methodName, IARM_BusCall_t handler)
This API is used to register an RPC method that can be invoked by other applications.
_TR69AgentCallback_FuncWrapper
IARM_Result_t _TR69AgentCallback_FuncWrapper(void *)
Function Wrapper around fpIncomingTR69Request.
Definition: TR69BusAgent.cpp:75
TR69BusAgent.h
TR69 Bus Agent Public API.
faultCode_t
enum _faultCodes faultCode_t
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
tr69Register
bool tr69Register(const char *, fpIncomingTR69Request)
Starts the TR69 Register Callback.
Definition: TR69BusAgent.cpp:98
_HostIf_MsgData_t::faultCode
faultCode_t faultCode
Definition: hostIf_tr69ReqHandler.h:179
libIBus.h
RDK IARM-Bus API Declarations.
_HostIf_MsgData_t::paramName
char paramName[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:171
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
tr69UnRegister
bool tr69UnRegister(const char *)
TR69 UnRegister function.
Definition: TR69BusAgent.cpp:135