common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / systemservice / logger_service / server / src / ss_logger_cfg.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_SS_LoggerService
19 /// \brief    Provide support for CPU high load monitor configuration.
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////////////////
23 // INCLUDES
24 ///////////////////////////////////////////////////////////////////////////////
25 #include "ss_logger_cfg.h"
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include <dirent.h>
30 #include <boost/bind.hpp>
31 #include <native_service/nslogutil_cmd_if.h>
32 #include <native_service/ns_np_service_protocol.h>
33 #include <system_service/ss_logger_service_notifications.h>
34 #include <iostream>
35 #include <iomanip>
36 #include <sstream>
37 #include <string>
38 #include <algorithm>
39 #include <vector>
40
41 const static UI_32 cMAX_EMMC_COUNTER_VALUE = 100000u;  // NOLINT (build/storage_class)
42 ///////////////////////////////////////////////////////////////////////////////
43 // CLASS METHODS
44 ///////////////////////////////////////////////////////////////////////////////
45
46 CLoggerCfg::CLoggerCfg()
47   : m_logMaxFileSize(0),
48     m_performanceLogMaxFileSize(0),
49     m_emmcOutputMax(0),
50     m_emmcOutputErrMax(0),
51     m_emmcOutputGrpRelaunchMax(0),
52     m_emmcOutputNaviLogMax(0),
53     m_emmcOutputNaviLogNmlMax(0),
54     m_emmcOutputNaviLogErrMax(0),
55     m_emmcOutputPath(""),
56     m_emmcOutputNaviLogPath(""),
57     m_usb0MountPath(""),
58     m_usb1MountPath(""),
59     m_sdMountPath(""),
60     m_eDevType(eDevUSB1),
61     m_UserInvokedLoggingNumber(1u),
62     m_EmmcCounter(0u),
63     m_eLoggerUDPLoggingStatus(eDeactivate),
64     m_eLoggerStatus(SS_LOGGER_DEFAULT_VALUE) {
65       m_udpEnvFlag = FALSE;
66       std::memset(m_logMask, 0, sizeof(m_logMask));
67       std::memset(&m_ExternalLogList, 0, sizeof(&m_ExternalLogList));
68     }
69
70 CLoggerCfg::~CLoggerCfg(void) {  // LCOV_EXCL_START 14:global instance
71   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
72
73   if (m_ExternalLogList.p_info != NULL) {
74     delete[] m_ExternalLogList.p_info;
75     m_ExternalLogList.p_info = NULL;
76   }
77 }
78 // LCOV_EXCL_STOP
79
80 EFrameworkunifiedStatus CLoggerCfg::Initialize(HANDLE f_hApp) {
81   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
82
83   char* l_udp_env = getenv("UDPLOGS_ON");
84   m_udpEnvFlag = (
85       l_udp_env == NULL ?
86           FALSE : (strcmp("TRUE", l_udp_env) == 0 ? TRUE : FALSE));
87
88   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
89   return eFrameworkunifiedStatusOK;
90 }
91 EFrameworkunifiedStatus CLoggerCfg::SetandPersistLoggingParams(HANDLE f_hApp,
92                                                   STLoggerSetAllParams f_Params,
93                                                   BOOL f_InitCall) {
94   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
95   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
96   BOOL l_paramChanged = f_InitCall;
97   BOOL l_updateLoggerState = f_InitCall;
98
99   if ((TRUE == l_paramChanged)  // LCOV_EXCL_BR_LINE 200:l_paramChanged is never TRUE
100       ||
101       (m_eLoggerStatus != f_Params.Logger_State)
102       ||  // LCOV_EXCL_BR_LINE 200:Because m_UserInvokedLoggingNumber != f_Params.Log_FolderCnt is never false
103       (m_UserInvokedLoggingNumber != f_Params.Log_FolderCnt)
104       || (m_eLoggerUDPLoggingStatus != f_Params.Logger_UDPState)
105       || (m_eDevType != f_Params.Device_Type)) {
106     l_paramChanged = TRUE;
107   } else {
108     l_paramChanged = FALSE;
109   }
110
111   l_updateLoggerState =
112       ((l_updateLoggerState == TRUE)
113           || (m_eLoggerStatus != f_Params.Logger_State)) ? TRUE : FALSE;
114
115   // After startup Logging will be set to default value
116   if (TRUE == f_InitCall) {  // LCOV_EXCL_BR_LINE 200:f_InitCall is never TRUE
117     // LCOV_EXCL_START 200:f_InitCall is never TRUE
118     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
119     m_eLoggerStatus = SS_LOGGER_DEFAULT_VALUE;
120     // LCOV_EXCL_STOP
121   } else {
122     m_eLoggerStatus = f_Params.Logger_State;
123   }
124   m_eLoggerUDPLoggingStatus = f_Params.Logger_UDPState;
125   m_UserInvokedLoggingNumber = f_Params.Log_FolderCnt;
126   m_eDevType = f_Params.Device_Type;
127
128   if (TRUE == l_paramChanged) {
129     l_eStatus = PersistLoggingParam(f_hApp);
130     LOG_STATUS_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: macro
131                           "PersistLoggingParam()");
132   }
133
134   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
135   return (l_eStatus);
136 }
137
138 EFrameworkunifiedStatus CLoggerCfg::SetLoggingParams(HANDLE f_hApp,
139                                         const STLoggerSetParams f_stLoggerSetParams) {
140   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
141   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
142   STLoggerSetAllParams l_Params;
143
144   l_Params.Logger_UDPState = m_eLoggerUDPLoggingStatus;
145   l_Params.Log_FolderCnt = m_UserInvokedLoggingNumber;
146   l_Params.Logger_State = f_stLoggerSetParams.Logger_State;
147   l_Params.Device_Type = f_stLoggerSetParams.Device_Type;
148
149   l_eStatus = SetandPersistLoggingParams(f_hApp, l_Params, FALSE);
150   LOG_STATUS_IF_ERRORED(l_eStatus, "SetandPersistLoggingParams()");  // LCOV_EXCL_BR_LINE 15: macro
151
152   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
153   return (l_eStatus);
154 }
155
156 EFrameworkunifiedStatus CLoggerCfg::SetUDPLogging(HANDLE f_hApp,
157                                      const ELOGGER_STAT f_eUDPLoggingStatus) {
158   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
159   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
160   STLoggerSetAllParams l_Params;
161
162   l_Params.Logger_UDPState = f_eUDPLoggingStatus;
163   l_Params.Log_FolderCnt = m_UserInvokedLoggingNumber;
164   l_Params.Logger_State = m_eLoggerStatus;
165   l_Params.Device_Type = m_eDevType;
166
167   l_eStatus = SetandPersistLoggingParams(f_hApp, l_Params, FALSE);
168   LOG_STATUS_IF_ERRORED(l_eStatus, "SetandPersistLoggingParams()");  // LCOV_EXCL_BR_LINE 15: macro
169
170   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
171   return (l_eStatus);
172 }
173
174 EFrameworkunifiedStatus CLoggerCfg::PersistLoggingParam(HANDLE f_hApp) {
175   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
176   FRAMEWORKUNIFIEDLOG(
177       ZONE_INFO, __FUNCTION__,
178       "LoggerState = %d, Device_Type = %d,UDPLogging = %d, TriggerNumber = %d",
179       m_eLoggerStatus, m_eDevType, m_eLoggerUDPLoggingStatus,
180       m_UserInvokedLoggingNumber);  // LCOV_EXCL_BR_LINE 11:Unexpected branch
181
182   this->UpdateLoggingStatus();
183   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
184   return eFrameworkunifiedStatusOK;
185 }
186
187 void CLoggerCfg::RemoveCarriageReturn(std::string &f_str) {
188   if (f_str.empty()) {  // LCOV_EXCL_BR_LINE 8: Because there is no empty string case
189     return;
190   }
191
192   if ('\r' == f_str.at(f_str.size() - 1)) {
193     f_str.erase(f_str.size() - 1, 1);
194   }
195 }
196 EFrameworkunifiedStatus CLoggerCfg::Load(const std::string &f_filePathAndName) {
197   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
198   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusDbRecNotFound;
199
200   if ("" == f_filePathAndName) {  // LCOV_EXCL_BR_LINE 200: Because there is no empty string case
201     // LCOV_EXCL_START 200: Because there is no empty string case
202     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
203     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Invalid configuration file name detected.");
204     l_eStatus = eFrameworkunifiedStatusInvldParam;
205     // LCOV_EXCL_STOP
206   } else {
207     // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Reading Configuration Data from %s", f_filePathAndName.c_str());
208
209     CNSConfigReader *l_pReaderCfg = new CNSConfigReader();  // LCOV_EXCL_BR_LINE 11:except,C++ STL
210     if (NULL == l_pReaderCfg) {  // LCOV_EXCL_BR_LINE 5:new error
211       // LCOV_EXCL_START 5:new error
212       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
213       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
214              " Error. Unable to allocate CNSConfigReader object.");
215       l_eStatus = eFrameworkunifiedStatusFileLoadError;
216       // LCOV_EXCL_STOP
217     } else {
218       if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->Parse(f_filePathAndName))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
219         // LCOV_EXCL_START 200:To ensure success
220         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
221         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
222                " Error. l_pReaderCfg->Parse(%s) returned: 0x%X",
223                f_filePathAndName.c_str(), l_eStatus);
224         // LCOV_EXCL_STOP
225       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.LogMaxFileSize", m_logMaxFileSize))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
226         // LCOV_EXCL_START 200:To ensure success
227         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
228         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(LOGGING.LogMaxFileSize)");
229         // LCOV_EXCL_STOP
230       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.PerformanceLogSize", m_performanceLogMaxFileSize))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
231         // LCOV_EXCL_START 200:To ensure success
232         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
233         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(LOGGING.LogMaxFileSize)");
234         // LCOV_EXCL_STOP
235       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.EmmcOutputPath", m_emmcOutputPath))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
236         // LCOV_EXCL_START 200:To ensure success
237         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
238         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.EmmcOutputPath)");
239         // LCOV_EXCL_STOP
240       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.EmmcOutputNaviLogPath", m_emmcOutputNaviLogPath))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
241         // LCOV_EXCL_START 200:To ensure success
242         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
243         LOG_STATUS(l_eStatus,
244                    "l_pReaderCfg->GetString(LOGGING.EmmcOutputNaviLogPath)");
245         // LCOV_EXCL_STOP
246       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.Usb0MountPath", m_usb0MountPath))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
247         // LCOV_EXCL_START 200:To ensure success
248         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
249         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.Usb0MountPath)");
250         // LCOV_EXCL_STOP
251       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.Usb1MountPath", m_usb1MountPath))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
252         // LCOV_EXCL_START 200:To ensure success
253         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
254         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.Usb1MountPath)");
255         // LCOV_EXCL_STOP
256       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("LOGGING.SdMountPath", m_sdMountPath))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
257         // LCOV_EXCL_START 200:To ensure success
258         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
259         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.SdMountPath)");
260         // LCOV_EXCL_STOP
261       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputMax", m_emmcOutputMax))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
262         // LCOV_EXCL_START 200:To ensure success
263         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
264         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.EmmcOutputMax)");
265         // LCOV_EXCL_STOP
266       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputErrMax", m_emmcOutputErrMax))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
267         // LCOV_EXCL_START 200:To ensure success
268         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
269         LOG_STATUS(l_eStatus,
270                    "l_pReaderCfg->GetString(LOGGING.EmmcOutputErrMax)");
271         // LCOV_EXCL_STOP
272       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputGrpRelaunchMax", m_emmcOutputGrpRelaunchMax))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
273         // LCOV_EXCL_START 200:To ensure success
274         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
275         LOG_STATUS(l_eStatus,
276                    "l_pReaderCfg->GetString(LOGGING.EmmcOutputGrpRelaunchMax)");
277         // LCOV_EXCL_STOP
278       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputNaviLogMax", m_emmcOutputNaviLogMax))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
279         // LCOV_EXCL_START 200:To ensure success
280         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
281         LOG_STATUS(l_eStatus,
282                    "l_pReaderCfg->GetString(LOGGING.EmmcOutputNaviLogMax)");
283         // LCOV_EXCL_STOP
284       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputNaviLogNmlMax", m_emmcOutputNaviLogNmlMax))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
285         // LCOV_EXCL_START 200:To ensure success
286         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
287         LOG_STATUS(l_eStatus,
288                    "l_pReaderCfg->GetString(LOGGING.EmmcOutputNaviLogNmlMax)");
289         // LCOV_EXCL_STOP
290       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.EmmcOutputNaviLogErrMax", m_emmcOutputNaviLogErrMax))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
291         // LCOV_EXCL_START 200:To ensure success
292         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
293         LOG_STATUS(l_eStatus,
294                    "l_pReaderCfg->GetString(LOGGING.EmmcOutputNaviLogErrMax)");
295         // LCOV_EXCL_STOP
296       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetString("STORAGE.ThreadName", m_loggerStorageInfo.Name))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
297         // LCOV_EXCL_START 200:To ensure success
298         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
299         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(STORAGE.ThreadName)");
300         // LCOV_EXCL_STOP
301       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("STORAGE.Priority", m_loggerStorageInfo.Priority))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
302         // LCOV_EXCL_START 200:To ensure success
303         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
304         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(STORAGE.Priority)");
305         // LCOV_EXCL_STOP
306       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("STORAGE.Timeout", m_loggerStorageInfo.Timeout))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
307         // LCOV_EXCL_START 200:To ensure success
308         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
309         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(STORAGE.Timeout)");
310         // LCOV_EXCL_STOP
311       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("STORAGE.TimeoutAfter", m_loggerStorageInfo.TimeoutAfter))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
312         // LCOV_EXCL_START 200:To ensure success
313         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
314         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetInt(STORAGE.TimeoutAfter)");
315         // LCOV_EXCL_STOP
316       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.ExternalLogNum", m_ExternalLogList.num))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
317         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.ExternalLogNum)");  // LCOV_EXCL_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
318       } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt("LOGGING.ExternalLogMax", m_ExternalLogList.max))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
319         LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(LOGGING.ExternalLogMax)");  // LCOV_EXCL_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
320       } else {
321         RemoveCarriageReturn(m_emmcOutputPath);
322         RemoveCarriageReturn(m_emmcOutputNaviLogPath);
323         RemoveCarriageReturn(m_usb0MountPath);
324         RemoveCarriageReturn(m_usb1MountPath);
325         RemoveCarriageReturn(m_sdMountPath);
326         RemoveCarriageReturn(m_loggerStorageInfo.Name);
327
328         for (UI_32 i = 0; i < ZONE_MASK_ARRAY_ELTS; i++) {
329           SI_32 l_logMaskTemp;
330           std::stringstream l_cfgParamName;
331
332           l_cfgParamName << "SETLOGMASK.MASK" << i;
333           if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->GetInt(l_cfgParamName.str(), l_logMaskTemp))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
334             // LCOV_EXCL_START 200:To ensure success
335             AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
336             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
337                    " Error. l_pReaderCfg->GetInt(%s) failed with error: %d.",
338                    l_cfgParamName.str().c_str(), l_eStatus);
339
340             break;
341             // LCOV_EXCL_STOP
342           } else {
343             m_logMask[i] = (UI_32) l_logMaskTemp;
344           }
345         }
346
347         m_EELStorageRelPath = "/EEL_export";
348         m_EELActivateRelPath = "/EEL_activate";
349         m_LoggerserviceEmmcLogsRelPath = "/LOGGERSERVICE_EMMC_LOGS";
350
351         if (m_ExternalLogList.num > 0) {
352           std::string str = "EXTERNAL_";  // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
353           UI_32 num = 0;
354
355           if (m_ExternalLogList.num <= m_ExternalLogList.max) {
356             num = m_ExternalLogList.num;
357           } else {
358             num = m_ExternalLogList.max;
359           }
360
361           // LCOV_EXCL_BR_START 11:Excluded due to gcov constraints (others)
362           m_ExternalLogList.p_info = new ExternalLogInfo[num];
363
364           // Load external log info
365           for (UI_32 i = 0; i < num; i++) {
366             std::string query = str + std::to_string(i+1);
367             if (eFrameworkunifiedStatusOK !=
368                 (l_eStatus = l_pReaderCfg->GetString((query+".OutputPath"), m_ExternalLogList.p_info[i].dirname))) {
369               LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(EXTERNAL.OutputPath)");  // LCOV_EXCL_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
370             } else if (eFrameworkunifiedStatusOK !=
371                 (l_eStatus = l_pReaderCfg->GetString((query+".ExtLogPath"), m_ExternalLogList.p_info[i].path))) {
372               LOG_STATUS(l_eStatus, "l_pReaderCfg->GetString(EXTERNAL.ExtLogPath)");  // LCOV_EXCL_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
373             } else if (eFrameworkunifiedStatusOK !=
374                 (l_eStatus = l_pReaderCfg->GetBool((query+".Remove"), m_ExternalLogList.p_info[i].remove))) {
375               LOG_STATUS(l_eStatus, "l_pReaderCfg->GetBool(EXTERNAL.Remove)");  // LCOV_EXCL_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
376             } else {
377               RemoveCarriageReturn(m_ExternalLogList.p_info[i].dirname);
378               RemoveCarriageReturn(m_ExternalLogList.p_info[i].path);
379             }
380           }
381           // LCOV_EXCL_BR_STOP 11:Excluded due to gcov constraints (others)
382         } else {
383           // None external log
384         }
385
386         if (eFrameworkunifiedStatusOK == l_eStatus) {  // LCOV_EXCL_BR_LINE 200:To ensure success
387           FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
388                  " Info. Configuration successfully loaded.");  // LCOV_EXCL_BR_LINE 15: macro
389         }
390       }
391
392       delete l_pReaderCfg;  // LCOV_EXCL_BR_LINE 11:Unexpected branch
393     }
394   }
395
396   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
397   return (l_eStatus);
398 }
399
400 EFrameworkunifiedStatus CLoggerCfg::Validate(void) {
401   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
402   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam;
403
404   if (m_logMaxFileSize == 0) {  // LCOV_EXCL_BR_LINE 200:Because the size is never 0
405     // LCOV_EXCL_START 200:Because the size is never 0
406     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
407     FRAMEWORKUNIFIEDLOG(
408         ZONE_ERR,
409         __FUNCTION__,
410         " Error. Invalid configuration detected. LogMaxFileSize: %d Must be > 0.",
411         m_logMaxFileSize);
412     // LCOV_EXCL_STOP
413   } else if (m_emmcOutputPath == "") {
414     FRAMEWORKUNIFIEDLOG(
415         ZONE_ERR,
416         __FUNCTION__,
417         " Error. Invalid configuration detected."
418         " EmmcOutputPath: %s Must be a valid path containing a trailing backslash.",
419         m_emmcOutputPath.c_str());
420   } else if (m_emmcOutputNaviLogPath == "") {  // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string
421     // LCOV_EXCL_START 200:Because it is not always an empty string
422     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
423     FRAMEWORKUNIFIEDLOG(
424         ZONE_ERR,
425         __FUNCTION__,
426         " Error. Invalid configuration detected."
427         " EmmcOutputNaviLogPath: %s Must be a valid path containing a trailing backslash.",
428         m_emmcOutputNaviLogPath.c_str());
429     // LCOV_EXCL_STOP
430   } else if (m_usb0MountPath == "") {  // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string
431     // LCOV_EXCL_START 200:Because it is not always an empty string
432     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
433     FRAMEWORKUNIFIEDLOG(
434         ZONE_ERR,
435         __FUNCTION__,
436         " Error. Invalid configuration detected."
437         " Usb0MountPath: %s Must be a valid path containing a trailing backslash.",
438         m_usb0MountPath.c_str());
439     // LCOV_EXCL_STOP
440   } else if (m_usb1MountPath == "") {  // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string
441     // LCOV_EXCL_START 200:Because it is not always an empty string
442     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
443     FRAMEWORKUNIFIEDLOG(
444         ZONE_ERR,
445         __FUNCTION__,
446         " Error. Invalid configuration detected."
447         " Usb1MountPath: %s Must be a valid path containing a trailing backslash.",
448         m_usb1MountPath.c_str());
449     // LCOV_EXCL_STOP
450   } else if (m_sdMountPath == "") {  // LCOV_EXCL_BR_LINE 200:Because it is not always an empty string
451     // LCOV_EXCL_START 200:Because it is not always an empty string
452     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
453     FRAMEWORKUNIFIEDLOG(
454         ZONE_ERR,
455         __FUNCTION__,
456         " Error. Invalid configuration detected. SdMountPath: %s Must be a valid path containing a trailing backslash.",
457         m_sdMountPath.c_str());
458     // LCOV_EXCL_STOP
459   } else {
460     l_eStatus = eFrameworkunifiedStatusOK;
461   }
462
463   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
464   return (l_eStatus);
465 }
466
467 void CLoggerCfg::Print(void) {
468   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
469
470   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
471 }
472
473 std::string CLoggerCfg::getEmmcOutputPath(void) {
474   return (m_emmcOutputPath);
475 }
476
477 std::string CLoggerCfg::getEmmcOutputNaviLogPath(void) {
478   return (m_emmcOutputNaviLogPath);
479 }
480
481 std::string CLoggerCfg::getUsb0MountPath(void) {
482   return (m_usb0MountPath);
483 }
484 void CLoggerCfg::setUsb0MountPath(std::string& f_deviceMountpath) {
485   m_usb0MountPath = f_deviceMountpath;
486 }
487
488 EFrameworkunifiedStatus CLoggerCfg::GetUserInvokedDestination(std::string& f_dest) {
489   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
490   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
491
492   f_dest = "";
493   switch (m_eDevType) {
494     case eDevUSB1:
495       f_dest = m_usb0MountPath;
496       break;
497
498     case eDevUSB2:
499       f_dest = m_usb1MountPath;
500       break;
501
502     case eDevSD:
503       f_dest = m_sdMountPath;
504       break;
505
506     case eTotalDevicesTypes:
507     case eInvalid_DevType:
508     default:
509       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Unknown device type: %d",
510              m_eDevType);
511       l_eStatus = eFrameworkunifiedStatusFail;
512       break;
513   }
514
515   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
516   return (l_eStatus);
517 }
518
519 EFrameworkunifiedStatus CLoggerCfg::GetEmmcDestination(std::string& f_dest) {
520   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
521   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
522
523   f_dest = m_emmcOutputPath;
524
525   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
526   return (l_eStatus);
527 }
528
529 EFrameworkunifiedStatus CLoggerCfg::GetEmmcNaviLogDestination(std::string& f_dest) {
530   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
531   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
532
533   f_dest = m_emmcOutputNaviLogPath;
534
535   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
536   return (l_eStatus);
537 }
538
539 UI_32 CLoggerCfg::GetUserInvokedCounter(void) {
540   return m_UserInvokedLoggingNumber;
541 }
542
543 EFrameworkunifiedStatus CLoggerCfg::GetIncrementAndPersistUserInvokedCounter(
544     HANDLE f_hApp, UI_32 &f_counter) {
545   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
546   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
547
548   f_counter = m_UserInvokedLoggingNumber;
549   m_UserInvokedLoggingNumber++;
550   l_eStatus = PersistLoggingParam(f_hApp);
551
552   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
553   return (l_eStatus);
554 }
555
556 EFrameworkunifiedStatus CLoggerCfg::GetAndIncrementEmmcCounter(UI_32 &f_counter) {
557   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
558   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
559   std::string l_checkFileName;
560   std::vector<UI_32> l_vector;
561   DIR *l_dirp;
562   struct dirent l_dirent;
563   struct dirent* next = NULL;
564   size_t l_pos;
565   UI_32 l_count;
566   UI_32 l_maxCount;
567
568   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
569
570   if (m_EmmcCounter == 0u) {
571     l_maxCount = 0;
572     l_dirp = opendir(m_emmcOutputPath.c_str());
573     if (l_dirp != NULL) {  // LCOV_EXCL_BR_LINE 5: m_emmcOutputPath is not null, opendir is C code, always ok
574       for (;;) {
575         int l_ret = readdir_r(l_dirp, &l_dirent, &next);
576         if (((l_ret == 0) && (next == NULL))
577             || (l_ret > 0)) {
578           break;
579         }
580         l_checkFileName = l_dirent.d_name;
581         l_pos = l_checkFileName.find(".tar.gz");
582         if (std::string::npos != l_pos) {
583           l_pos = l_checkFileName.find("_");
584           if (std::string::npos != l_pos) {  // LCOV_EXCL_BR_LINE 200: tar.gz file is aways has "_"
585             std::string l_numberString = l_checkFileName.substr(0, l_pos);
586             l_count = static_cast<UI_32>(strtoul(l_numberString.c_str(), NULL, 10));
587             l_vector.push_back(l_count);
588             l_maxCount = std::max(l_count, l_maxCount);
589           }
590         }
591       }
592       closedir(l_dirp);
593     } else {
594       // LCOV_EXCL_START 5: m_emmcOutputPath is not null, opendir is C code, always ok
595       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
596       f_counter = 1;
597       return eFrameworkunifiedStatusOK;
598       // LCOV_EXCL_STOP
599     }
600
601     // reach at max number
602     if (l_maxCount >= LOGGERSERVICELOG_EMMC_COUNTER_MAX) {
603       RefreshEmmcCounter(m_EmmcCounter);
604     } else {
605       m_EmmcCounter = l_maxCount + 1;
606     }
607   } else if (m_EmmcCounter >= LOGGERSERVICELOG_EMMC_COUNTER_MAX) {
608     // reach at max number
609     RefreshEmmcCounter(m_EmmcCounter);
610   } else {
611     m_EmmcCounter++;
612   }
613
614   f_counter = m_EmmcCounter;
615   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
616   return (l_eStatus);
617 }
618
619 EFrameworkunifiedStatus CLoggerCfg::RefreshEmmcCounter(UI_32& f_counter) const {
620   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
621   std::string l_checkFileName;
622   std::vector<std::string> l_vector;
623   DIR *l_dirp;
624   struct dirent l_dirent;
625   struct dirent* next = NULL;
626   size_t l_pos;
627
628   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
629
630   // get filename saved frameworkunifiedlog on eMMC Device
631   l_dirp = opendir(m_emmcOutputPath.c_str());
632   if (l_dirp != NULL) {  // LCOV_EXCL_BR_LINE 5: m_emmcOutputPath is not null, opendir is C code, always ok
633     for (;;) {
634       int l_ret = readdir_r(l_dirp, &l_dirent, &next);
635       if (((l_ret == 0) && (next == NULL)) || (l_ret > 0)) {
636         break;
637       }
638       l_checkFileName = l_dirent.d_name;
639       l_pos = l_checkFileName.find(".tar.gz");
640       if (std::string::npos != l_pos) {
641         l_pos = l_checkFileName.find("_");
642         if (std::string::npos != l_pos) {
643           l_vector.push_back(l_checkFileName);
644         }
645       }
646     }
647     closedir(l_dirp);
648   } else {
649     // LCOV_EXCL_START 5: m_emmcOutputPath is not null, opendir is C code, always ok
650       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
651     // ignore opendir failure. this means saved frameworkunifiedlog is nothing on eMMC Device
652     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "open dir error path=%s errno=%s.",
653            m_emmcOutputPath.c_str(), strerror(errno));
654     f_counter = 1;
655     return eFrameworkunifiedStatusOK;
656     // LCOV_EXCL_STOP
657   }
658
659   // sort at log count
660   std::sort(l_vector.begin(), l_vector.end());
661
662   std::vector<std::string>::iterator it;
663   std::string l_orgFilePath;
664   std::string l_renameFilePath;
665   UI_32 l_wpt = 0;
666   UI_32 l_count;
667
668   it = l_vector.begin();
669   while (it != l_vector.end()) {
670     std::stringstream l_nameStream;
671     // get log counter parts
672     l_wpt++;
673     l_checkFileName = *it;
674     l_pos = l_checkFileName.find("_");
675     std::string l_numberString = l_checkFileName.substr(0, l_pos);
676     l_count = static_cast<UI_32>(strtoul(l_numberString.c_str(), NULL, 10));
677
678     // rename file if necessary
679     if (l_count != l_wpt) {
680       l_renameFilePath = l_orgFilePath = m_emmcOutputPath.c_str();
681       l_renameFilePath.append("/");
682       l_orgFilePath.append("/");
683       l_orgFilePath.append(l_checkFileName);
684
685       l_nameStream << std::setw(5) << std::setfill('0') << std::right
686                    << std::dec << l_wpt;
687       l_checkFileName.replace(0, l_pos, l_nameStream.str());
688
689       l_renameFilePath.append(l_checkFileName);
690
691       if (rename(l_orgFilePath.c_str(), l_renameFilePath.c_str()) != 0) {  // LCOV_EXCL_BR_LINE 5: rename is C code
692         // LCOV_EXCL_START 5: rename is C code
693         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
694         // rename failed but continue reamin log rename because new log need to be saved.
695         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
696                "log file[%s]->[%s] rename failed: err=%s.",
697                l_orgFilePath.c_str(), l_renameFilePath.c_str(), strerror(errno));
698         // LCOV_EXCL_STOP
699       }
700     }
701     it++;
702   }
703
704   f_counter = l_wpt + 1;
705
706   // set return value as next log counter
707   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
708   return l_eStatus;
709 }
710
711 BOOL CLoggerCfg::IsUDPLoggingEnabled(void) {
712   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
713   BOOL l_ret =
714       ((this->m_eLoggerUDPLoggingStatus == eActivate)
715           || (this->m_udpEnvFlag == TRUE)) ? TRUE : FALSE;
716   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- : %s", (TRUE == l_ret)?"TRUE":"FALSE");
717   return (l_ret);
718 }
719
720 void CLoggerCfg::AddLoggingParamCB(CbFuncPtr f_fp) {
721   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
722   if (f_fp != NULL) {  // LCOV_EXCL_BR_LINE 6: it aways not be null
723     this->m_LoggingCallBack.push_back(f_fp);
724     (void) f_fp(NULL);
725   }
726   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
727 }
728
729 void CLoggerCfg::UpdateLoggingStatus(void) {
730   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
731   std::vector<CbFuncPtr>::iterator l_iter;
732   for (l_iter = m_LoggingCallBack.begin(); l_iter != m_LoggingCallBack.end(); l_iter++) {  // LCOV_EXCL_BR_LINE 11:Unexpected branch  // NOLINT[whitespace/line_length]
733     (void) (*l_iter)(NULL);
734   }
735   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
736 }
737
738 EFrameworkunifiedStatus CLoggerCfg::GetLoggerStorageInfo(SLoggerStorageInfo &f_info) {
739   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
740   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
741   f_info = m_loggerStorageInfo;
742   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
743   return (l_eStatus);
744 }
745
746 BOOL CLoggerCfg::IsLoggingEnabled(void) {
747   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
748   return (this->m_eLoggerStatus == eActivate) ? TRUE : FALSE;
749   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
750 }
751
752 ExternalLogList CLoggerCfg::GetExternalLogList(void) {
753   return (m_ExternalLogList);
754 }  // LCOV_EXCL_BR_LINE 10:the last line