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