1 /*
2 * Copyright (c) 2022-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 "softbus_adapter_xcollie.h"
17
18 #include "comm_log.h"
19 #include "softbus_errcode.h"
20 #include "xcollie/watchdog.h"
21 #include "xcollie/xcollie.h"
22
SoftBusSetWatchdogTimer(const char * name,uint32_t timeout,void (* func)(void *),void * args)23 int32_t SoftBusSetWatchdogTimer(const char *name, uint32_t timeout, void (*func)(void *), void *args)
24 {
25 if (name == nullptr || func == nullptr || args == nullptr) {
26 COMM_LOGE(COMM_ADAPTER, "SoftBus Set Watchdog Timer param is invalid.");
27 return SOFTBUS_INVALID_PARAM;
28 }
29 return OHOS::HiviewDFX::XCollie::GetInstance().SetTimer(
30 name, timeout, func, args, OHOS::HiviewDFX::XCOLLIE_FLAG_LOG);
31 }
32
SoftBusCancelWatchdogTimer(int32_t id)33 void SoftBusCancelWatchdogTimer(int32_t id)
34 {
35 OHOS::HiviewDFX::XCollie::GetInstance().CancelTimer(id);
36 }
37
SoftBusRunOneShotTask(const char * name,void (* task)(void),uint64_t delay)38 void SoftBusRunOneShotTask(const char *name, void (*task)(void), uint64_t delay)
39 {
40 if (name == nullptr || task == nullptr) {
41 COMM_LOGE(COMM_ADAPTER, "SoftBus Run Shot Watchdog Task param is invalid.");
42 return;
43 }
44 OHOS::HiviewDFX::Watchdog::GetInstance().RunOneShotTask(name, task, delay);
45 }
46
SoftBusRunPeriodicalTask(const char * name,void (* task)(void),uint64_t interval,uint64_t delay)47 void SoftBusRunPeriodicalTask(const char *name, void (*task)(void), uint64_t interval, uint64_t delay)
48 {
49 if (name == nullptr || task == nullptr) {
50 COMM_LOGE(COMM_ADAPTER, "SoftBus Run Periodical Watchdog Task param is invalid");
51 return;
52 }
53 OHOS::HiviewDFX::Watchdog::GetInstance().RunPeriodicalTask(name, task, interval, delay);
54 }
55