1 /* 2 * Copyright (c) 2024-2025 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_EXPORT_EVENT_WRITE_HANDLER_H 17 #define HIVIEW_BASE_EVENT_EXPORT_EVENT_WRITE_HANDLER_H 18 19 #include <list> 20 21 #include "cached_event.h" 22 #include "export_base_handler.h" 23 #include "export_db_storage.h" 24 #include "export_event_packager.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 struct EventWriteRequest : public BaseRequest { 29 // name of export module 30 std::string moduleName; 31 32 // item: <system version, domain, sequecen, sysevent content> 33 std::list<std::shared_ptr<CachedEvent>> events; 34 35 // directory configured for export event file to store 36 std::string exportDir; 37 38 // tag whether the query is completed 39 bool isQueryCompleted = false; 40 41 // max size of a single event file 42 int64_t maxSingleFileSize = 0; 43 EventWriteRequestEventWriteRequest44 EventWriteRequest(std::string& moduleName, std::list<std::shared_ptr<CachedEvent>>& events, 45 std::string& exportDir, bool isQueryCompleted, int64_t maxSingleFileSize) 46 : moduleName(moduleName), events(events), exportDir(exportDir), 47 isQueryCompleted(isQueryCompleted), maxSingleFileSize(maxSingleFileSize) {} 48 }; 49 50 class EventWriteHandler : public ExportBaseHandler { 51 public: 52 bool HandleRequest(RequestPtr req) override; 53 54 private: 55 std::shared_ptr<ExportEventPackager> GetEventPackager(const std::shared_ptr<CachedEvent> event, 56 std::shared_ptr<EventWriteRequest> writeReq); 57 void Finish(); 58 void Rollback(); 59 60 private: 61 std::map<std::string, std::shared_ptr<ExportEventPackager>> packagers_; 62 }; 63 } // namespace HiviewDFX 64 } // namespace OHOS 65 66 #endif // HIVIEW_BASE_EVENT_EXPORT_EVENT_WRITE_HANDLER_H