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_DATABASE_H
16 #define HIVIEWDFX_HIVIEW_FAULTLOGGER_FAULTLOG_DATABASE_H
17 
18 #include <cstdint>
19 #include <ctime>
20 #include <list>
21 #include <memory>
22 #include <mutex>
23 #include <string>
24 
25 #include "event_loop.h"
26 #include "faultlog_info.h"
27 #include "sys_event.h"
28 
29 namespace OHOS {
30 namespace HiviewDFX {
31 class FaultLogDatabase {
32 public:
33     explicit FaultLogDatabase(const std::shared_ptr<EventLoop>& eventLoop);
34     void SaveFaultLogInfo(FaultLogInfo& info);
35     std::list<FaultLogInfo> GetFaultInfoList(
36         const std::string& module, int32_t id, int32_t faultType, int32_t maxNum);
37     bool IsFaultExist(int32_t pid, int32_t uid, int32_t faultType);
38 private:
39     std::shared_ptr<EventLoop> eventLoop_{nullptr};
40     std::mutex mutex_;
41 };
42 }  // namespace HiviewDFX
43 }  // namespace OHOS
44 #endif  // HIVIEWDFX_HIVIEW_FAULTLOGGER_FAULTLOG_DATABASE_H