17a9a4b8fSopenharmony_ci/* 27a9a4b8fSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 37a9a4b8fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47a9a4b8fSopenharmony_ci * you may not use this file except in compliance with the License. 57a9a4b8fSopenharmony_ci * You may obtain a copy of the License at 67a9a4b8fSopenharmony_ci * 77a9a4b8fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 87a9a4b8fSopenharmony_ci * 97a9a4b8fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 107a9a4b8fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 117a9a4b8fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127a9a4b8fSopenharmony_ci * See the License for the specific language governing permissions and 137a9a4b8fSopenharmony_ci * limitations under the License. 147a9a4b8fSopenharmony_ci */ 157a9a4b8fSopenharmony_ci#include "watchdog.h" 167a9a4b8fSopenharmony_ci 177a9a4b8fSopenharmony_ci#include "work_sched_hilog.h" 187a9a4b8fSopenharmony_ci#include "work_policy_manager.h" 197a9a4b8fSopenharmony_ci 207a9a4b8fSopenharmony_ciusing namespace std; 217a9a4b8fSopenharmony_ci 227a9a4b8fSopenharmony_cinamespace OHOS { 237a9a4b8fSopenharmony_cinamespace WorkScheduler { 247a9a4b8fSopenharmony_ciconst std::string WORK_SCHEDULER_WATCHDOG = "WorkSchedulerWatchdog"; 257a9a4b8fSopenharmony_ci 267a9a4b8fSopenharmony_ciWatchdog::Watchdog(const std::shared_ptr<WorkPolicyManager>& service, 277a9a4b8fSopenharmony_ci const std::shared_ptr<AppExecFwk::EventRunner>& runner) : service_(service) 287a9a4b8fSopenharmony_ci{ 297a9a4b8fSopenharmony_ci if (runner != nullptr) { 307a9a4b8fSopenharmony_ci SetEventRunner(runner); 317a9a4b8fSopenharmony_ci } 327a9a4b8fSopenharmony_ci} 337a9a4b8fSopenharmony_ci 347a9a4b8fSopenharmony_cibool Watchdog::AddWatchdog(uint32_t watchdogId, int32_t interval) 357a9a4b8fSopenharmony_ci{ 367a9a4b8fSopenharmony_ci WS_HILOGD("Add watchdog with Id:%{public}u", watchdogId); 377a9a4b8fSopenharmony_ci return SendEvent(watchdogId, 0, interval); 387a9a4b8fSopenharmony_ci} 397a9a4b8fSopenharmony_ci 407a9a4b8fSopenharmony_civoid Watchdog::RemoveWatchdog(uint32_t watchdogId) 417a9a4b8fSopenharmony_ci{ 427a9a4b8fSopenharmony_ci WS_HILOGD("Remove watchdog with Id:%{public}u", watchdogId); 437a9a4b8fSopenharmony_ci RemoveEvent(watchdogId); 447a9a4b8fSopenharmony_ci} 457a9a4b8fSopenharmony_ci 467a9a4b8fSopenharmony_civoid Watchdog::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) 477a9a4b8fSopenharmony_ci{ 487a9a4b8fSopenharmony_ci if (event == nullptr) { 497a9a4b8fSopenharmony_ci return; 507a9a4b8fSopenharmony_ci } 517a9a4b8fSopenharmony_ci uint32_t watchdogId = event->GetInnerEventId(); 527a9a4b8fSopenharmony_ci if (service_ != nullptr) { 537a9a4b8fSopenharmony_ci service_->WatchdogTimeOut(watchdogId); 547a9a4b8fSopenharmony_ci } else { 557a9a4b8fSopenharmony_ci WS_HILOGE("service is null"); 567a9a4b8fSopenharmony_ci } 577a9a4b8fSopenharmony_ci} 587a9a4b8fSopenharmony_ci} // namespace WorkScheduler 597a9a4b8fSopenharmony_ci} // namespace OHOS