RDK Documentation (Open Sourced RDK Components)
hostIf_utils.h
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 #ifndef HOSTIF_UTILS_H_
31 #define HOSTIF_UTILS_H_
32 
33 #include <unistd.h>
34 #include <math.h>
35 #include <string>
36 #include "hostIf_main.h"
37 #include "hostIf_tr69ReqHandler.h"
38 
39 #define REBOOT_SCR "sh /rebootNow.sh -s hostIf_utils"
40 #define SCR_PATH "/lib/rdk"
41 #define NTP_FILE_NAME "/opt/persistent/firstNtpTime"
42 #define FW_DWN_FILE_PATH "/opt/fwdnldstatus.txt"
43 #define TEMP_FW_DWN_FILE_PATH "/opt/fwdnldstatus_tmp.txt"
44 #define JSONRPC_URL "http://127.0.0.1:9998/jsonrpc"
45 
46 #define BUFF_MAC 18
47 #define BUFF_MIN_16 16
48 #define BUFF_LENGTH_16 16
49 #define BUFF_LENGTH_32 32
50 #define BUFF_LENGTH_64 64
51 #define BUFF_LENGTH_128 128
52 #define BUFF_LENGTH_256 256
53 #define BUFF_LENGTH_1024 1024
54 #define BUFF_LENGTH BUFF_LENGTH_1024
55 
56 static const char* NOT_IMPLEMENTED = "Not Implemented";
57 
58 static const char* STATE_UP = "Up";
59 static const char* STATE_DOWN = "Down";
60 
61 static const char* TIME_UNKNOWN = "0001-01-01T00:00:00Z";
62 static const char* TIME_INFINITY = "9999-12-31T23:59:59Z";
63 
64 typedef enum __eSTBResetState
65 {
66  NoReset = 0,
67  ColdReset,
68  FactoryReset,
69  WarehouseReset,
70  CustomerReset
71 } eSTBResetState;
72 
73 typedef struct
74 {
75  int enumCode;
76  const char *enumString;
78 
80 {
81  const char* func;
82  const char* file;
83 public:
84  EntryExitLogger (const char* func, const char* file);
85  ~EntryExitLogger ();
86 };
87 
88 #define LOG_ENTRY_EXIT EntryExitLogger logger (__FUNCTION__, __FILE__)
89 
90 static volatile eSTBResetState gResetState = NoReset;
91 
92 void setResetState( eSTBResetState );
93 
94 eSTBResetState getResetState( void );
95 
96 void triggerResetScript(void);
97 
98 const char * getStringFromEnum( EnumStringMapper *, int, int );
99 
100 int getEnumFromString( EnumStringMapper *, int, const char * );
101 
102 bool matchComponent(const char* pParam, const char *pKey, const char **pSetting, int &instanceNo);
103 
104 int get_int(const char *ptr);
105 
106 void put_int(char *ptr, int val);
107 
108 uint get_uint(char *ptr);
109 
110 void put_uint(char *ptr, uint val);
111 
112 bool get_boolean(const char *ptr);
113 
114 void put_boolean(char *ptr, bool val);
115 
116 int get_ulong(const char* ptr);
117 
118 void put_ulong(char *ptr, unsigned long val);
119 
120 std::string int_to_string(int d);
121 
122 std::string uint_to_string(uint d);
123 
124 std::string ulong_to_string(unsigned long d);
125 
126 int string_to_int(const char *value);
127 
128 uint string_to_uint(const char *value);
129 
130 unsigned long string_to_ulong(const char *value);
131 
132 bool string_to_bool(const char *value);
133 
134 std::string getStringValue(HOSTIF_MsgData_t *stMsgData);
135 
136 void putValue(HOSTIF_MsgData_t *stMsgData, const std::string &value);
137 
138 /*
139  * Set the flag for ACS connection status
140  */
141 void set_ACSStatus(bool enabled);
142 
143 /*
144  * Get the flag for ACS connection status
145  */
146 bool get_ACSStatus();
147 
148 bool set_GatewayConnStatus();
149 bool get_GatewayConnStatus();
150 
151 /**
152  * Returns:
153  * the specified environment variable's value if it is not NULL.
154  * the specified default value otherwise.
155  */
156 char* getenvOrDefault (const char* name, char* defaultValue);
157 
158 int read_command_output (char* cmd, char* resultBuff, int length);
159 int GetStdoutFromCommand(char *cmd, string &consoleString);
160 
161 //bool write_config_file(const std::string &filename, const std::string &key, const std::string &value);
162 //std::string read_config_file(const std::string &filename, const std::string &key, const std::string &defaultValue);
163 
164 #ifndef NEW_HTTP_SERVER_DISABLE
165 void getCurrentTime(struct timespec *timer);
166 long timeValDiff(struct timespec *starttime, struct timespec *finishtime);
167 
168 void setLegacyRFCEnabled(bool value);
169 bool legacyRFCEnabled();
170 #endif
171 HostIf_Source_Type_t getBSUpdateEnum(const char *bsUpdate);
172 
173 bool isWebpaReady();
174 bool isNtpTimeFilePresent();
175 unsigned long get_system_manageble_ntp_time();
176 unsigned long get_device_manageble_time();
177 
178 /**
179  * This function retrieves the security token for Thunder.
180  * @return A string containing the security token or an empty string.
181  */
182 std::string get_security_token();
183 
184 
185 #endif /* HOSTIF_UTILS_H_*/
186 
187 
188 /** @} */
189 /** @} */
getCurrentTime
void getCurrentTime(struct timespec *timer)
Get Current time.
Definition: hostIf_utils.cpp:466
EntryExitLogger
Definition: hostIf_utils.h:79
getenvOrDefault
char * getenvOrDefault(const char *name, char *defaultValue)
Definition: hostIf_utils.cpp:404
HostIf_Source_Type_t
enum _HostIf_Source_Type_t HostIf_Source_Type_t
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
put_boolean
void put_boolean(char *ptr, bool val)
This function converts the input data to Boolean type.
Definition: hostIf_utils.cpp:191
hostIf_main.h
hostIf_main API.
get_security_token
std::string get_security_token()
Definition: hostIf_utils.cpp:572
GetStdoutFromCommand
int GetStdoutFromCommand(char *cmd, string &consoleString)
This function reads the complete output(upto 1k bytes) as string and return to caller....
Definition: hostIf_utils.cpp:435
EnumStringMapper
Definition: hostIf_utils.h:73
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152