• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "power_hdf_log.h"
17 #include "power_xcollie.h"
18 #ifdef HICOLLIE_ENABLE
19 #include "xcollie/xcollie.h"
20 #endif
21 
22 namespace OHOS {
23 namespace HDI {
24 namespace Power {
PowerXCollie(const std::string & logTag,uint32_t timeoutSeconds)25 PowerXCollie::PowerXCollie(const std::string &logTag, uint32_t timeoutSeconds)
26 {
27     logTag_ = logTag;
28     isCanceled_ = false;
29 #ifdef HICOLLIE_ENABLE
30     id_ = HiviewDFX::XCollie::GetInstance().SetTimer(
31         logTag_, timeoutSeconds, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG | HiviewDFX::XCOLLIE_FLAG_RECOVERY);
32 #else
33     id_ = -1;
34 #endif
35     HDF_LOGD("Start PowerXCollie, id:%{public}d, tag:%{public}s, timeout(s):%{public}u", id_, logTag_.c_str(),
36         timeoutSeconds);
37 }
38 
~PowerXCollie()39 PowerXCollie::~PowerXCollie()
40 {
41     CancelPowerXCollie();
42 }
43 
CancelPowerXCollie()44 void PowerXCollie::CancelPowerXCollie()
45 {
46     if (!isCanceled_) {
47 #ifdef HICOLLIE_ENABLE
48         HiviewDFX::XCollie::GetInstance().CancelTimer(id_);
49 #endif
50         isCanceled_ = true;
51         HDF_LOGD("Cancel PowerXCollie, id:%{public}d, tag:%{public}s", id_, logTag_.c_str());
52     }
53 }
54 
55 } // namespace Power
56 } // namespace HDI
57 } // namespace OHOS