RDK Documentation (Open Sourced RDK Components)
Device_IP_Diagnostics_IPPing.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 #include "Device_IP_Diagnostics_IPPing.h"
21 #include "hostIf_utils.h"
22 #include <string>
23 #include <fstream>
24 
25 const char* hostIf_IP_Diagnostics_IPPing::PROFILE_NAME = "Device.IP.Diagnostics.IPPing.";
26 
27 hostIf_IP_Diagnostics_IPPing::hostIf_IP_Diagnostics_IPPing ()
28 {
29  std::string filename;
30  filename.append ("/opt/tr-181/").append (PROFILE_NAME).append ("dat");
31 
32  // if file read fails or file doesn't exist, create empty file
33  if (!store.load (filename))
34  {
35  std::ofstream output_stream (filename.c_str());
36  }
37 }
38 
39 hostIf_IP_Diagnostics_IPPing& hostIf_IP_Diagnostics_IPPing::getInstance ()
40 {
41  static hostIf_IP_Diagnostics_IPPing instance;
42  return instance;
43 }
44 
45 int hostIf_IP_Diagnostics_IPPing::handleGetMsg (HOSTIF_MsgData_t* stMsgData)
46 {
47  LOG_ENTRY_EXIT;
48 
49  int ret = NOK;
50  std::string ipping_parameter_name (stMsgData->paramName + strlen (PROFILE_NAME));
51 
52  if (ipping_parameter_name.compare ("Host") &&
53  ipping_parameter_name.compare ("NumberOfRepetitions") &&
54  ipping_parameter_name.compare ("DataBlockSize"))
55  {
56  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Unsupported parameter '%s'\n", __FUNCTION__, stMsgData->paramName);
57  stMsgData->faultCode = fcInvalidParameterName;
58  }
59  else
60  {
61  std::string value = store.value (stMsgData->paramName, "");
62 
63  stMsgData->paramtype = hostIf_StringType;
64  stMsgData->paramLen = value.length ();
65  strncpy (stMsgData->paramValue, value.c_str (), stMsgData->paramLen);
66  stMsgData->faultCode = fcNoFault;
67  ret = OK;
68  }
69 
70  return ret;
71 }
72 
73 int hostIf_IP_Diagnostics_IPPing::handleSetMsg (HOSTIF_MsgData_t* stMsgData)
74 {
75  LOG_ENTRY_EXIT;
76 
77  int ret = NOK;
78  std::string ipping_parameter_name (stMsgData->paramName + strlen (PROFILE_NAME));
79 
80  if (ipping_parameter_name.compare ("Host") &&
81  ipping_parameter_name.compare ("NumberOfRepetitions") &&
82  ipping_parameter_name.compare ("DataBlockSize"))
83  {
84  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Unsupported parameter '%s'\n", __FUNCTION__, stMsgData->paramName);
85  stMsgData->faultCode = fcInvalidParameterName;
86  }
87  else if (false == store.setValue (stMsgData->paramName, stMsgData->paramValue))
88  {
89  stMsgData->faultCode = fcInternalError;
90  }
91  else
92  {
93  stMsgData->faultCode = fcNoFault;
94  ret = OK;
95  }
96 
97  return ret;
98 }
hostIf_IP_Diagnostics_IPPing
Definition: Device_IP_Diagnostics_IPPing.h:33
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
_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_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
_HostIf_MsgData_t::paramLen
short paramLen
Definition: hostIf_tr69ReqHandler.h:175