1 /*
2  * Copyright (c) 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 #ifndef FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_CONDITIONS_TIMER_INFO_H
17 #define FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_CONDITIONS_TIMER_INFO_H
18 
19 #include <functional>
20 #include "itimer_info.h"
21 #include "time_service_client.h"
22 
23 namespace OHOS::WorkScheduler {
24 using namespace OHOS::MiscServices;
25 class TimerInfo : public ITimerInfo {
26 public:
27     TimerInfo();
28     virtual ~TimerInfo();
29     void OnTrigger() override;
30     void SetType(const int &type_) override;
31     void SetRepeat(bool repeat_) override;
32     void SetInterval(const uint64_t &interval_) override;
33     void SetWantAgent(std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent_) override;
34     void SetCallbackInfo(const std::function<void()> &callBack);
35 private:
36     std::function<void()> callBack_ = nullptr;
37 };
38 
TimerInfo()39 TimerInfo::TimerInfo()
40 {
41 }
42 
~TimerInfo()43 TimerInfo::~TimerInfo()
44 {
45 }
46 
OnTrigger()47 void TimerInfo::OnTrigger()
48 {
49     if (callBack_ != nullptr) {
50         callBack_();
51     }
52 }
53 
SetCallbackInfo(const std::function<void ()> & callBack)54 void TimerInfo::SetCallbackInfo(const std::function<void()> &callBack)
55 {
56     callBack_ = callBack;
57 }
58 
SetType(const int & type_)59 void TimerInfo::SetType(const int &type_)
60 {
61     type = type_;
62 }
63 
SetRepeat(bool repeat_)64 void TimerInfo::SetRepeat(bool repeat_)
65 {
66     repeat = repeat_;
67 }
68 
SetInterval(const uint64_t & interval_)69 void TimerInfo::SetInterval(const uint64_t &interval_)
70 {
71     interval = interval_;
72 }
73 
SetWantAgent(std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent_)74 void TimerInfo::SetWantAgent(std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent_)
75 {
76     wantAgent = wantAgent_;
77 }
78 }
79 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_CONDITIONS_TIMER_INFO_H