• 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 #include <unistd.h>
16 #include "hdf_xcollie.h"
17 #include "hdf_core_log.h"
18 
19 namespace OHOS {
20 #ifdef HDFHICOLLIE_ENABLE
HdfXCollie(const std::string & tag,uint32_t timeoutSeconds,std::function<void (void *)> func,void * arg,uint32_t flag)21 HdfXCollie::HdfXCollie(const std::string& tag, uint32_t timeoutSeconds,
22     std::function<void(void *)> func, void* arg, uint32_t flag)
23 {
24     tag_ = tag;
25     id_ = HiviewDFX::XCollie::GetInstance().SetTimer(tag_, timeoutSeconds, func, arg, flag);
26     isCanceled_ = false;
27     HDF_LOGD("start HdfXCollie, tag:%{public}s,timeout:%{public}u,flag:%{public}u,id:%{public}d",
28         tag_.c_str(), timeoutSeconds, flag, id_);
29 }
30 
~HdfXCollie()31 HdfXCollie::~HdfXCollie()
32 {
33     CancelHdfXCollie();
34 }
35 
CancelHdfXCollie()36 void HdfXCollie::CancelHdfXCollie()
37 {
38     if (!isCanceled_) {
39         HiviewDFX::XCollie::GetInstance().CancelTimer(id_);
40         isCanceled_ = true;
41         HDF_LOGD("cancel HdfXCollie, tag:%{public}s,id:%{public}d", tag_.c_str(), id_);
42     }
43 }
44 #else
45 
46 HdfXCollie::HdfXCollie(const std::string& tag, uint32_t timeoutSeconds,
47     std::function<void(void *)> func, void* arg, uint32_t flag)
48 {
49 }
50 
51 HdfXCollie::~HdfXCollie()
52 {
53 }
54 #endif
55 }
56