RDK Documentation (Open Sourced RDK Components)
hostIf_updateHandler.cpp
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 
22 /**
23 * @defgroup tr69hostif
24 * @{
25 * @defgroup hostif
26 * @{
27 **/
28 
29 
30 #include "hostIf_updateHandler.h"
38 #include "hostIf_NotificationHandler.h"
39 #include <mutex>
40 
41 #ifdef USE_WIFI_PROFILE
42 #include "hostIf_WiFi_ReqHandler.h"
43 #endif
44 
45 #ifdef USE_DHCPv4_PROFILE
47 #endif /* WITH_DHCP_PROFILE*/
48 
49 #ifdef USE_STORAGESERVICE_PROFILE
51 #endif /* USE_STORAGESERVICE_PROFILE */
52 
53 #ifdef USE_INTFSTACK_PROFILE
55 #endif /* USE_INTFSTACK_PROFILE */
56 
57 #ifdef USE_XRESRC
58 #include "Device_XComcast_Xcalibur_Client_XRE_ConnectionTable.h"
59 #endif
60 
61 #ifdef USE_XRDK_BT_PROFILE
62 #include "XrdkBlueTooth.h"
63 #endif
64 
65 
66 bool updateHandler::stopped = false;
67 GThread * updateHandler::thread = NULL;
68 void updateHandler::Init()
69 {
70  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FILE__, __FUNCTION__);
71 
72 #ifdef USE_MoCA_PROFILE
73  MoCAClientReqHandler::registerUpdateCallback(notifyCallback);
74 #endif /*USE_MoCA_PROFILE*/
75 
76  /* XREClientReqHandler::registerUpdateCallback(notifyCallback); */
77  EthernetClientReqHandler::registerUpdateCallback(notifyCallback);
78  /* DSClientReqHandler::registerUpdateCallback(notifyCallback);*/
79  IPClientReqHandler::registerUpdateCallback(notifyCallback);
80  DeviceClientReqHandler::registerUpdateCallback(notifyCallback);
81  /*TimeClientReqHandler::registerUpdateCallback(notifyCallback);*/
82 
83 #ifdef USE_WIFI_PROFILE
84  WiFiReqHandler::registerUpdateCallback(notifyCallback);
85 #endif
86 
87 #ifdef USE_DHCPv4_PROFILE
88  DHCPv4ClientReqHandler::registerUpdateCallback(notifyCallback);
89 #endif /* USE_DHCPv4_PROFILE*/
90 #ifdef USE_INTFSTACK_PROFILE
91  InterfaceStackClientReqHandler::registerUpdateCallback(notifyCallback);
92 #endif /* USE_STORAGESERVICE_PROFILE */
93 
94 #ifdef USE_XRESRC
95  XREClientReqHandler::registerUpdateCallback(notifyCallback);
96 #endif
97 
98 #ifdef USE_XRDK_BT_PROFILE
99  hostIf_DeviceInfoRdk_xBT::registerUpdateCallback(notifyCallback);
100 #endif // USE_XRDK_BT_PROFILE
101 
102  thread=g_thread_create(run,NULL,TRUE,NULL);
103  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FILE__, __FUNCTION__);
104 }
105 
106 void updateHandler::stop()
107 {
108  stopped = true;
109 }
110 
111 void updateHandler::reset()
112 {
113  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FILE__, __FUNCTION__);
114 #ifdef USE_MoCA_PROFILE
115  MoCAClientReqHandler::reset();
116 #endif /* USE_MoCA_PROFILE */
117  EthernetClientReqHandler::reset();
118  IPClientReqHandler::reset();
119  DeviceClientReqHandler::reset();
120 #ifdef USE_WIFI_PROFILE
121  WiFiReqHandler::reset();
122 #endif
123 
124 #ifdef USE_INTFSTACK_PROFILE
125  InterfaceStackClientReqHandler::reset();
126 #endif
127 #if 0
128 #ifdef USE_XRESRC
129  XREClientReqHandler::reset();
130 #endif
131 #endif
132 #ifdef USE_XRDK_BT_PROFILE
133  hostIf_DeviceInfoRdk_xBT::reset();
134 #endif
135 
136  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FILE__, __FUNCTION__);
137 }
138 
139 
140 
141 gpointer updateHandler::run(gpointer ptr)
142 {
143  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] updateHandler::run Entering..\n", __FILE__, __FUNCTION__);
144 // sleep(120);
145  while(!stopped)
146  {
147  RDK_LOG(RDK_LOG_TRACE2,LOG_TR69HOSTIF,"[%s:%s:%d] Entering..\n", __FILE__, __FUNCTION__, __LINE__);
148 #ifdef USE_MoCA_PROFILE
149  MoCAClientReqHandler::checkForUpdates();
150 #endif /* USE_MoCA_PROFILE*/
151  EthernetClientReqHandler::checkForUpdates();
152  IPClientReqHandler::checkForUpdates();
153  DeviceClientReqHandler::checkForUpdates();
154 #ifdef USE_WIFI_PROFILE
155  WiFiReqHandler::checkForUpdates();
156 #endif
157 #ifdef USE_DHCPv4_PROFILE
158  DHCPv4ClientReqHandler::checkForUpdates();
159 #endif /* USE_DHCPv4_PROFILE*/
160 #ifdef USE_INTFSTACK_PROFILE
161  InterfaceStackClientReqHandler::checkForUpdates();
162 #endif /* USE_STORAGESERVICE_PROFILE */
163 
164  /* No need to update now, since it has one instances */
165  /*XREClientReqHandler::checkForUpdates();*/
166 
167  /* Here no need to add event by agent. The agent will not
168  * be responsible for creating instances. The ACS can create
169  * instance and get the value for that instances. */
170  /*DSClientReqHandler::checkForUpdates();*/
171  /*TimeClientReqHandler::checkForUpdates(); */
172 #if 0
173 #ifdef USE_XRESRC
174  XREClientReqHandler::checkForUpdates();
175 #endif
176 #endif
177 #ifdef USE_XRDK_BT_PROFILE
178  hostIf_DeviceInfoRdk_xBT::checkForUpdates();
179 #endif
180 
181  sleep(60);
182  RDK_LOG(RDK_LOG_TRACE2,LOG_TR69HOSTIF,"[%s:%s:%d] Exiting..\n", __FILE__, __FUNCTION__, __LINE__);
183  }
184  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FILE__, __FUNCTION__);
185  return ptr;
186 }
187 
188 void updateHandler::notifyCallback(IARM_Bus_tr69HostIfMgr_EventId_t event_type, const char* paramName, const char* paramValue, HostIf_ParamType_t paramtype)
189 {
191  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] updateHandler::notifyCallback for Parameter :- %s..\n", __FILE__, __FUNCTION__,paramName);
192  strncpy(eventData.paramName,paramName, TR69HOSTIFMGR_MAX_PARAM_LEN-1);
193  eventData.paramName[TR69HOSTIFMGR_MAX_PARAM_LEN-1] = '\0';
194 
195  if(paramValue)
196  {
197  strncpy(eventData.paramValue, paramValue, TR69HOSTIFMGR_MAX_PARAM_LEN-1);
198  eventData.paramValue[TR69HOSTIFMGR_MAX_PARAM_LEN-1] = '\0';
199  }
200 
201  eventData.paramtype = paramtype;
202  IARM_Bus_BroadcastEvent(IARM_BUS_TR69HOSTIFMGR_NAME, (IARM_EventId_t) event_type, (void *)&eventData, sizeof(eventData));
203  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] Inside Parodus :- %s..\n", __FILE__, __FUNCTION__,paramName);
204 
205  if (IARM_BUS_TR69HOSTIFMGR_EVENT_VALUECHANGED == event_type &&
206  paramName && strcmp(paramName+strlen(paramName)-1,".")) // parameter name should not end with .
207  {
208  NotificationHandler::getInstance()->pushValueChangeNotification(eventData);
209  }
210 }
211 
212 void sendAddRemoveEvents (updateCallback callbackFn, int newValue, int& savedValue, char* objectPath)
213 {
214  // function lock to serialize sending add/remove events
215  static std::mutex m;
216 
217  static char instancePath[TR69HOSTIFMGR_MAX_PARAM_LEN];
218 
219  // grab function lock
220  std::lock_guard<std::mutex> lg(m);
221 
222  while (savedValue > newValue)
223  {
224  sprintf (instancePath, "%s%d.", objectPath, savedValue);
225  RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s] IARM_BUS_TR69HOSTIFMGR_EVENT_REMOVE %s\n", __FUNCTION__, instancePath);
226  callbackFn (IARM_BUS_TR69HOSTIFMGR_EVENT_REMOVE, instancePath, NULL, hostIf_IntegerType);
227  savedValue--;
228 // sleep(1);
229  }
230  while (savedValue < newValue)
231  {
232  RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s] IARM_BUS_TR69HOSTIFMGR_EVENT_ADD %s\n", __FUNCTION__, objectPath);
233  callbackFn (IARM_BUS_TR69HOSTIFMGR_EVENT_ADD, objectPath, NULL, hostIf_IntegerType);
234  savedValue++;
235 // sleep(1);
236  }
237 }
238 
239 /** @} */
240 /** @} */
IARM_BUS_TR69HOSTIFMGR_EVENT_REMOVE
@ IARM_BUS_TR69HOSTIFMGR_EVENT_REMOVE
Definition: hostIf_tr69ReqHandler.h:188
IARM_BUS_TR69HOSTIFMGR_EVENT_ADD
@ IARM_BUS_TR69HOSTIFMGR_EVENT_ADD
Definition: hostIf_tr69ReqHandler.h:187
hostIf_IPClient_ReqHandler.h
The header file provides HostIf IP client request handler information APIs.
_tr69HostIfMgr_EventData_t
Definition: hostIf_tr69ReqHandler.h:195
hostIf_StorageSrvc_ReqHandler.h
The header file provides HostIf Storage service request handler information APIs.
hostIf_XREClient_ReqHandler.h
The header file provides HostIf XRE Client request handler information APIs.
hostIf_DeviceClient_ReqHandler.h
The header file provides HostIf Device client request handler information APIs.
_tr69HostIfMgr_EventData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:199
IARM_Bus_tr69HostIfMgr_EventId_t
enum _tr69HostIfMgr_EventId_t IARM_Bus_tr69HostIfMgr_EventId_t
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
IARM_Bus_BroadcastEvent
IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *data, size_t len)
This API is used to publish an Asynchronous event to all IARM client registered for this perticular e...
HostIf_ParamType_t
enum _HostIf_ParamType HostIf_ParamType_t
hostIf_DHCPv4Client_ReqHandler.h
host Interface for DHCPV4 Client Request Handler.
hostIf_InterfaceStackClient_ReqHandler.h
The header file provides HostIf InterfaceStack client request handler information APIs.
hostIf_MoCAClient_ReqHandler.h
The header file provides HostIf MoCA client request handler information APIs.
hostIf_dsClient_ReqHandler.h
The header file provides HostIf ds client request handler information APIs.
IARM_BUS_TR69HOSTIFMGR_NAME
#define IARM_BUS_TR69HOSTIFMGR_NAME
Definition: hostIf_tr69ReqHandler.h:85
hostIf_WiFi_ReqHandler.h
The header file provides HostIf WiFi request handler information APIs.
XrdkBlueTooth.h
The header file provides components Xrdk SDCard information APIs.
hostIf_TimeClient_ReqHandler.h
The header file provides HostIf time client request handler information APIs.
IARM_BUS_TR69HOSTIFMGR_EVENT_VALUECHANGED
@ IARM_BUS_TR69HOSTIFMGR_EVENT_VALUECHANGED
Definition: hostIf_tr69ReqHandler.h:189
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199
hostIf_EthernetClient_ReqHandler.h
The header file provides HostIf Ethernet client request handler information APIs.