1209bc2fbSopenharmony_ci/* 2209bc2fbSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3209bc2fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4209bc2fbSopenharmony_ci * you may not use this file except in compliance with the License. 5209bc2fbSopenharmony_ci * You may obtain a copy of the License at 6209bc2fbSopenharmony_ci * 7209bc2fbSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8209bc2fbSopenharmony_ci * 9209bc2fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10209bc2fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11209bc2fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12209bc2fbSopenharmony_ci * See the License for the specific language governing permissions and 13209bc2fbSopenharmony_ci * limitations under the License. 14209bc2fbSopenharmony_ci */ 15209bc2fbSopenharmony_ci 16209bc2fbSopenharmony_ci#include "xcollie.h" 17209bc2fbSopenharmony_ci 18209bc2fbSopenharmony_ci#include <future> 19209bc2fbSopenharmony_ci 20209bc2fbSopenharmony_ci#include "xcollie_utils.h" 21209bc2fbSopenharmony_ci#include "watchdog_inner.h" 22209bc2fbSopenharmony_ci 23209bc2fbSopenharmony_cinamespace OHOS { 24209bc2fbSopenharmony_cinamespace HiviewDFX { 25209bc2fbSopenharmony_ciconstexpr uint64_t TO_MILLISECOND_MULTPLE = 1000; 26209bc2fbSopenharmony_ciXCollie::XCollie() 27209bc2fbSopenharmony_ci{ 28209bc2fbSopenharmony_ci} 29209bc2fbSopenharmony_ciXCollie::~XCollie() 30209bc2fbSopenharmony_ci{ 31209bc2fbSopenharmony_ci} 32209bc2fbSopenharmony_ci 33209bc2fbSopenharmony_ciint XCollie::SetTimer(const std::string &name, unsigned int timeout, std::function<void(void *)> func, 34209bc2fbSopenharmony_ci void *arg, unsigned int flag) 35209bc2fbSopenharmony_ci{ 36209bc2fbSopenharmony_ci return WatchdogInner::GetInstance().RunXCollieTask(name, timeout * TO_MILLISECOND_MULTPLE, func, arg, flag); 37209bc2fbSopenharmony_ci} 38209bc2fbSopenharmony_ci 39209bc2fbSopenharmony_civoid XCollie::CancelTimer(int id) 40209bc2fbSopenharmony_ci{ 41209bc2fbSopenharmony_ci WatchdogInner::GetInstance().RemoveXCollieTask(id); 42209bc2fbSopenharmony_ci} 43209bc2fbSopenharmony_ci 44209bc2fbSopenharmony_ciint XCollie::SetTimerCount(const std::string &name, unsigned int timeLimit, int countLimit) 45209bc2fbSopenharmony_ci{ 46209bc2fbSopenharmony_ci return WatchdogInner::GetInstance().SetTimerCountTask(name, timeLimit * TO_MILLISECOND_MULTPLE, countLimit); 47209bc2fbSopenharmony_ci} 48209bc2fbSopenharmony_ci 49209bc2fbSopenharmony_civoid XCollie::TriggerTimerCount(const std::string &name, bool bTrigger, const std::string &message) 50209bc2fbSopenharmony_ci{ 51209bc2fbSopenharmony_ci WatchdogInner::GetInstance().TriggerTimerCountTask(name, bTrigger, message); 52209bc2fbSopenharmony_ci} 53209bc2fbSopenharmony_ci} // end of namespace HiviewDFX 54209bc2fbSopenharmony_ci} // end of namespace OHOS 55209bc2fbSopenharmony_ci 56209bc2fbSopenharmony_citypedef void (*XCollieCallbackRust)(void *); 57209bc2fbSopenharmony_ci 58209bc2fbSopenharmony_ciextern "C" int SetTimerRust(const char* data, unsigned int timeout, 59209bc2fbSopenharmony_ci XCollieCallbackRust func, void *arg, unsigned int flag) 60209bc2fbSopenharmony_ci{ 61209bc2fbSopenharmony_ci std::string str = data; 62209bc2fbSopenharmony_ci return OHOS::HiviewDFX::XCollie::GetInstance().SetTimer(str, timeout, func, arg, flag); 63209bc2fbSopenharmony_ci} 64209bc2fbSopenharmony_ci 65209bc2fbSopenharmony_ciextern "C" void CancelTimerRust(int id) 66209bc2fbSopenharmony_ci{ 67209bc2fbSopenharmony_ci OHOS::HiviewDFX::XCollie::GetInstance().CancelTimer(id); 68209bc2fbSopenharmony_ci} 69