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_WRITER_H 17 #define HIVIEW_BASE_EVENT_STORE_UTILITY_SYS_EVENT_DOC_WRITER_H 18 19 #include <fstream> 20 #include <memory> 21 #include <string> 22 23 #include "event_doc_writer.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 namespace EventStore { 28 class SysEventDocWriter : public EventDocWriter { 29 public: 30 SysEventDocWriter(const std::string& path); 31 ~SysEventDocWriter(); 32 int Write(const std::shared_ptr<SysEvent>& sysEvent); 33 34 private: 35 int WriteHeader(const std::shared_ptr<SysEvent>& sysEvent, uint32_t contentSize); 36 int WriteContent(const std::shared_ptr<SysEvent>& sysEvent, uint32_t contentSize); 37 uint32_t GetCurrPageRemainSize(int fileSize, uint32_t pageSize); 38 int FillCurrPageWithZero(uint32_t remainSize); 39 int GetContentSize(const std::shared_ptr<SysEvent>& sysEvent, uint32_t& contentSize); 40 41 private: 42 std::ofstream out_; 43 uint32_t headerSize_ = 0; 44 }; // EventDocWriter 45 } // EventStore 46 } // HiviewDFX 47 } // OHOS 48 #endif // HIVIEW_BASE_EVENT_STORE_UTILITY_SYS_EVENT_DOC_WRITER_H 49