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