1600cc4afSopenharmony_ci/*
2600cc4afSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3600cc4afSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4600cc4afSopenharmony_ci * you may not use this file except in compliance with the License.
5600cc4afSopenharmony_ci * You may obtain a copy of the License at
6600cc4afSopenharmony_ci *
7600cc4afSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8600cc4afSopenharmony_ci *
9600cc4afSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10600cc4afSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11600cc4afSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12600cc4afSopenharmony_ci * See the License for the specific language governing permissions and
13600cc4afSopenharmony_ci * limitations under the License.
14600cc4afSopenharmony_ci */
15600cc4afSopenharmony_ci
16600cc4afSopenharmony_ci#include "xcollie_helper.h"
17600cc4afSopenharmony_ci
18600cc4afSopenharmony_ci#include "app_log_wrapper.h"
19600cc4afSopenharmony_ci#ifdef HICOLLIE_ENABLE
20600cc4afSopenharmony_ci#include "xcollie/xcollie.h"
21600cc4afSopenharmony_ci#include "xcollie/xcollie_define.h"
22600cc4afSopenharmony_ci#endif
23600cc4afSopenharmony_ci
24600cc4afSopenharmony_cinamespace OHOS {
25600cc4afSopenharmony_cinamespace AppExecFwk {
26600cc4afSopenharmony_ciint XCollieHelper::SetTimer(const std::string &name, unsigned int timeout, std::function<void(void *)> func, void *arg)
27600cc4afSopenharmony_ci{
28600cc4afSopenharmony_ci#ifdef HICOLLIE_ENABLE
29600cc4afSopenharmony_ci    return HiviewDFX::XCollie::GetInstance().SetTimer(name, timeout, func, arg, HiviewDFX::XCOLLIE_FLAG_LOG);
30600cc4afSopenharmony_ci#else
31600cc4afSopenharmony_ci    APP_LOGI("HICOLLIE_ENABLE is false");
32600cc4afSopenharmony_ci    // HICOLLIE_ENABLE is false, do nothing and return -1.
33600cc4afSopenharmony_ci    return -1;
34600cc4afSopenharmony_ci#endif
35600cc4afSopenharmony_ci}
36600cc4afSopenharmony_ci
37600cc4afSopenharmony_civoid XCollieHelper::CancelTimer(int id)
38600cc4afSopenharmony_ci{
39600cc4afSopenharmony_ci#ifdef HICOLLIE_ENABLE
40600cc4afSopenharmony_ci    HiviewDFX::XCollie::GetInstance().CancelTimer(id);
41600cc4afSopenharmony_ci#endif
42600cc4afSopenharmony_ci}
43600cc4afSopenharmony_ci
44600cc4afSopenharmony_ciint32_t XCollieHelper::SetRecoveryTimer(const std::string &methodName, unsigned int timeout)
45600cc4afSopenharmony_ci{
46600cc4afSopenharmony_ci    return SetTimer(methodName, timeout, nullptr, nullptr);
47600cc4afSopenharmony_ci}
48600cc4afSopenharmony_ci}  // namespace AppExecFwk
49600cc4afSopenharmony_ci}  // namespace OHOS
50