1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef HIVIEWDFX_HIVIEW_FAULTLOGGER_FAULTLOG_MANAGER_H 16 #define HIVIEWDFX_HIVIEW_FAULTLOGGER_FAULTLOG_MANAGER_H 17 #include <cstdint> 18 #include <ctime> 19 #include <list> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 24 #include "event_loop.h" 25 #include "log_store_ex.h" 26 27 #include "faultlog_info.h" 28 29 namespace OHOS { 30 namespace HiviewDFX { 31 class FaultLogDatabase; 32 class FaultLogManager { 33 public: 34 // use rawdb manage fault log infos FaultLogManager(std::shared_ptr<EventLoop> looper)35 explicit FaultLogManager(std::shared_ptr<EventLoop> looper) : looper_(looper) {}; 36 virtual ~FaultLogManager(); 37 void Init(); 38 39 bool GetFaultLogContent(const std::string& name, std::string& content) const; 40 int32_t CreateTempFaultLogFile(time_t time, int32_t id, int32_t faultType, const std::string& module) const; 41 std::list<std::string> GetFaultLogFileList(const std::string& module, time_t time, int32_t id, int32_t faultType, 42 int32_t maxNum) const; 43 std::string SaveFaultLogToFile(FaultLogInfo& info) const; 44 void SaveFaultInfoToRawDb(FaultLogInfo& info) const; 45 std::list<FaultLogInfo> GetFaultInfoList( 46 const std::string& module, int32_t id, int32_t faultType, int32_t maxNum) const; 47 bool IsProcessedFault(int32_t pid, int32_t uid, int32_t faultType); 48 49 private: 50 void ReduceLogFileListSize(std::list<std::string>& infoVec, int32_t maxNum) const; 51 std::shared_ptr<EventLoop> looper_ = nullptr; 52 std::unique_ptr<LogStoreEx> store_ = nullptr; 53 FaultLogDatabase* faultLogDb_ = nullptr; 54 }; 55 } // namespace HiviewDFX 56 } // namespace OHOS 57 #endif // HIVIEWDFX_HIVIEW_FAULTLOGGER_FAULTLOG_MANAGER_H