Re-organized sub-directory by category
[staging/basesystem.git] / service / system / logger_service / server / include / ss_logger_util.h
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 SS Logger module utility functions.
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22 #ifndef LOGGER_SERVICE_SERVER_INCLUDE_SS_LOGGER_UTIL_H_
23 #define LOGGER_SERVICE_SERVER_INCLUDE_SS_LOGGER_UTIL_H_
24
25 ///////////////////////////////////////////////////////////////////////////////
26 // INCLUDES
27 ///////////////////////////////////////////////////////////////////////////////
28
29 #include <time.h>
30 #include <native_service/frameworkunified_types.h>
31 #include <system_service/ss_templates.h>
32 #include <system_service/ss_system_manager_if.h>
33 #include <string>
34 #include <vector>
35 #include "ss_logger_error_event_cfg.h"
36 #include "loggerservicedebug_loggerservicelog.h"
37 #include "ss_logger_cfg.h"
38 ///////////////////////////////////////////////////////////////////////////////
39 // DEFINE
40 ///////////////////////////////////////////////////////////////////////////////
41 // If you changed BUF_MAX_SIZE, To contact the secure team.
42 // Because There is impact for decrypt tool.
43 #define BUF_MAX_SIZE (1024*8)
44 #define USB_PATH_SIZE 64
45 #ifdef RELEASE_BUILD
46 #define DEV_ENC_EXTENSION            ".enc1"
47 #define REL_ENC_EXTENSION            ".enc2"
48 #define ALIGNMENT_SIZE 4
49 #endif  // RELEASE_BUILD
50 #define LOGGER_TMP_FN                "__LOGGER.tmp"
51
52 ///////////////////////////////////////////////////////////////////////////////
53 // CONFIGURATION CLASS DEFINITION
54 ///////////////////////////////////////////////////////////////////////////////
55 typedef enum _ELoggerserviceLogType {
56   eLoggerservicelogTypeNormal,
57   eLoggerservicelogTypeAbnormal,
58   eLoggerservicelogTypeGrpRelaunch,
59   eLoggerservicelogTypeOther,
60 } ELOGGERSERVICELOGTYPE;
61
62 class CLoggerUtil {
63  public:
64   CLoggerUtil(void);
65
66   ~CLoggerUtil(void);
67
68   EFrameworkunifiedStatus Initialize(CLoggerCfg *f_pLoggerCfg);
69
70   EFrameworkunifiedStatus checkDestinationAvailable(TLoggerErrorEvent &f_eventNtfData);  // NOLINT (runtime/references)
71   std::string getDestination(TLoggerErrorEvent &f_eventNtfData);  // NOLINT (runtime/references)
72   EFrameworkunifiedStatus getFilePathAndName(HANDLE f_hApp,
73                                 TLoggerErrorEvent &f_eventNtfData,  // NOLINT (runtime/references)
74                                 uint32_t f_time, std::string &f_pathAndName);  // NOLINT (runtime/references)
75   void SetMilage(UI_32 f_milage);
76
77   EFrameworkunifiedStatus getEmmcNaviLogParams(uint32_t f_time,
78                                   EPWR_SHUTDOWN_TRIGGER_TYPE errorType,
79                                   std::string &f_pathAndName, UI_32 &f_logMax);  // NOLINT (runtime/references)
80
81   EFrameworkunifiedStatus deleteOldLog(std::string log_path,
82                           std::vector<std::string> &l_vector,  // NOLINT (runtime/references)
83                           std::string &f_archive_destination, UI_32 max_num);  // NOLINT (runtime/references)
84   EFrameworkunifiedStatus deleteOldEmmcLog(std::string &f_archive_destination,  // NOLINT (runtime/references)
85                               EErrorEventType type);
86   static EFrameworkunifiedStatus forceDeleteOldLog(std::string f_archive_destination,
87                                       size_t f_req_size);
88   static size_t deleteRequestLogs(std::string f_emmcpath, ELOGGERSERVICELOGTYPE f_reqtype,
89                                   size_t f_reqsize, ELOGGERSERVICELOGTYPE f_deltype);
90   static EFrameworkunifiedStatus CopyFile(std::string f_source, std::string f_destination);
91   static EFrameworkunifiedStatus CopyUntyped(std::string f_source,
92                                 std::string f_destination);
93   static EFrameworkunifiedStatus CopyDirectory(std::string f_source,
94                                   std::string f_destination);
95
96   static EFrameworkunifiedStatus MoveFile(std::string f_source, std::string f_destination);
97   static EFrameworkunifiedStatus MoveUntyped(std::string f_source,
98                                 std::string f_destination);
99   static EFrameworkunifiedStatus MoveDirectory(std::string f_source,
100                                   std::string f_destination);
101
102   static ELOGGERSERVICELOGTYPE QueryLoggerservicelogType(std::string f_logname);
103   static void SyncDir(std::string f_dir_path);
104 #ifdef RELEASE_BUILD
105   static EFrameworkunifiedStatus PathCheckAndCopyFile(std::string f_source,
106       std::string f_destination);
107 #endif  // RELEASE_BUILD
108   void SetUsbMountPath(std::string usbpath);
109
110  private:
111   std::string GetUserInvokedFilename(HANDLE f_hApp, uint32_t f_time);
112   std::string GetEmmcFilename(uint32_t f_time);
113   std::string GetEmmcErrorFilename(uint32_t f_time);
114   std::string GetEmmcNaviLogFilename(uint32_t f_time);
115   std::string GetTimeString(uint32_t f_time);
116
117   EFrameworkunifiedStatus getNaviLogFilePathAndName(std::string &f_prefix, uint32_t f_time,  // NOLINT (runtime/references)
118                                        std::string &f_pathAndName);  // NOLINT (runtime/references)
119
120   CLoggerCfg *m_pCfg;
121   UI_32 m_Milage;
122   UI_32 m_bootCount;
123   static char m_usbpath[USB_PATH_SIZE];
124 };
125
126 #endif  // LOGGER_SERVICE_SERVER_INCLUDE_SS_LOGGER_UTIL_H_
127