• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "event_write_strategy_factory.h"
17 
18 #include <functional>
19 #include <unordered_map>
20 
21 #include "hiview_logger.h"
22 #include "write_zip_file_strategy.h"
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 DEFINE_LOG_TAG("HiView-EventExportFlow");
27 namespace {
28 using StrategyBuilderFunc = std::function<std::shared_ptr<EventWriteBaseStrategy>()>;
29 }
30 
SetWriteStrategyParam(WriteStrategyParam & param)31 void EventWriteBaseStrategy::SetWriteStrategyParam(WriteStrategyParam& param)
32 {
33     param_ = param;
34 }
35 
GetPackagerKey(std::shared_ptr<CachedEvent> cachedEvent)36 std::string EventWriteBaseStrategy::GetPackagerKey(std::shared_ptr<CachedEvent> cachedEvent)
37 {
38     return "";
39 }
40 
Write(std::string & exportContent,WroteCallback callback)41 bool EventWriteBaseStrategy::Write(std::string& exportContent, WroteCallback callback)
42 {
43     return false;
44 }
45 
GetWriteStrategy(StrategyType type)46 std::shared_ptr<EventWriteBaseStrategy> EventWriteStrategyFactory::GetWriteStrategy(StrategyType type)
47 {
48     static std::unordered_map<StrategyType, StrategyBuilderFunc> strategyBuilderMap = {
49         {
50             StrategyType::ZIP_JSON_FILE, [] () {
51                 return std::make_shared<WriteZipFileStrategy>();
52             }
53         }
54     };
55     auto iter = strategyBuilderMap.find(type);
56     if (iter == strategyBuilderMap.end() || iter->second == nullptr) {
57         return nullptr;
58     }
59     return iter->second();
60 }
61 } // namespace HiviewDFX
62 } // namespace OHOS