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     uint64_t interval;
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      *        fasle: 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     virtual void SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent) = 0;
93     virtual void OnTrigger() = 0;
94 };
95 } // MiscServices
96 } // OHOS
97 
98 #endif // I_TIMER_INFO_H