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 "export_file_writer.h"
17
18 #include "hiview_logger.h"
19
20 namespace OHOS {
21 namespace HiviewDFX {
22 DEFINE_LOG_TAG("HiView-EventExportFlow");
Write(std::shared_ptr<ExportFileBaseBuilder> fileBuilder,CachedEventMap events,WriteStrategyParam & param)23 bool ExportFileWriter::Write(std::shared_ptr<ExportFileBaseBuilder> fileBuilder, CachedEventMap events,
24 WriteStrategyParam& param)
25 {
26 if (fileBuilder == nullptr) {
27 HIVIEW_LOGE("invalid export file builder");
28 return false;
29 }
30 std::string buildStr;
31 if (!fileBuilder->Build(events, buildStr)) {
32 return false;
33 }
34 auto strategy = EventWriteStrategyFactory::GetWriteStrategy(StrategyType::ZIP_JSON_FILE);
35 if (strategy == nullptr) {
36 HIVIEW_LOGE("write strategy is null");
37 return false;
38 }
39 strategy->SetWriteStrategyParam(param);
40 return strategy->Write(buildStr,
41 [this] (const std::string& srcPath, const std::string& destPath) {
42 if (exportFileWroteListener_ == nullptr) {
43 return;
44 }
45 exportFileWroteListener_(srcPath, destPath);
46 });
47 }
48
SetExportFileWroteListener(ExportFileWroteListener listener)49 void ExportFileWriter::SetExportFileWroteListener(ExportFileWroteListener listener)
50 {
51 exportFileWroteListener_ = listener;
52 }
53 } // HiviewDFX
54 } // OHOS
55