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 ALARM_TIMER_UTILS_H
17 #define ALARM_TIMER_UTILS_H
18 
19 #include <functional>
20 #include <string>
21 
22 #include "itimer_info.h"
23 
24 namespace OHOS {
25 namespace UpdateEngine {
26 using AlarmTimerCallback = std::function<void()>;
27 
28 class AlarmTimerUtils {
29 public:
30     static uint64_t RegisterAlarm(int64_t time, const AlarmTimerCallback &callback);
31     static void UnregisterAlarm(uint64_t timerId);
32 
33     static uint64_t RegisterRepeatAlarm(int64_t time, int64_t repeatTime, const AlarmTimerCallback &callback);
34     static uint64_t GetSystemBootTime();
35 
36 private:
37     static uint64_t RegisterTimer(int64_t time, const std::shared_ptr<MiscServices::ITimerInfo> &timerInfo);
38 
39 private:
40     class TimerTaskInfo : public MiscServices::ITimerInfo {
41     public:
TimerTaskInfo()42         TimerTaskInfo() {};
~TimerTaskInfo()43         virtual ~TimerTaskInfo() {};
44         void OnTrigger() override;
45         void SetType(const int &type) override;
46         void SetRepeat(bool repeat) override;
47         void SetInterval(const uint64_t &interval) override;
48         void SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent) override;
49         void SetCallbackInfo(const std::function<void()> &callBack);
50     public:
51         AlarmTimerCallback callBack_ = nullptr;
52     };
53 };
54 } // namespace UpdateEngine
55 } // namespace OHOS
56 #endif // ALARM_TIMER_UTILS_H