1 /* 2 * Copyright (C) 2021 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 #ifndef I_TIMER_INFO_H 16 #define I_TIMER_INFO_H 17 18 #include "visibility.h" 19 #include "want_agent_helper.h" 20 21 namespace OHOS { 22 namespace MiscServices { 23 class ITimerInfo { 24 public: 25 TIME_API ITimerInfo(); 26 TIME_API virtual ~ITimerInfo(); 27 28 int type; 29 bool repeat; 30 bool disposable = false; 31 bool autoRestore = false; 32 uint64_t interval; 33 std::string name = ""; 34 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent; 35 36 /** 37 * Indicates the timing policy the timer use, which can be REALTIME or UTC. 38 */ 39 const int TIMER_TYPE_REALTIME = 1 << 0; 40 41 /** 42 * Describes whether a timer will wake the device up. 43 */ 44 const int TIMER_TYPE_WAKEUP = 1 << 1; 45 46 /** 47 * Describes whether a timer will be delivered precisely at a scheduled time. 48 */ 49 const int TIMER_TYPE_EXACT = 1 << 2; 50 51 /** 52 * Indicates whether the timer waking up the system is supported in low-power mode. 53 */ 54 const int TIMER_TYPE_IDLE = 1 << 3; 55 56 /** 57 * Indicates whether the timer is from inexact reminder agent. 58 */ 59 const int TIMER_TYPE_INEXACT_REMINDER = 1 << 4; 60 /** 61 * SetType set timer type 62 * @para: type: TIMER_TYPE_REALTIME | TIMER_TYPE_WAKEUP 63 * 64 */ 65 virtual void SetType(const int &type) = 0; 66 67 /** 68 * SetRepeat set timer repeat or not 69 * @para: repeat: bool 70 * 71 */ 72 virtual void SetRepeat(bool repeat) = 0; 73 74 /** 75 * SetInterval set timer repeat interval 76 * @para: repeat: uint64_t >= 5000ms 77 * 78 */ 79 virtual void SetInterval(const uint64_t &interval) = 0; 80 81 /** 82 * SetDisposable set timer disposable or not 83 * @para: _disposable bool 84 * true: the timer will be destoryed automaticly when it is triggered. 85 * But do not take effect for repeat timer. 86 * false: the timer need to be destroyed by client 87 */ SetDisposable(const bool & _disposable)88 void SetDisposable(const bool &_disposable) 89 { 90 disposable = _disposable; 91 } 92 93 /** 94 * SetAutoRestore set timer restored upon reboot 95 * @para: _autoRestore bool 96 * true: the timer will be restored when the device reboots. 97 * false: the timer won't be restored when the device reboots. 98 */ SetAutoRestore(bool _autoRestore)99 void SetAutoRestore(bool _autoRestore) 100 { 101 autoRestore = _autoRestore; 102 } 103 104 /** 105 * SetName set timer name 106 * @para: _name string 107 * If set a timer with the same name as a previous one, 108 * the previous timer will be destroyed. 109 */ SetName(const std::string & _name)110 void SetName(const std::string &_name) 111 { 112 name = _name; 113 } 114 virtual void SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent) = 0; 115 virtual void OnTrigger() = 0; 116 }; 117 } // MiscServices 118 } // OHOS 119 120 #endif // I_TIMER_INFO_H