1 /* 2 * Copyright (c) 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_WRITE_BASE_STRAGEGY_H 17 #define HIVIEW_BASE_EVENT_WRITE_BASE_STRAGEGY_H 18 19 #include <string> 20 #include <functional> 21 22 #include "cached_event.h" 23 24 namespace OHOS { 25 namespace HiviewDFX { 26 struct WriteStrategyParam { 27 std::string moduleName; 28 std::string exportDir; 29 EventVersion version; 30 int32_t uid = 0; 31 }; 32 33 using WroteCallback = std::function<void(const std::string&, const std::string&)>; 34 class EventWriteBaseStrategy { 35 public: 36 EventWriteBaseStrategy() = default; 37 virtual ~EventWriteBaseStrategy() = default; 38 39 virtual void SetWriteStrategyParam(WriteStrategyParam& param); 40 41 virtual std::string GetPackagerKey(std::shared_ptr<CachedEvent> cachedEvent); 42 virtual bool Write(std::string& exportContent, WroteCallback callback); 43 44 protected: 45 WriteStrategyParam param_; 46 }; 47 48 enum StrategyType { 49 ZIP_JSON_FILE, 50 }; 51 52 class EventWriteStrategyFactory { 53 public: 54 static std::shared_ptr<EventWriteBaseStrategy> GetWriteStrategy(StrategyType type); 55 }; 56 } // namespace HiviewDFX 57 } // namespace OHOS 58 59 #endif // HIVIEW_BASE_EVENT_EXPORT_BASE_STRAGEGY_H