1 /*
2 * Copyright (c) 2021-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 "watchdog.h"
17
18 #include "watchdog_inner.h"
19
20 namespace OHOS {
21 namespace HiviewDFX {
Watchdog()22 Watchdog::Watchdog()
23 {
24 }
25
~Watchdog()26 Watchdog::~Watchdog()
27 {
28 }
29
AddThread(const std::string & name,std::shared_ptr<AppExecFwk::EventHandler> handler,TimeOutCallback timeOutCallback,uint64_t interval)30 int Watchdog::AddThread(const std::string &name, std::shared_ptr<AppExecFwk::EventHandler> handler,
31 TimeOutCallback timeOutCallback, uint64_t interval)
32 {
33 return WatchdogInner::GetInstance().AddThread(name, handler, timeOutCallback, interval);
34 }
35
AddThread(const std::string & name,std::shared_ptr<AppExecFwk::EventHandler> handler,uint64_t interval)36 int Watchdog::AddThread(const std::string &name, std::shared_ptr<AppExecFwk::EventHandler> handler, uint64_t interval)
37 {
38 return WatchdogInner::GetInstance().AddThread(name, handler, nullptr, interval);
39 }
40
RunOneShotTask(const std::string & name,Task && task,uint64_t delay)41 void Watchdog::RunOneShotTask(const std::string& name, Task&& task, uint64_t delay)
42 {
43 return WatchdogInner::GetInstance().RunOneShotTask(name, std::move(task), delay);
44 }
45
RunPeriodicalTask(const std::string & name,Task && task,uint64_t interval,uint64_t delay)46 void Watchdog::RunPeriodicalTask(const std::string& name, Task&& task, uint64_t interval, uint64_t delay)
47 {
48 return WatchdogInner::GetInstance().RunPeriodicalTask(name, std::move(task), interval, delay);
49 }
50
StopWatchdog()51 void Watchdog::StopWatchdog()
52 {
53 return WatchdogInner::GetInstance().StopWatchdog();
54 }
55
InitFfrtWatchdog()56 void Watchdog::InitFfrtWatchdog()
57 {
58 return WatchdogInner::GetInstance().InitFfrtWatchdog();
59 }
60
SetBundleInfo(const std::string & bundleName,const std::string & bundleVersion)61 void Watchdog::SetBundleInfo(const std::string& bundleName, const std::string& bundleVersion)
62 {
63 return WatchdogInner::GetInstance().SetBundleInfo(bundleName, bundleVersion);
64 }
65
SetForeground(const bool & isForeground)66 void Watchdog::SetForeground(const bool& isForeground)
67 {
68 return WatchdogInner::GetInstance().SetForeground(isForeground);
69 }
70
RemovePeriodicalTask(const std::string & name)71 void Watchdog::RemovePeriodicalTask(const std::string& name)
72 {
73 WatchdogInner::GetInstance().RemoveInnerTask(name);
74 }
75
RemoveThread(const std::string & name)76 void Watchdog::RemoveThread(const std::string& name)
77 {
78 WatchdogInner::GetInstance().RemoveInnerTask(name);
79 }
80
InitMainLooperWatcher(WatchdogBeginFunc * beginFunc,WatchdogEndFunc * endFunc)81 void Watchdog::InitMainLooperWatcher(WatchdogBeginFunc* beginFunc, WatchdogEndFunc* endFunc)
82 {
83 WatchdogInner::GetInstance().InitMainLooperWatcher(beginFunc, endFunc);
84 }
85
SetAppDebug(bool isAppDebug)86 void Watchdog::SetAppDebug(bool isAppDebug)
87 {
88 WatchdogInner::GetInstance().SetAppDebug(isAppDebug);
89 }
90
GetAppDebug()91 bool Watchdog::GetAppDebug()
92 {
93 return WatchdogInner::GetInstance().GetAppDebug();
94 }
95 } // end of namespace HiviewDFX
96 } // end of namespace OHOS
97