RDK Documentation (Open Sourced RDK Components)
Service_Storage.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 Service_Storage.cpp
22  * @brief This source file contains the APIs of TR069 storage service.
23  */
24 #include <string.h>
26 #include "Service_Storage.h"
27 
28 #define MAX_CMD_LEN 128
29 #define MAX_BUF_LEN 256
30 #define MAX_IP_LEN 16
31 #define MAX_DEV_STR 6
32 
33 GHashTable *hostIf_StorageSrvc::storageSrvHash = NULL;
34 GMutex *hostIf_StorageSrvc::m_mutex = NULL;
35 
36 /* Constructor for hostIf_StorageSrvc*/
37 
38 /**
39  * @brief Class Constructor of the class hostIf_StorageSrvc.
40  *
41  * It will initialize the device id.
42  *
43  * @param[in] dev_id Identification number of the device.
44  */
45 hostIf_StorageSrvc::hostIf_StorageSrvc(int dev_id):dev_id(dev_id) {
46  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Inside constructor for dev_id:%d\n", dev_id);
47 }
48 
49 void hostIf_StorageSrvc::getLock()
50 {
51  if(!m_mutex)
52  {
53  m_mutex = g_mutex_new();
54  }
55  g_mutex_lock(m_mutex);
56 }
57 
58 void hostIf_StorageSrvc::releaseLock()
59 {
60  g_mutex_unlock(m_mutex);
61 }
62 
63 hostIf_StorageSrvc* hostIf_StorageSrvc::getInstance(int dev_id)
64 {
65  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Entering [%s]\n", __FUNCTION__);
66  hostIf_StorageSrvc* pRet = NULL;
67  int maxInstance = 0;
68  HOSTIF_MsgData_t stMsgData;
69  if(NULL==storageSrvHash)
70  {
71  get_Device_StorageSrvc_ClientNumberOfEntries(&stMsgData);
72  }
73  pRet = (hostIf_StorageSrvc *)g_hash_table_lookup(storageSrvHash, (gpointer) dev_id);
74  return pRet;
75 }
76 
77 
78 GList* hostIf_StorageSrvc::getAllInstances()
79 {
80  if(storageSrvHash)
81  return g_hash_table_get_keys(storageSrvHash);
82  return NULL;
83 }
84 
85 
86 void hostIf_StorageSrvc::closeInstance(hostIf_StorageSrvc *pDev)
87 {
88  if(pDev)
89  {
90  g_hash_table_remove(storageSrvHash, (gconstpointer)pDev->dev_id);
91  delete pDev;
92  }
93 }
94 
95 
96 void hostIf_StorageSrvc::closeAllInstances()
97 {
98  if(storageSrvHash)
99  {
100  GList* val_list = g_hash_table_get_values (storageSrvHash);
101  GList* tmp_list = val_list;
102  while(tmp_list)
103  {
104  hostIf_StorageSrvc* pDev = (hostIf_StorageSrvc *)tmp_list->data;
105  tmp_list = tmp_list->next;
106  closeInstance(pDev);
107  }
108  g_list_free(val_list);
109  }
110 }
111 
112 
113 unsigned int hostIf_StorageSrvc :: get_Device_StorageSrvc_ClientNumberOfEntries(HOSTIF_MsgData_t* stMsgData)
114 {
115  //Currently we have only one type of Storage service. The one which is within the box. So Number of entries is one.
116  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Entring :%s\n",__FUNCTION__);
117  int numberOfEntries = 1;
118  put_int(stMsgData->paramValue, numberOfEntries);
119  stMsgData->paramtype = hostIf_UnsignedIntType;
120  stMsgData->paramLen = sizeof(unsigned int);
121  hostIf_StorageSrvc* pRet = NULL;
122  if(NULL != storageSrvHash)
123  {
124  closeAllInstances();
125  }
126  else
127  {
128  storageSrvHash = g_hash_table_new(NULL, NULL);
129  }
130  for(int index=1;index<=numberOfEntries; index++)
131  {
132  try
133  {
134  pRet = new hostIf_StorageSrvc(index);
135  g_hash_table_insert(storageSrvHash, (gpointer)(index), pRet);
136  }
137  catch(int e)
138  {
139  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create physical medium instance..\n");
140  }
141  }
142  return OK;
143 }
144 
145 /**
146  * @brief This function get the hostIf storage service interface such as total number
147  * physical medium entries, attributes of physical medium "Name", "SmartCapable" and
148  * "Health".
149  *
150  * @param[in] stMsgData HostIf Message Request param contains the storage service attribute value.
151  *
152  * @return Returns an Integer value.
153  * @retval 0 If successfully get the hostIf storage service interface attribute.
154  * @retval -1 If Not able to get the hostIf storage service interface attribute.
155  * @retval -2 If Not handle the hostIf storage service interface attribute.
156  * @ingroup TR69_HOSTIF_STORAGE_SERVICE_API
157  */
159 {
160  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Entring:%s\n",__FUNCTION__);
161  int retVal = NOK;
162  string param;
163  const char* psettings;
164  const char* pSubSettings;
165  int instanceNumber = 0;
166  char dev_str[MAX_DEV_STR]={'\0'};
167  /* Incoming message will be of Device.Service.StorageService.1.PhysicalMedium.1.X
168  * We would have parsed till Device.Service.StorageService.1, Now we have to find
169  * the handler for the remaining part and call the functon accordingly
170  */
171  hostIf_PhysicalMedium *pPhyMed ;
172  param.assign("Device.Services.StorageService");
173  snprintf(dev_str, MAX_DEV_STR, ".%d",dev_id);
174  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Param Name:%s param:%s\n",stMsgData->paramName,param.c_str());
175  if(matchComponent(stMsgData->paramName, param.c_str(), &psettings, instanceNumber))
176  {
177  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"psettings:%s\n",psettings);
178  if(strcasecmp(psettings,"PhysicalMediumNumberOfEntries")==0)
179  {
180  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Getting the number of physical medium number of entries\n");
181  retVal = hostIf_PhysicalMedium::get_Device_Service_StorageMedium_ClientNumberOfEntries(stMsgData, dev_id);
182  }
183  else if(strncasecmp(psettings,"PhysicalMedium.",strlen("PhysicalMedium."))==0)
184  {
185  param.append(dev_str);
186  param.append(".PhysicalMedium");
187  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Getting the param value for Physical Medium:%s from param name:%s\n",param.c_str(), stMsgData->paramName);
188  if(matchComponent(stMsgData->paramName, param.c_str(), &pSubSettings, instanceNumber))
189  {
190  F("Sub param:%s\n",pSubSettings);
191  pPhyMed = hostIf_PhysicalMedium :: getInstance(dev_id,instanceNumber);
192  if(NULL!= pPhyMed )
193  {
194  if(0 == strcasecmp(pSubSettings, "Name"))
195  {
196  retVal = pPhyMed->get_Device_Service_StorageMedium_Name(stMsgData);
197  }
198  else if(0 == strcasecmp(pSubSettings, "SmartCapable"))
199  {
200  retVal = pPhyMed->get_Device_Service_StorageMedium_SMARTCapable(stMsgData);
201  }
202  else if(0 == strcasecmp(pSubSettings, "Health"))
203  {
204  retVal = pPhyMed->get_Device_Service_StorageMedium_Health(stMsgData);
205  }
206  else
207  {
208  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%d] Parameter : \'%s\' is Not Supported \n", __FUNCTION__, __LINE__, stMsgData->paramName);
209  stMsgData->faultCode = fcInvalidParameterName;
210  ret = NOK;
211  }
212  }
213 
214  }
215  else
216  {
217  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Failed to match component\n");
218  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%d] Parameter : \'%s\' is Not Supported \n", __FUNCTION__, __LINE__, stMsgData->paramName);
219  stMsgData->faultCode = fcInvalidParameterName;
220  ret = NOK;
221  }
222  }
223  else
224  {
225  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s not implemented\n",stMsgData->paramName);
226  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%d] Parameter : \'%s\' is Not Supported \n", __FUNCTION__, __LINE__, stMsgData->paramName);
227  stMsgData->faultCode = fcInvalidParameterName;
228  ret = NOK;
229  }
230  }
231  else
232  {
233  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Not able to get component:%s %s %d",stMsgData->paramName, __FUNCTION__, __LINE__);
234  stMsgData->faultCode = fcInvalidParameterName;
235  ret = NOK;
236  }
237  return retVal;
238 }
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_Health
int get_Device_Service_StorageMedium_Health(HOSTIF_MsgData_t *stMsgData)
This function get the health of the storage service medium.
Definition: Service_Storage_PhyMedium.cpp:300
Service_Storage.h
The header file provides storage service information APIs.
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
hostIf_StorageSrvc::handleGetMsg
int handleGetMsg(HOSTIF_MsgData_t *stMsgData)
This function get the hostIf storage service interface such as total number physical medium entries,...
Definition: Service_Storage.cpp:158
Service_Storage_PhyMedium.h
The header file provides storage service physical medium information APIs.
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
_HostIf_MsgData_t::faultCode
faultCode_t faultCode
Definition: hostIf_tr69ReqHandler.h:179
hostIf_PhysicalMedium
This class provides the TR-069 host interface physical medium information.
Definition: Service_Storage_PhyMedium.h:114
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_SMARTCapable
int get_Device_Service_StorageMedium_SMARTCapable(HOSTIF_MsgData_t *stMsgData)
This function get the SMART capability of the storage service medium.
Definition: Service_Storage_PhyMedium.cpp:324
_HostIf_MsgData_t::paramName
char paramName[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:171
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_Name
int get_Device_Service_StorageMedium_Name(HOSTIF_MsgData_t *stMsgData)
This function get the name of the storage service medium.
Definition: Service_Storage_PhyMedium.cpp:276
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
hostIf_StorageSrvc
This class provides the TR-069 storage service information.
Definition: Service_Storage.h:99
hostIf_StorageSrvc::hostIf_StorageSrvc
hostIf_StorageSrvc(int dev_id)
Class Constructor of the class hostIf_StorageSrvc.
Definition: Service_Storage.cpp:45
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152
_HostIf_MsgData_t::paramLen
short paramLen
Definition: hostIf_tr69ReqHandler.h:175