1 /*
2  * Copyright (C) 2021 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 #include "executor/hidumper_executor.h"
16 #include "datetime_ex.h"
17 namespace OHOS {
18 namespace HiviewDFX {
19 const std::string HidumperExecutor::TIME_OUT_STR = "time out";
20 
~HidumperExecutor()21 HidumperExecutor::~HidumperExecutor()
22 {
23 }
24 
Reset()25 void HidumperExecutor::Reset()
26 {
27     rawParam_ = nullptr;
28     ptrParent_ = nullptr;
29 }
30 
DoPreExecute(const std::shared_ptr<DumperParameter>& parameter, StringMatrix dumpDatas)31 DumpStatus HidumperExecutor::DoPreExecute(const std::shared_ptr<DumperParameter>& parameter, StringMatrix dumpDatas)
32 {
33     if (parameter != nullptr) {
34         rawParam_ = parameter->getClientCallback();
35     }
36 
37     DumpStatus ret = PreExecute(parameter, dumpDatas);
38     return ret;
39 }
40 
DoExecute()41 DumpStatus HidumperExecutor::DoExecute()
42 {
43     DumpStatus ret = Execute();
44     return ret;
45 }
46 
DoAfterExecute()47 DumpStatus HidumperExecutor::DoAfterExecute()
48 {
49     DumpStatus ret = AfterExecute();
50     rawParam_ = nullptr;
51     return ret;
52 }
53 
SetDumpConfig(const std::shared_ptr<DumpCfg>& config)54 void HidumperExecutor::SetDumpConfig(const std::shared_ptr<DumpCfg>& config)
55 {
56     if (config == nullptr) {
57         DUMPER_HILOGF(MODULE_COMMON, "fatal|config is null");
58         return;
59     }
60 
61     ptrDumpCfg_ = config;
62 
63     if ((!ptrDumpCfg_->IsOutput()) && (ptrDumpCfg_->parent_ != nullptr)) {
64         ptrParent_ = ptrDumpCfg_->parent_->executor_;
65     }
66 }
67 
GetDumpConfig() const68 const std::shared_ptr<DumpCfg>& HidumperExecutor::GetDumpConfig() const
69 {
70     return ptrDumpCfg_;
71 }
72 
IsCanceled() const73 bool HidumperExecutor::IsCanceled() const
74 {
75     return ((rawParam_ != nullptr) && rawParam_->IsCanceled());
76 }
77 } // namespace HiviewDFX
78 } // namespace OHOS
79