• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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_UTILITY_SYS_EVENT_DOC_READER_H
17 #define HIVIEW_BASE_EVENT_STORE_UTILITY_SYS_EVENT_DOC_READER_H
18 
19 #include <fstream>
20 #include <functional>
21 #include <string>
22 
23 #include "content_reader_factory.h"
24 #include "event_doc_reader.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 namespace EventStore {
29 using ReadCallback = std::function<bool(uint8_t* content, uint32_t& contentSize)>;
30 class SysEventDocReader : public EventDocReader {
31 public:
32     SysEventDocReader(const std::string& path);
33     ~SysEventDocReader();
34     int Read(const DocQuery& query, EntryQueue& entries, int& num) override;
35     int ReadFileSize();
36     int ReadPageSize(uint32_t& pageSize);
37     int ReadHeader(DocHeader& header);
38     int ReadHeader(DocHeader& header, HeadExtraInfo& headExtra);
39     int64_t ReadMaxEventSequence();
40 
41 private:
42     void Init(const std::string& path);
43     void InitEventInfo(const std::string& path);
44     int Read(ReadCallback callback);
45     int ReadContent(uint8_t** content, uint32_t& contentSize, uint32_t pageIndex);
46     int ReadPages(ReadCallback callback);
47     bool HasReadFileEnd();
48     bool HasReadPageEnd(uint32_t pageIndex);
49     bool IsValidHeader(const DocHeader& header);
50     bool CheckEventInfo(uint8_t* content);
51     int SeekgPage(uint32_t pageIndex);
52     std::shared_ptr<RawData> BuildRawData(uint8_t* content, uint32_t contentSize);
53     void TryToAddEntry(uint8_t* content, uint32_t contentSize, const DocQuery& query,
54         EntryQueue& entries, int& num);
55 
56 private:
57     std::ifstream in_;
58     int fileSize_ = 0;
59     uint32_t pageSize_ = 0;
60     uint8_t dataFmtVersion_ = 0;
61     uint64_t docHeaderSize_ = 0;
62     HeadExtraInfo headExtra_;
63     EventInfo info_;
64 }; // EventDocWriter
65 } // EventStore
66 } // HiviewDFX
67 } // OHOS
68 #endif // HIVIEW_BASE_EVENT_STORE_UTILITY_SYS_EVENT_DOC_READER_H
69