• 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 "thermal_log.h"
17 #include "thermal_xcollie.h"
18 #include "xcollie/xcollie.h"
19 
20 namespace OHOS {
21 namespace PowerMgr {
ThermalXCollie(const std::string & logTag,bool isRecovery)22 ThermalXCollie::ThermalXCollie(const std::string &logTag, bool isRecovery)
23 {
24     logTag_ = logTag;
25     isCanceled_ = false;
26     const int DFX_DELAY_S = 60;
27     unsigned int flag = HiviewDFX::XCOLLIE_FLAG_LOG;
28     if (isRecovery) {
29         flag = HiviewDFX::XCOLLIE_FLAG_LOG | HiviewDFX::XCOLLIE_FLAG_RECOVERY;
30     }
31     id_ = HiviewDFX::XCollie::GetInstance().SetTimer(logTag_, DFX_DELAY_S, nullptr, nullptr, flag);
32     THERMAL_HILOGD(COMP_SVC, "Start ThermalXCollie, id:%{public}d, tag:%{public}s, timeout(s):%{public}u", id_,
33         logTag_.c_str(), DFX_DELAY_S);
34 }
35 
~ThermalXCollie()36 ThermalXCollie::~ThermalXCollie()
37 {
38     CancelThermalXCollie();
39 }
40 
CancelThermalXCollie()41 void ThermalXCollie::CancelThermalXCollie()
42 {
43     if (!isCanceled_) {
44         HiviewDFX::XCollie::GetInstance().CancelTimer(id_);
45         isCanceled_ = true;
46         THERMAL_HILOGD(COMP_SVC, "Cancel ThermalXCollie, id:%{public}d, tag:%{public}s", id_, logTag_.c_str());
47     }
48 }
49 
50 } // namespace PowerMgr
51 } // namespace OHOS