1 /*
2  * Copyright (c) 2023 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 
16 #ifndef HIVIEW_BASE_EVENT_STORE_SYS_EVENT_DOC_H
17 #define HIVIEW_BASE_EVENT_STORE_SYS_EVENT_DOC_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "base_def.h"
23 #include "event_doc_reader.h"
24 #include "event_doc_writer.h"
25 #include "sys_event.h"
26 
27 namespace OHOS {
28 namespace HiviewDFX {
29 namespace EventStore {
30 class SysEventDoc {
31 public:
32     SysEventDoc(const std::string& domain, const std::string& name);
33     SysEventDoc(const std::string& file);
34     ~SysEventDoc();
35 
36     int Insert(const std::shared_ptr<SysEvent>& sysEvent);
37     int Query(const DocQuery& query, EntryQueue& entries, int& num);
38 
39 private:
40     int InitWriter(const std::shared_ptr<SysEvent>& sysEvent);
41     int InitReader();
42     std::string CreateFile();
43     std::string GetDir();
44     std::string GetCurFile(const std::string& dir);
45     uint32_t GetMaxFileSize();
46     bool IsFileFull(const std::string& file);
47     bool IsNeedUpdateCurFile();
48     int UpdateCurFile(const std::shared_ptr<SysEvent>& sysEvent);
49     int CreateCurFile(const std::string& dir, const std::shared_ptr<SysEvent>& sysEvent);
50 
51 private:
52     std::shared_ptr<EventDocWriter> writer_;
53     std::shared_ptr<EventDocReader> reader_;
54     std::string domain_;
55     std::string name_;
56     int type_;
57     std::string level_;
58     std::string curFile_;
59 }; // SysEventDoc
60 } // EventStore
61 } // HiviewDFX
62 } // OHOS
63 #endif // HIVIEW_BASE_EVENT_STORE_SYS_EVENT_DOC_H
64