2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_SS_LoggerService
19 /// \brief Provide support for CPU high load monitor configuration.
21 ///////////////////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////////////////
25 #include "ss_logger_cfg.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>
41 const static UI_32 cMAX_EMMC_COUNTER_VALUE = 100000u; // NOLINT (build/storage_class)
42 ///////////////////////////////////////////////////////////////////////////////
44 ///////////////////////////////////////////////////////////////////////////////
46 CLoggerCfg::CLoggerCfg()
47 : m_logMaxFileSize(0),
48 m_performanceLogMaxFileSize(0),
50 m_emmcOutputErrMax(0),
51 m_emmcOutputGrpRelaunchMax(0),
52 m_emmcOutputNaviLogMax(0),
53 m_emmcOutputNaviLogNmlMax(0),
54 m_emmcOutputNaviLogErrMax(0),
56 m_emmcOutputNaviLogPath(""),
61 m_UserInvokedLoggingNumber(1u),
63 m_eLoggerUDPLoggingStatus(eDeactivate),
64 m_eLoggerStatus(SS_LOGGER_DEFAULT_VALUE) {
66 std::memset(m_logMask, 0, sizeof(m_logMask));
67 std::memset(&m_ExternalLogList, 0, sizeof(&m_ExternalLogList));
70 CLoggerCfg::~CLoggerCfg(void) { // LCOV_EXCL_START 14:global instance
71 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
73 if (m_ExternalLogList.p_info != NULL) {
74 delete[] m_ExternalLogList.p_info;
75 m_ExternalLogList.p_info = NULL;
80 EFrameworkunifiedStatus CLoggerCfg::Initialize(HANDLE f_hApp) {
81 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
83 char* l_udp_env = getenv("UDPLOGS_ON");
86 FALSE : (strcmp("TRUE", l_udp_env) == 0 ? TRUE : FALSE));
88 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
89 return eFrameworkunifiedStatusOK;
91 EFrameworkunifiedStatus CLoggerCfg::SetandPersistLoggingParams(HANDLE f_hApp,
92 STLoggerSetAllParams f_Params,
94 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
95 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
96 BOOL l_paramChanged = f_InitCall;
97 BOOL l_updateLoggerState = f_InitCall;
99 if ((TRUE == l_paramChanged) // LCOV_EXCL_BR_LINE 200:l_paramChanged is never TRUE
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;
108 l_paramChanged = FALSE;
111 l_updateLoggerState =
112 ((l_updateLoggerState == TRUE)
113 || (m_eLoggerStatus != f_Params.Logger_State)) ? TRUE : FALSE;
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;
122 m_eLoggerStatus = f_Params.Logger_State;
124 m_eLoggerUDPLoggingStatus = f_Params.Logger_UDPState;
125 m_UserInvokedLoggingNumber = f_Params.Log_FolderCnt;
126 m_eDevType = f_Params.Device_Type;
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()");
134 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
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;
149 l_eStatus = SetandPersistLoggingParams(f_hApp, l_Params, FALSE);
150 LOG_STATUS_IF_ERRORED(l_eStatus, "SetandPersistLoggingParams()"); // LCOV_EXCL_BR_LINE 15: macro
152 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
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;
167 l_eStatus = SetandPersistLoggingParams(f_hApp, l_Params, FALSE);
168 LOG_STATUS_IF_ERRORED(l_eStatus, "SetandPersistLoggingParams()"); // LCOV_EXCL_BR_LINE 15: macro
170 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
174 EFrameworkunifiedStatus CLoggerCfg::PersistLoggingParam(HANDLE f_hApp) {
175 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
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
182 this->UpdateLoggingStatus();
183 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
184 return eFrameworkunifiedStatusOK;
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
192 if ('\r' == f_str.at(f_str.size() - 1)) {
193 f_str.erase(f_str.size() - 1, 1);
196 EFrameworkunifiedStatus CLoggerCfg::Load(const std::string &f_filePathAndName) {
197 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
198 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusDbRecNotFound;
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;
207 // FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Reading Configuration Data from %s", f_filePathAndName.c_str());
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;
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);
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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]
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);
328 for (UI_32 i = 0; i < ZONE_MASK_ARRAY_ELTS; i++) {
330 std::stringstream l_cfgParamName;
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);
343 m_logMask[i] = (UI_32) l_logMaskTemp;
347 m_EELStorageRelPath = "/EEL_export";
348 m_EELActivateRelPath = "/EEL_activate";
349 m_LoggerserviceEmmcLogsRelPath = "/LOGGERSERVICE_EMMC_LOGS";
351 if (m_ExternalLogList.num > 0) {
352 std::string str = "EXTERNAL_"; // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
355 if (m_ExternalLogList.num <= m_ExternalLogList.max) {
356 num = m_ExternalLogList.num;
358 num = m_ExternalLogList.max;
361 // LCOV_EXCL_BR_START 11:Excluded due to gcov constraints (others)
362 m_ExternalLogList.p_info = new ExternalLogInfo[num];
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]
377 RemoveCarriageReturn(m_ExternalLogList.p_info[i].dirname);
378 RemoveCarriageReturn(m_ExternalLogList.p_info[i].path);
381 // LCOV_EXCL_BR_STOP 11:Excluded due to gcov constraints (others)
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
392 delete l_pReaderCfg; // LCOV_EXCL_BR_LINE 11:Unexpected branch
396 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
400 EFrameworkunifiedStatus CLoggerCfg::Validate(void) {
401 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
402 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam;
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
410 " Error. Invalid configuration detected. LogMaxFileSize: %d Must be > 0.",
413 } else if (m_emmcOutputPath == "") {
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
426 " Error. Invalid configuration detected."
427 " EmmcOutputNaviLogPath: %s Must be a valid path containing a trailing backslash.",
428 m_emmcOutputNaviLogPath.c_str());
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
436 " Error. Invalid configuration detected."
437 " Usb0MountPath: %s Must be a valid path containing a trailing backslash.",
438 m_usb0MountPath.c_str());
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
446 " Error. Invalid configuration detected."
447 " Usb1MountPath: %s Must be a valid path containing a trailing backslash.",
448 m_usb1MountPath.c_str());
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
456 " Error. Invalid configuration detected. SdMountPath: %s Must be a valid path containing a trailing backslash.",
457 m_sdMountPath.c_str());
460 l_eStatus = eFrameworkunifiedStatusOK;
463 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
467 void CLoggerCfg::Print(void) {
468 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
470 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
473 std::string CLoggerCfg::getEmmcOutputPath(void) {
474 return (m_emmcOutputPath);
477 std::string CLoggerCfg::getEmmcOutputNaviLogPath(void) {
478 return (m_emmcOutputNaviLogPath);
481 std::string CLoggerCfg::getUsb0MountPath(void) {
482 return (m_usb0MountPath);
484 void CLoggerCfg::setUsb0MountPath(std::string& f_deviceMountpath) {
485 m_usb0MountPath = f_deviceMountpath;
488 EFrameworkunifiedStatus CLoggerCfg::GetUserInvokedDestination(std::string& f_dest) {
489 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
490 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
493 switch (m_eDevType) {
495 f_dest = m_usb0MountPath;
499 f_dest = m_usb1MountPath;
503 f_dest = m_sdMountPath;
506 case eTotalDevicesTypes:
507 case eInvalid_DevType:
509 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Unknown device type: %d",
511 l_eStatus = eFrameworkunifiedStatusFail;
515 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
519 EFrameworkunifiedStatus CLoggerCfg::GetEmmcDestination(std::string& f_dest) {
520 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
521 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
523 f_dest = m_emmcOutputPath;
525 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
529 EFrameworkunifiedStatus CLoggerCfg::GetEmmcNaviLogDestination(std::string& f_dest) {
530 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
531 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
533 f_dest = m_emmcOutputNaviLogPath;
535 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
539 UI_32 CLoggerCfg::GetUserInvokedCounter(void) {
540 return m_UserInvokedLoggingNumber;
543 EFrameworkunifiedStatus CLoggerCfg::GetIncrementAndPersistUserInvokedCounter(
544 HANDLE f_hApp, UI_32 &f_counter) {
545 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
546 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
548 f_counter = m_UserInvokedLoggingNumber;
549 m_UserInvokedLoggingNumber++;
550 l_eStatus = PersistLoggingParam(f_hApp);
552 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
562 struct dirent l_dirent;
563 struct dirent* next = NULL;
568 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
570 if (m_EmmcCounter == 0u) {
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
575 int l_ret = readdir_r(l_dirp, &l_dirent, &next);
576 if (((l_ret == 0) && (next == NULL))
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);
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
597 return eFrameworkunifiedStatusOK;
601 // reach at max number
602 if (l_maxCount >= LOGGERSERVICELOG_EMMC_COUNTER_MAX) {
603 RefreshEmmcCounter(m_EmmcCounter);
605 m_EmmcCounter = l_maxCount + 1;
607 } else if (m_EmmcCounter >= LOGGERSERVICELOG_EMMC_COUNTER_MAX) {
608 // reach at max number
609 RefreshEmmcCounter(m_EmmcCounter);
614 f_counter = m_EmmcCounter;
615 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
624 struct dirent l_dirent;
625 struct dirent* next = NULL;
628 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
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
634 int l_ret = readdir_r(l_dirp, &l_dirent, &next);
635 if (((l_ret == 0) && (next == NULL)) || (l_ret > 0)) {
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);
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));
655 return eFrameworkunifiedStatusOK;
660 std::sort(l_vector.begin(), l_vector.end());
662 std::vector<std::string>::iterator it;
663 std::string l_orgFilePath;
664 std::string l_renameFilePath;
668 it = l_vector.begin();
669 while (it != l_vector.end()) {
670 std::stringstream l_nameStream;
671 // get log counter parts
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));
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);
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());
689 l_renameFilePath.append(l_checkFileName);
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));
704 f_counter = l_wpt + 1;
706 // set return value as next log counter
707 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
711 BOOL CLoggerCfg::IsUDPLoggingEnabled(void) {
712 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
714 ((this->m_eLoggerUDPLoggingStatus == eActivate)
715 || (this->m_udpEnvFlag == TRUE)) ? TRUE : FALSE;
716 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- : %s", (TRUE == l_ret)?"TRUE":"FALSE");
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);
726 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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);
735 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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__, "-");
746 BOOL CLoggerCfg::IsLoggingEnabled(void) {
747 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
748 return (this->m_eLoggerStatus == eActivate) ? TRUE : FALSE;
749 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
752 ExternalLogList CLoggerCfg::GetExternalLogList(void) {
753 return (m_ExternalLogList);
754 } // LCOV_EXCL_BR_LINE 10:the last line