RDK Documentation (Open Sourced RDK Components)
Device_DeviceInfo_Processor.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 Device_DeviceInfo_Processor.cpp
22  * @brief This source file contains the APIs for getting device processor information.
23  */
24 
25 
26 /*****************************************************************************
27  * STANDARD INCLUDE FILES
28  *****************************************************************************/
29 
30 
31 /**
32 * @defgroup tr69hostif
33 * @{
34 * @defgroup hostif
35 * @{
36 **/
37 
38 
40 
41 GHashTable* hostIf_DeviceProcessorInterface::ifHash = NULL;
42 GMutex* hostIf_DeviceProcessorInterface::m_mutex = NULL;
43 
44 hostIf_DeviceProcessorInterface* hostIf_DeviceProcessorInterface::getInstance(int dev_id)
45 {
47  if(dev_id > getNumOfProcessorEntries())
48  {
49  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Processor interface instace doesnot exist..\n");
50  return pRet;
51  }
52 
53  if(ifHash)
54  {
55  pRet = (hostIf_DeviceProcessorInterface *)g_hash_table_lookup(ifHash,(gpointer) dev_id);
56  }
57  else
58  {
59  ifHash = g_hash_table_new(NULL,NULL);
60  }
61 
62  if(!pRet)
63  {
64  try {
65  pRet = new hostIf_DeviceProcessorInterface(dev_id);
66  } catch(int e)
67  {
68  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create Ethernet Interface instance..\n");
69  }
70  g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
71  }
72  return pRet;
73 }
74 
75 GList* hostIf_DeviceProcessorInterface::getAllInstances()
76 {
77  if(ifHash)
78  return g_hash_table_get_keys(ifHash);
79  return NULL;
80 }
81 
82 void hostIf_DeviceProcessorInterface::closeInstance(hostIf_DeviceProcessorInterface *pDev)
83 {
84  if(pDev)
85  {
86  g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
87  delete pDev;
88  }
89 }
90 
91 void hostIf_DeviceProcessorInterface::closeAllInstances()
92 {
93  if(ifHash)
94  {
95  GList* tmp_list = g_hash_table_get_values (ifHash);
96 
97  while(tmp_list)
98  {
100  tmp_list = tmp_list->next;
101  closeInstance(pDev);
102  }
103  }
104 }
105 
106 void hostIf_DeviceProcessorInterface::getLock()
107 {
108  if(!m_mutex)
109  {
110  m_mutex = g_mutex_new();
111  }
112  g_mutex_lock(m_mutex);
113 }
114 
115 void hostIf_DeviceProcessorInterface::releaseLock()
116 {
117  g_mutex_unlock(m_mutex);
118 }
119 
120 /**
121  * @brief Class Constructor of the class hostIf_DeviceProcessorInterface.
122  *
123  * It will initialize the device id.
124  *
125  * @param[in] devid Device identification Number.
126  */
128 {
129  dev_id = devid;
130  bCalledArchitecture = false;
131  backupArchitecture[0]='\0';
132 }
133 
134 
135 
136 unsigned int hostIf_DeviceProcessorInterface::getNumOfProcessorEntries(void) {
137 
138  FILE *fp = NULL;
139  char resultBuff[BUF_LEN] = {'\0'};
140  char cmd[BUF_LEN] = "/bin/cat /proc/cpuinfo | /bin/grep processor | /usr/bin/wc -l";
141  int noOfProcessorEntries = 0;
142 
143  fp = popen(cmd,"r");
144 
145  if(fp == NULL) {
146  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s(): Error popen\n", __FUNCTION__);
147  return 0;
148  }
149 
150  if(fgets(resultBuff, BUF_LEN,fp)!=NULL) {
151  sscanf(resultBuff,"%d",&noOfProcessorEntries);
152  }
153 
154  pclose(fp);
155 
156  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"%s(): Processors Count: [%d]\n", __FUNCTION__, noOfProcessorEntries);
157 
158  return noOfProcessorEntries;
159 }
160 
161 /**
162  * @brief This function use to get the architecture of the processor on the underlying hardware.
163  *
164  * @param[out] stMsgData TR-069 Host interface message request.
165  * @param[in] pChanged Status of the operation.
166  *
167  * @return Returns the status of the operation.
168  *
169  * @retval OK if it is successfully fetch the data from device.
170  * @retval NOK if not able to fetch the data from device.
171  * @ingroup TR69_HOSTIF_DEVICE_PROCESSOR_API
172  */
174 {
175  struct utsname utsName;
176  uname(&utsName);
177 
178  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"Get Architecture value: '%s'\n", utsName.machine);
179  strncpy(stMsgData->paramValue, utsName.machine, strlen(utsName.machine));
180  if(pChanged && bCalledArchitecture && strncpy(stMsgData->paramValue,backupArchitecture,strlen(stMsgData->paramValue)))
181  {
182  *pChanged = true;
183  }
184 
185  bCalledArchitecture = true;
186  strncpy(backupArchitecture,stMsgData->paramValue,sizeof(backupArchitecture) -1); //CID:136590 - Buffer size
187  backupArchitecture[sizeof(backupArchitecture)-1] = '\0';
188 
189  return OK;
190 }
191 /* End of doxygen group */
192 /**
193  * @}
194  */
195 
196 /* End of file xxx_api.c. */
197 
198 
199 /** @} */
200 /** @} */
Device_DeviceInfo_Processor.h
The header file provides TR069 device information of processor APIs.
hostIf_DeviceProcessorInterface
This class provides the interface for getting device processor information.
Definition: Device_DeviceInfo_Processor.h:71
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
hostIf_DeviceProcessorInterface::get_Device_DeviceInfo_Processor_Architecture
int get_Device_DeviceInfo_Processor_Architecture(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function use to get the architecture of the processor on the underlying hardware.
Definition: Device_DeviceInfo_Processor.cpp:173
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
hostIf_DeviceProcessorInterface::hostIf_DeviceProcessorInterface
hostIf_DeviceProcessorInterface(int dev_id)
Class Constructor of the class hostIf_DeviceProcessorInterface.
Definition: Device_DeviceInfo_Processor.cpp:127